From a55b5b7094b5a85fcba0a039b699e1fff3e6673c Mon Sep 17 00:00:00 2001 From: Sneha Sahu Date: Thu, 3 Dec 2026 18:55:56 +0000 Subject: [PATCH] docs(storage): warn about V2 signed URL query parameter behavior Document in Storage#signUrl, Storage.SignUrlOption#withV2Signature, and Blob#signUrl Javadocs that V2 Signed URLs do not include query parameters in signature computation, so query parameters can be added, removed, or altered after signing, and recommend withV4Signature() instead. [Generated-by: AI] --- .../main/java/com/google/cloud/storage/Blob.java | 6 ++++++ .../java/com/google/cloud/storage/Storage.java | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java b/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java index 03d9d3f1cbc0..492cd4030900 100644 --- a/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java +++ b/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java @@ -1080,6 +1080,12 @@ public WriteChannel writer(BlobWriteOption... options) { *
  • The default credentials, if no credentials were passed to {@link StorageOptions} * * + *

    Warning: By default, {@code signUrl} uses V2 signing. For V2 Signed URLs, query parameters + * are not used to compute the signature, so query parameters can be added, removed, or altered + * after the URL has been signed. Pass {@link SignUrlOption#withV4Signature()} to use V4 signing + * instead, as query parameters cannot be added, removed, or altered after a V4 signature is + * generated. + * *

    Example of creating a signed URL for the blob that is valid for 2 weeks, using the default * credentials for signing the URL: * diff --git a/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java b/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java index 9d71d8f73711..bf947c199481 100644 --- a/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java +++ b/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java @@ -3044,6 +3044,16 @@ public static SignUrlOption withExtHeaders(Map extHeaders) { /** * Use if signature version should be V2. This is the default if neither this or {@code * withV4Signature()} is called. + * + *

    Warning: For V2 Signed URLs, query parameters are not used to compute the signature, so + * query parameters can be added, removed, or altered after the URL has been signed. Prefer + * {@link #withV4Signature()}, as query parameters cannot be added, removed, or altered after a + * V4 signature is generated. + * + * @see + * Canonical Requests + * @see V2 Signing + * Process */ @TransportCompatibility(Transport.HTTP) public static SignUrlOption withV2Signature() { @@ -4786,6 +4796,12 @@ Blob createFrom( *

  • The default credentials, if no credentials were passed to {@link StorageOptions} * * + *

    Warning: By default, {@code signUrl} uses V2 signing. For V2 Signed URLs, query parameters + * are not used to compute the signature, so query parameters can be added, removed, or altered + * after the URL has been signed. Pass {@link SignUrlOption#withV4Signature()} to use V4 signing + * instead, as query parameters cannot be added, removed, or altered after a V4 signature is + * generated. + * *

    Example of creating a signed URL that is valid for 1 week, using the default credentials for * signing the URL, the default signing method (V2), and the default URL style (path-style): *