Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: azure storage signing failed for query contains = #409

Merged
merged 3 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/azure/constants.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
use percent_encoding::{AsciiSet, NON_ALPHANUMERIC};

// Headers used in azure services.
pub const X_MS_DATE: &str = "x-ms-date";
pub const CONTENT_MD5: &str = "content-md5";

pub static AZURE_QUERY_ENCODE_SET: AsciiSet = NON_ALPHANUMERIC
.remove(b'-')
.remove(b'.')
.remove(b'_')
.remove(b'/')
.remove(b'~');
15 changes: 13 additions & 2 deletions src/azure/storage/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use anyhow::anyhow;
use anyhow::Result;
use http::header::*;
use log::debug;
use percent_encoding::percent_encode;

use super::super::constants::*;
use super::credential::Credential;
Expand Down Expand Up @@ -142,7 +143,11 @@ impl Signer {
/// }
/// ```
pub fn sign(&self, req: &mut impl SignableRequest, cred: &Credential) -> Result<()> {
let ctx = self.build(req, SigningMethod::Header, cred)?;
let mut ctx = self.build(req, SigningMethod::Header, cred)?;

for (_, v) in ctx.query.iter_mut() {
*v = percent_encode(v.as_bytes(), &AZURE_QUERY_ENCODE_SET).to_string();
}
req.apply(ctx)
}

Expand Down Expand Up @@ -243,11 +248,17 @@ fn canonicalize_resource(ctx: &mut SigningContext, ak: &str) -> String {
return format!("/{}{}", ak, ctx.path);
}

let query = ctx
.query
.iter()
.map(|(k, v)| (k.to_lowercase(), v.clone()))
.collect();

format!(
"/{}{}\n{}",
ak,
ctx.path,
SigningContext::query_to_string(ctx.query.clone(), ":", "\n")
SigningContext::query_to_percent_decoded_string(query, ":", "\n")
)
}

Expand Down
Loading