Repository navigation
fix(storage): validate bucket name in signed URL requests - #16721
nidhiii-27 wants to merge 3 commits into
Conversation
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]
There was a problem hiding this comment.
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.
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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
kalragauri
left a comment
There was a problem hiding this comment.
A few additional findings:
PolicyDocumentV4Request::Urlalso interpolatespolicy_document().bucketunencoded into both path-style and virtual-hosted-style URLs, andClient::SignPolicyDocumentV4currently has no bucket-name validation. ShouldPolicyDocumentV4Requestshare this bucket-name check here, or be handled in a follow-up PR?- nit: existing
V4SignUrlRequest::Validate()checks are unit-tested directly insigned_url_requests_test.cc. Consider adding direct unit tests there forV2SignUrlRequest::Validate()(both valid and invalid bucket names) and forV4SignUrlRequest::Validate()bucket validation alongsideVirtualHostnameandBucketBoundHostname.
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]
|
Re: feedback from @kalragauri
Co-authored by AI Agent |
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.