Skip to content

getSignedUrl with cname results in SignatureDoesNotMatch error #859

@rhodgkins

Description

@rhodgkins

Note that this works fine with v2. I thought it did, but it actually no longer does.

Environment details

  • OS: macOS 10.14.6
  • Node.js version: v8.16.1
  • npm version: 6.4.1
  • yarn version: 1.17.3
  • @google-cloud/storage version: 3.2.1

Steps to reproduce v2

file.getSignedUrl({
 version: 'v2',
 action: 'read',
 expires: Date.now() + 10000000,
 cname: 'https://storage.customhostname.com'
}, (err, url) => {

})

With cname, the URL doesn't work in the browser.

However, sending the same request using curl works:

curl 'https://storage.dev.bookcreator.com/data%2Fi4rNhrOGJgNGlzELwesBcVrSfnG2%2Fbooks%2Fqle8FcNGSNGXQGd1EElspA%2Fresources%2FQC5Qdp5gQgeCMw7AQ18nmw.m4a?GoogleAccessId=api-service%40bookcreator-dev.iam.gserviceaccount.com&Expires=1568829600&Signature=oDAGX4myOoD%2F1UrWPhKOhl2WCw09fQ%2FatkJk5C8%2Bvk4FV%2F5t5lj2Kr3EUNUkQc2jm7vMg1X1XGu8y23sTIklW525f6VbJvN7MjHSGSnh317FO%2Fv6lTBVSekmN7CfUY4Bds%2BdcWYj%2FgI%2FjPFqXMsjmr%2Bqs4wYGRZJ0P6%2BiGUgX8WueF%2F0LNdsI44OsZiZ7z%2FR3vXR%2BTzCfRfxOMETAYrn8jjjITMJpQ1UO7PVYc5E0aAAT0URh816T%2BSee%2Fu3UNkD0hUMJbQC6XtiqPsOawHb%2Bi%2FCNr0R7yjYuluKnIuCe51oIBVQdG9iNTBZD8oJFsPtgrMufibXgS2e%2BuJcTPbMww%3D%3D' -Lv > /dev/null

But sending the same user-agent as the browser, causes a 403:

curl 'https://storage.dev.bookcreator.com/data%2Fi4rNhrOGJgNGlzELwesBcVrSfnG2%2Fbooks%2Fqle8FcNGSNGXQGd1EElspA%2Fresources%2FQC5Qdp5gQgeCMw7AQ18nmw.m4a?GoogleAccessId=api-service%40bookcreator-dev.iam.gserviceaccount.com&Expires=1568829600&Signature=oDAGX4myOoD%2F1UrWPhKOhl2WCw09fQ%2FatkJk5C8%2Bvk4FV%2F5t5lj2Kr3EUNUkQc2jm7vMg1X1XGu8y23sTIklW525f6VbJvN7MjHSGSnh317FO%2Fv6lTBVSekmN7CfUY4Bds%2BdcWYj%2FgI%2FjPFqXMsjmr%2Bqs4wYGRZJ0P6%2BiGUgX8WueF%2F0LNdsI44OsZiZ7z%2FR3vXR%2BTzCfRfxOMETAYrn8jjjITMJpQ1UO7PVYc5E0aAAT0URh816T%2BSee%2Fu3UNkD0hUMJbQC6XtiqPsOawHb%2Bi%2FCNr0R7yjYuluKnIuCe51oIBVQdG9iNTBZD8oJFsPtgrMufibXgS2e%2BuJcTPbMww%3D%3D' -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36' -Lv > /dev/null

If you change the user-agent to just user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) it also works.

The v2 signing used to work (but unsure when it stopped it stopped working around 1700 yesterday [GMT]).

Steps to reproduce v4

I thought that maybe the legacy (as the docs called it) v2 had been deprecated so tried the v4 and this doesn't work either.

file.getSignedUrl({
 version: 'v4',
 action: 'read',
 expires: Date.now() + 10000000,
 cname: 'https://storage.customhostname.com'
}, (err, url) => {

})

The URL produced does have the correct host, but on going to the URL you get a SignatureDoesNotMatch error.
Removing the cname results in a working URL.

E.g.: with cname:

https://storage.dev.bookcreator.com/data%2Fi4rNhrOGJgNGlzELwesBcVrSfnG2%2Fbooks%2Fqle8FcNGSNGXQGd1EElspA%2Fresources%2FQC5Qdp5gQgeCMw7AQ18nmw.m4a?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=api-service%40bookcreator-dev.iam.gserviceaccount.com%2F20190918%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20190918T143035Z&X-Goog-Expires=12565&X-Goog-SignedHeaders=host&X-Goog-Signature=484a09592958f698cb72e534cc82578f439ba6e6d7ceccc3b50e4d89b78afb6e3566bd9e9d1c160213b6c76e30dbc1ff5a6d43a8bb060219a99a6c7a2183745418021b1c573b30e2e9a0ff50a87ff0a38c5b472577cfd76d4bae41e01e8bd001dd57bb227b14e0bc6a431c16f556e5c2a39a9433eaaa74ce5864a6fa7455888dc11867e716821c99be7854b6a19d8a07c1985a25374b472039ee351cf5f92e7b7706d04f53985d11ce0d3444a005eea3b8079b5bc319146b68478e87821dc0cad51a895eea5d9516410a4691896e72fecc627e4cb6c1815856568fbba046b5c52fe415857896389fb769b66de7d1635ab48a3c35f95361ab12635eabf88e2402

Results:

<Error>
   <Code>SignatureDoesNotMatch</Code>
   <Message>
      The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.
   </Message>
   <StringToSign>
      GOOG4-RSA-SHA256 20190918T143035Z 20190918/auto/storage/goog4_request 75304e5ca664b15a1fbbebca700d83f4fbe48fc7bfe8db70399ce7fbc3ba0b38
   </StringToSign>
   <CanonicalRequest>
      GET /data%2Fi4rNhrOGJgNGlzELwesBcVrSfnG2%2Fbooks%2Fqle8FcNGSNGXQGd1EElspA%2Fresources%2FQC5Qdp5gQgeCMw7AQ18nmw.m4a X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=api-service%40bookcreator-dev.iam.gserviceaccount.com%2F20190918%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20190918T143035Z&X-Goog-Expires=12565&X-Goog-SignedHeaders=host host:storage.dev.bookcreator.com host UNSIGNED-PAYLOAD
   </CanonicalRequest>
</Error>

Without cname downloads the file: https://storage.googleapis.com/bookcreator-dev.appspot.com/data%2Fi4rNhrOGJgNGlzELwesBcVrSfnG2%2Fbooks%2Fqle8FcNGSNGXQGd1EElspA%2Fresources%2FQC5Qdp5gQgeCMw7AQ18nmw.m4a?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=api-service%40bookcreator-dev.iam.gserviceaccount.com%2F20190918%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20190918T143301Z&X-Goog-Expires=12419&X-Goog-SignedHeaders=host&X-Goog-Signature=636007c44a015244a9d30379dc326a82895c9b3bc0ee0ecd5317d36b4396937198bdd1d9c1f03690e2d26bf7e0ef351116b992e5cbdef25b74d509f0429dda8e7c516f8eb30d1f01656ae090bce206312af436af6df613ca6ae732fadd8da45172ed8cb424e3a96f4c472ec604bf802a86c4b6df1756d401d97ea25e5e4b1ddc1e96c650d3bb8fafd706d9228d282bb73de30025463ed0a03ad268ba06affa2234ea1ca0405e41a8a9006a8fb86719b326cc01696cc5cc0fa0836bac2016157274312f2dc4023f34e8b8d94dfc798910cfbad93591210c682bf45e27fffa0c101bc62a0c3cb5a53d15ca5a509f244b6e11bc30cfe7a667c4240c300d04022d0f

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the googleapis/nodejs-storage API.externalThis issue is blocked on a bug with the actual product.help wantedWe'd love to have community involvement on this issue.needs more infoThis issue needs more information from the customer to proceed.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions