Skip to content

[Storage] Strip sensitive auth info on cross-domain redirect#47541

Open
weirongw23-msft wants to merge 8 commits into
Azure:mainfrom
weirongw23-msft:weirongw23/disable-redirect-attach
Open

[Storage] Strip sensitive auth info on cross-domain redirect#47541
weirongw23-msft wants to merge 8 commits into
Azure:mainfrom
weirongw23-msft:weirongw23/disable-redirect-attach

Conversation

@weirongw23-msft

Copy link
Copy Markdown
Member

No description provided.

@github-actions github-actions Bot added the Storage Storage Service (Queues, Blobs, Files) label Jun 17, 2026
@weirongw23-msft weirongw23-msft marked this pull request as ready for review June 17, 2026 16:20
Copilot AI review requested due to automatic review settings June 17, 2026 16:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a Storage pipeline policy intended to prevent credential/SAS leakage by stripping sensitive authentication headers and query parameters when an HTTP redirect crosses domains, and wires that policy into the Blob, Queue, File Share, and Data Lake pipelines.

Changes:

  • Added StorageSensitiveHeaderCleanupPolicy to scrub sensitive headers and remove sig from the URL query when RedirectPolicy flags a cross-domain redirect.
  • Inserted the new policy into the sync/async pipeline construction for Blob, Queue, File Share, and Data Lake clients.
  • Added a Blob unit test covering the redirect-cleanup behavior.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
sdk/storage/azure-storage-queue/azure/storage/queue/_shared/policies.py Adds StorageSensitiveHeaderCleanupPolicy implementation for Queue.
sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client.py Wires the new cleanup policy into the Queue sync pipeline.
sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client_async.py Wires the new cleanup policy into the Queue async pipeline.
sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/policies.py Adds StorageSensitiveHeaderCleanupPolicy implementation for File Share.
sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/base_client.py Wires the new cleanup policy into the File Share sync pipeline.
sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/base_client_async.py Wires the new cleanup policy into the File Share async pipeline.
sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/policies.py Adds StorageSensitiveHeaderCleanupPolicy implementation for Data Lake.
sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/base_client.py Wires the new cleanup policy into the Data Lake sync pipeline.
sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/base_client_async.py Wires the new cleanup policy into the Data Lake async pipeline.
sdk/storage/azure-storage-blob/azure/storage/blob/_shared/policies.py Adds StorageSensitiveHeaderCleanupPolicy implementation for Blob.
sdk/storage/azure-storage-blob/azure/storage/blob/_shared/base_client.py Wires the new cleanup policy into the Blob sync pipeline.
sdk/storage/azure-storage-blob/azure/storage/blob/_shared/base_client_async.py Wires the new cleanup policy into the Blob async pipeline.
sdk/storage/azure-storage-blob/tests/test_sensitive_redirect.py Adds unit coverage for redirect-based sensitive header/query cleanup (Blob only).

Comment on lines +912 to +919
# Clean up request query parameters
parsed = urlparse(request.http_request.url)
kept = [
pair
for pair in parsed.query.split("&")
if pair and pair.split("=", 1)[0] not in self._blocked_query_params
]
request.http_request.url = urlunparse(parsed._replace(query="&".join(kept)))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am okay with using parse_qsl but I don't think we should re-encode. A lot of existing SAS features (e.g. Directory-Level SAS on Blob FNS) predicates on that we do not re-encode as it is encoding sensitive.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Headers can be case sensitive and the blocked header list is also case sensitive.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yeah this is a tricky one since parse_qsl will decode so we must re-encode when we build the string back. But yeah, I remember those new SAS query params are picky about encoding... I think it's probably safer to go back to something like you had before with manual parsing. Since we are the ones building the URLs we can be somewhat certain that there is less funny business like encoded separators or empty params.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

Comment thread sdk/storage/azure-storage-blob/azure/storage/blob/_shared/policies.py Outdated
Comment thread sdk/storage/azure-storage-queue/azure/storage/queue/_shared/policies.py Outdated
return True


class StorageSensitiveHeaderCleanupPolicy(SansIOHTTPPolicy[HTTPRequestType, HTTPResponseType]):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably don't need any of this HTTP type stuff, just inherit from plain SansIOHTTPPolicy like all of our other policies.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

DEFAULT_SENSITIVE_HEADERS = {
"Authorization", "x-ms-authorization-auxiliary", "x-ms-copy-source", "x-ms-copy-source-authorization",
"x-ms-rename-source"
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this how black wants this formatted? I would prefer one per line.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

black automatically formatted like this, but I will put one line each and even during future reformats it'll be okay.

self, # pylint: disable=unused-argument
*,
blocked_redirect_headers: Optional[List[str]] = None,
blocked_query_params: Optional[List[str]] = None,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's call this blocked_redirect_query_params. I originally was going to suggest getting rid of all these customization options since this is our policy and we should just hardcode the list BUT because we pass kwargs in base_client it means that users could pass these when constructing a Storage client, which I think is good flexibility to have if a customer wants to customize this at all. So, because of that, the keyword name needs to be specific to redirect since it gets pass to our constructor.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, done :)

Comment on lines +912 to +919
# Clean up request query parameters
parsed = urlparse(request.http_request.url)
kept = [
pair
for pair in parsed.query.split("&")
if pair and pair.split("=", 1)[0] not in self._blocked_query_params
]
request.http_request.url = urlunparse(parsed._replace(query="&".join(kept)))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yeah this is a tricky one since parse_qsl will decode so we must re-encode when we build the string back. But yeah, I remember those new SAS query params are picky about encoding... I think it's probably safer to go back to something like you had before with manual parsing. Since we are the ones building the URLs we can be somewhat certain that there is less funny business like encoded separators or empty params.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Storage Storage Service (Queues, Blobs, Files)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants