Skip to content

fix(storage): validate bucket name in signed URL requests - #16721

Open
nidhiii-27 wants to merge 3 commits into
mainfrom
fix/storage-signed-url-bucket-validation
Open

nidhiii-27 wants to merge 3 commits into
mainfrom
fix/storage-signed-url-bucket-validation

Conversation

@nidhiii-27

@nidhiii-27 nidhiii-27 commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

SignUrlRequestCommon::Validate() now rejects empty bucket names (unless BucketBoundHostname is set), dot segments, and characters outside [A-Za-z0-9._-], and both V2SignUrlRequest and V4SignUrlRequest run this check before signing. Existing signed URL generation for valid bucket names remains unchanged. Updated unit tests in google/cloud/storage/client_sign_url_test.cc and google/cloud/storage/internal/signed_url_requests_test.cc.

SignUrlRequestCommon::Validate() now checks that the bucket name does not contain '/' and returns an invalid-argument status otherwise, and both V2SignUrlRequest and V4SignUrlRequest run this check before signing. Existing signed URL generation for valid bucket names remains unchanged. Added unit tests in google/cloud/storage/client_sign_url_test.cc covering bucket name validation for V2 and V4 signed URL requests.

[Generated-by: AI]
@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Nov 29, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces bucket name validation for V2 and V4 signed URL requests, ensuring that bucket names do not contain a '/' character. It implements a Validate() method in SignUrlRequestCommon and propagates this validation to both V2SignUrlRequest and V4SignUrlRequest, with corresponding unit tests added to verify the behavior. The feedback suggests renaming the Status variable valid to status in Client::SignUrlV2 to improve readability and maintain consistency with other validation routines.

Comment thread google/cloud/storage/client.cc Resolved
@nidhiii-27 nidhiii-27 added the storage-bug-immunity Generated by storage-bug-immunity skill label Nov 29, 2026
Renamed the local Status variable in Client::SignUrlV2 from valid to status for consistency with V4SignUrlRequest::Validate. Existing signed URL validation and signing behavior remain unchanged.

[Generated-by: AI]
@codecov

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.21875% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.79%. Comparing base (4a2bfb0) to head (87bf4a0).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
google/cloud/storage/client_sign_url_test.cc 98.18% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main   #16721    +/-   ##
========================================
  Coverage   92.78%   92.79%            
========================================
  Files        2277     2277            
  Lines      228147   228276   +129     
========================================
+ Hits       211696   211831   +135     
+ Misses      16451    16445     -6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nidhiii-27
nidhiii-27 marked this pull request as ready for review November 29, 2026 17:41
@nidhiii-27
nidhiii-27 requested review from a team as code owners November 29, 2026 17:41

@kalragauri kalragauri 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.

A few additional findings:

  • PolicyDocumentV4Request::Url also interpolates policy_document().bucket unencoded into both path-style and virtual-hosted-style URLs, and Client::SignPolicyDocumentV4 currently has no bucket-name validation. Should PolicyDocumentV4Request share this bucket-name check here, or be handled in a follow-up PR?
  • nit: existing V4SignUrlRequest::Validate() checks are unit-tested directly in signed_url_requests_test.cc. Consider adding direct unit tests there for V2SignUrlRequest::Validate() (both valid and invalid bucket names) and for V4SignUrlRequest::Validate() bucket validation alongside VirtualHostname and BucketBoundHostname.

SignUrlRequestCommon::Validate() now rejects empty bucket names (unless BucketBoundHostname is set), dot segments, and characters outside [A-Za-z0-9._-], and V2SignUrlRequest and V4SignUrlRequest run this check before signing. Existing signed URL generation for valid bucket names remains unchanged. Updated unit tests in google/cloud/storage/client_sign_url_test.cc and google/cloud/storage/internal/signed_url_requests_test.cc.

[Generated-by: AI]
@nidhiii-27

Copy link
Copy Markdown
Contributor Author

Re: feedback from @kalragauri

  • We will handle PolicyDocumentV4Request / Client::SignPolicyDocumentV4 bucket validation in a dedicated follow-up PR so this change stays focused on signed URL requests.
  • Done — added direct V2SignUrlRequest::Validate() and V4SignUrlRequest::Validate() bucket-name unit tests (including VirtualHostname and BucketBoundHostname combinations) in google/cloud/storage/internal/signed_url_requests_test.cc.

Co-authored by AI Agent

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

Labels

ai-generated api: storage Issues related to the Cloud Storage API. storage-bug-immunity Generated by storage-bug-immunity skill

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants