-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[Storage] Strip sensitive auth info on cross-domain redirect #47541
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
Open
weirongw23-msft
wants to merge
9
commits into
Azure:main
Choose a base branch
from
weirongw23-msft:weirongw23/disable-redirect-attach
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f8371ea
Strip sensitive auth info on cross-domain redirect
weirongw23-msft 03f9fa8
Small formatting change
weirongw23-msft c95a659
Shared code
weirongw23-msft 8e961ee
Fixed import error
weirongw23-msft 3d0b0b0
Copilot feedback
weirongw23-msft f6404c3
PR feedback, pylint, mypy
weirongw23-msft 0953f55
Black formatting
weirongw23-msft 9ee6da4
Merge branch 'main' into weirongw23/disable-redirect-attach
weirongw23-msft 5d0e934
PR feedback
weirongw23-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
sdk/storage/azure-storage-blob/tests/test_sensitive_redirect.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| from azure.core.pipeline import PipelineRequest, PipelineContext | ||
| from azure.core.rest import HttpRequest | ||
| from azure.storage.blob._shared.policies import StorageSensitiveHeaderCleanupPolicy | ||
|
|
||
|
|
||
| def make_request(url, headers=None): | ||
| http_request = HttpRequest("GET", url, headers=headers or {}) | ||
| context = PipelineContext(None) | ||
| return PipelineRequest(http_request, context) | ||
|
|
||
|
|
||
| class TestStorageSensitiveHeaderCleanup: | ||
| SENSITIVE_HEADERS = { | ||
| "Authorization": "Bearer token", | ||
| "x-ms-authorization-auxiliary": "Bearer aux-token", | ||
| "x-ms-copy-source": "https://acct.blob.core.windows.net/c/src?sig=SECRET", | ||
| "x-ms-copy-source-authorization": "Bearer copy-token", | ||
| "x-ms-rename-source": "/c/old", | ||
| } | ||
|
|
||
| def test_storage_sensitive_cleanup_on_redirect(self): | ||
| headers = dict(self.SENSITIVE_HEADERS) | ||
| headers["x-ms-meta-keep"] = "ok" | ||
| request = make_request( | ||
| "https://acct.blob.core.windows.net/c/b?comp=block&sv=2026-04-06&sig=SECRET", | ||
| headers=headers, | ||
| ) | ||
| request.context["insecure_domain_change"] = True | ||
|
|
||
| StorageSensitiveHeaderCleanupPolicy().on_request(request) | ||
|
|
||
| assert "sig=" not in request.http_request.url | ||
| assert "sv=2026-04-06" in request.http_request.url | ||
| assert "comp=block" in request.http_request.url | ||
|
|
||
| for header in self.SENSITIVE_HEADERS: | ||
| assert header not in request.http_request.headers | ||
|
|
||
| assert request.http_request.headers["x-ms-meta-keep"] == "ok" | ||
|
|
||
| def test_no_cleanup_when_no_redirect(self): | ||
| request = make_request( | ||
| "https://acct.blob.core.windows.net/c/b?sig=SECRET", | ||
| headers=dict(self.SENSITIVE_HEADERS), | ||
| ) | ||
| StorageSensitiveHeaderCleanupPolicy().on_request(request) | ||
|
|
||
| assert "sig=SECRET" in request.http_request.url | ||
| for header, value in self.SENSITIVE_HEADERS.items(): | ||
| assert request.http_request.headers[header] == value | ||
|
|
||
| def test_no_cleanup_when_disabled(self): | ||
| request = make_request( | ||
| "https://acct.blob.core.windows.net/c/b?sig=SECRET", | ||
| headers=dict(self.SENSITIVE_HEADERS), | ||
| ) | ||
| request.context["insecure_domain_change"] = True | ||
|
|
||
| StorageSensitiveHeaderCleanupPolicy(disable_redirect_cleanup=True).on_request(request) | ||
|
|
||
| assert "sig=SECRET" in request.http_request.url | ||
| for header, value in self.SENSITIVE_HEADERS.items(): | ||
| assert request.http_request.headers[header] == value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.