Skip to content

[Storage] Validate account endpoints before attaching SAS credentials - #34230

Open
YangAn-microsoft wants to merge 5 commits into
Azure:devfrom
YangAn-microsoft:fix/storage-sas-endpoint-validation
Open

YangAn-microsoft wants to merge 5 commits into
Azure:devfrom
YangAn-microsoft:fix/storage-sas-endpoint-validation

Conversation

@YangAn-microsoft

@YangAn-microsoft YangAn-microsoft commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

🤖 PR Validation — ️✔️ All clear

Breaking Changes Tests
️✔️ None ️✔️ 130/130

Related command

az storage copy
az storage fs directory upload
az storage fs directory download

Description

Validate the actual destination origin before generating or attaching storage SAS credentials. The previous copy URL recognition used a substring regex, allowing Azure-looking hostnames to be treated as storage endpoints.

  • Reuse the origin normalization introduced in {Storage} Validate blob copy source endpoint #34138 through shared Storage URL helpers (DNS case/trailing dots, IDNA, default ports and IPv6), retaining the previous blob-copy behavior.
  • Validate normalized URL origins against account endpoints using the active cloud configuration, or explicitly configured connection-string endpoints resolved by the Storage SDK.
  • Preserve an explicitly selected credential account rather than replacing it from the copy URL.
  • Apply the shared check to generated and supplied SAS credentials, including filesystem directory upload/download callers.
  • Leave external copy URLs unchanged without adding Azure storage credentials.
  • Preserve configured custom endpoints, secondary endpoints, and SAS-only Blob/File connection strings. SAS permissions and lifetime are unchanged.
  • Add offline validator regression coverage and a mocked command-level test; no attacker endpoint is contacted.

This is a draft pending final review and CI. The filesystem callers are hardened at the shared boundary; this does not claim a separately demonstrated exploit through those commands.

Testing Guide

Rerun on the clean branch based on upstream dev at 8112200cfa. Set repository source imports in PowerShell:

$env:PYTHONPATH = "$PWD\src\azure-cli;$PWD\src\azure-cli-core;$PWD\src\azure-cli-telemetry;$PWD\src\azure-cli-testsdk"
  • & '.\.tmp_style_env\Scripts\python.exe' -m unittest azure.cli.command_modules.storage.tests.latest.test_storage_validators azure.cli.command_modules.storage.tests.latest.test_storage_url_helpers azure.cli.command_modules.storage.tests.latest.test_storage_azcopy_scenarios.StorageAzcopyEndpointTests azure.cli.command_modules.storage.tests.latest.test_storage_blob_copy_scenarios.StorageBlobCopySecurityTests — Passed: 60 tests. Transfer and SAS generation are mocked in the command-level regression test.
  • & '.\.tmp_style_env\Scripts\python.exe' -m pylint --rcfile .\pylintrc .\src\azure-cli\azure\cli\command_modules\storage\_validators.py .\src\azure-cli\azure\cli\command_modules\storage\storage_url_helpers.py .\src\azure-cli\azure\cli\command_modules\storage\operations\blob.py — Passed: 10.00/10.
  • git diff --check — Passed before committing.
  • & '.\.tmp_style_env\Scripts\python.exe' -m flake8 --append-config .\.flake8 .\src\azure-cli\azure\cli\command_modules\storage\_validators.py .\src\azure-cli\azure\cli\command_modules\storage\tests\latest\test_storage_validators.py .\src\azure-cli\azure\cli\command_modules\storage\tests\latest\test_storage_azcopy_scenarios.py — Failed on pre-existing test-file E302/E122 findings; compared against HEAD before rebasing and confirmed no remaining new findings.
  • & '.\.tmp_style_env\Scripts\python.exe' -m azdev style storage --pylint — Blocked by local azdev repository/extension configuration; direct repository-configured pylint passed as above.
  • Full azdev command linter, full storage replay suite, and live storage replay were not completed successfully. No live vulnerability replay was performed.
  • Local commit/push hooks reported a missing Python activation script and exited zero; they did not provide additional validation.

History Notes

[Storage] az storage copy, az storage fs directory upload/download: Validate configured account endpoints before attaching SAS credentials


This checklist is used to make sure that common guidelines for a pull request are followed.

Validate parsed endpoint origins against account and trusted connection-string endpoints before SAS generation or attachment. Preserve external URL passthrough without adding storage credentials and cover copy and filesystem validators.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove the manual changelog entry; retain the draft PR History Notes for automated release history generation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use the existing get_account_url helper for primary and secondary standard endpoints without changing SAS destination validation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

🔵 Needs a closer look

Credential-boundary changes need human review, with an unresolved copy regression and incomplete broader storage validation.

1 open finding
What changed in this PR

Hardens storage copy and filesystem transfers by validating account endpoints before attaching SAS credentials.

Changes:

  • Replaces substring matching with parsed-origin validation.
  • Preserves credential account selection and supports configured endpoints.
  • Adds offline validator and mocked command-level regression tests.
File Description
src/​azure-cli/​azure/​cli/​command_modules/​storage/​tests/​latest/​test_storage_validators.py Adds endpoint and credential validation coverage.
src/​azure-cli/​azure/​cli/​command_modules/​storage/​tests/​latest/​test_storage_azcopy_scenarios.py Adds mocked storage copy regression coverage.
src/​azure-cli/​azure/​cli/​command_modules/​storage/​_validators.py Validates endpoint origins before attaching SAS credentials.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/azure-cli/azure/cli/command_modules/storage/_validators.py Outdated
Restrict space rejection to URL authorities and leading whitespace while continuing to reject control characters. Cover Blob and File wildcard paths in both copy directions with generated and supplied SAS credentials.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

🔵 Needs a closer look

Security-sensitive credential routing warrants final human review, particularly while broader storage replay and CI validation remain incomplete.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

Move existing blob-copy origin normalization and comparison into storage_url_helpers. Reuse normalization in the AzCopy SAS trust gate while preserving credential-boundary validation and existing blob-copy semantics. Cover equivalent DNS, IDNA and IPv6 origins.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

🔵 Needs a closer look

Security-sensitive credential routing needs final human review, particularly while broader storage replay validation remains incomplete.

0 open findings

🧠 Review effort: Balanced

@yonzhan

Copy link
Copy Markdown
Collaborator

Storage

@YangAn-microsoft
YangAn-microsoft marked this pull request as ready for review October 16, 2026 05:08
@YangAn-microsoft
YangAn-microsoft requested a review from a team as a code owner October 16, 2026 05:08

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants