Repository navigation
fix(storage): use code-point ordering for canonical headers - #9841
itsrayeedscodespace wants to merge 1 commit into
Conversation
Sort lowercased header names by character code to match the V4 signed header list and avoid locale-dependent signature mismatches. Add V4 signing-input and V2 regression coverage. Fixes googleapis#9840
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request updates the header sorting logic in URLSigner to use code-point order instead of localeCompare for canonical headers, and adds corresponding test cases for V2 and V4 header ordering. The feedback suggests using a regular expression like /\r?\n/ instead of a literal newline character when splitting strings in tests to ensure cross-platform compatibility with Windows line endings.
| 'host:storage.googleapis.com\n' + testCase.canonical; | ||
| const signedHeaders = headers | ||
| .trim() | ||
| .split('\n') |
There was a problem hiding this comment.
When splitting string content by lines, use a regular expression like /\r?\n/ instead of '\n' to ensure cross-platform compatibility with Windows line endings (\r\n), and include test cases with \r\n line endings to verify this behavior.
.split(/\r?\n/)References
- When splitting string content by lines, use a regular expression like /\r?\n/ instead of '\n' to ensure cross-platform compatibility with Windows line endings (\r\n), and include test cases with \r\n line endings to verify this behavior.
Description
This change sorts canonical signing headers by character code.
Impact
Signed URLs use matching canonical and signed header orders across locales.
Changes
localeComparewith direct string comparison after lowercasing header names inURLSigner.getCanonicalHeaders.signedHeaders, as required by the GCS canonical request specification. Valid HTTP header names are ASCII, so JavaScript code-unit ordering agrees with code-point ordering here.Testing
X-Goog-SignedHeaders, and exact string passed to mocked signing credentials, including the canonical request SHA-256 digest.node ../../bin/run-test.cjs --no-c8 --no-parallel build/cjs/test/signer.js: 82 passing; also 82 passing withLANG=lt_LT.UTF-8.pnpm install --frozen-lockfile --filter @google-cloud/storage...,pnpm run compile(CJS and ESM), andpnpm test: 1,112 passing.pnpm run check,pnpm exec prettier --check src/signer.ts test/signer.ts, andgit diff --check: passed.Alternatives
Keeping
localeCompareproduces signatures inconsistent with the advertised signed header list for valid header names. Locale-specific collation options still do not express the protocol's character-code ordering. Direct comparison of the already-lowercased names is sufficient, requires no helper or API changes, and compares names independently of header values.Fixes #9840