fix(proxy): classify a presigned SigV4A URL as presigned, not unsigned - #521
Open
MaxFreedomPollard wants to merge 1 commit into
Open
fix(proxy): classify a presigned SigV4A URL as presigned, not unsigned#521MaxFreedomPollard wants to merge 1 commit into
MaxFreedomPollard wants to merge 1 commit into
Conversation
detectSigv4 only accepted AWS4-HMAC-SHA256 as the query-string X-Amz-Algorithm, so a presigned SigV4A URL (X-Amz-Algorithm AWS4-ECDSA-P256-SHA256, plus X-Amz-Region-Set) referencing a masked pair's fake access key id returned null. createSigv4Planner then had nothing to act on and the request went upstream untouched, escaping credentials.sigv4.presigned and credentials.sigv4.sigv4a alike -- including their "deny" defaults. The client got an opaque upstream signature error instead of the 403 the policy promises, and a "passthrough" setting was never what let it through. src/sandbox/aws-sigv4.ts:91 now accepts either signing algorithm in the query check. The shape decides the kind, as the module already documents for a non-AWS Authorization value alongside presigned params: the signature is in the URL, so re-signing would rewrite the URL, which is exactly what "presigned" names. The header-Authorization SigV4A case still classifies as sigv4a, and an unknown X-Amz-Algorithm is still not a SigV4 signature.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
detectSigv4recognizes a presigned URL by theX-Amz-Algorithmquery parameter, but it only acceptedAWS4-HMAC-SHA256(src/sandbox/aws-sigv4.ts:91). A presigned SigV4A URL spells that parameterAWS4-ECDSA-P256-SHA256and addsX-Amz-Region-Set, so it returnednulleven when theX-Amz-Credentialscope named a masked pair's fake access key id.createSigv4Plannerreturnsundefinedon a null detection, so such a request was forwarded exactly as if no masked credential were involved. That slips past both knobs that should govern it:credentials.sigv4.presigned(the signature is in the URL) andcredentials.sigv4.sigv4a(which only ever sees the Authorization-header form). Both default todeny, so the promised behaviour is a 403 naming the case; instead the sandboxed client got an opaque upstream signature failure, because the URL was signed with the placeholder secret. Nothing leaks in either direction, but the policy is not enforced and the failure is not diagnosable.Fix
Accept either signing algorithm in the query check. The kind stays
presigned, which is what the shape means here: the module already documents that the query check "applies whenever the Authorization header does not itself classify", andSigv4ConfigSchemadescribespresignedby shape, "X-Amz-Algorithm/X-Amz-Signature in the query ... the signature lives in the URL itself". That is true of a presigned SigV4A URL for exactly the same reason, and neither algorithm can be re-signed without rewriting the URL. The header-Authorization SigV4A case still classifies assigv4a, and an unrecognizedX-Amz-Algorithmis still not a SigV4 signature at all.Tests
test/sandbox/aws-sigv4.test.ts: a presigned SigV4A URL now classifies aspresignedwith the access key id fromX-Amz-Credential, plus a negative case pinning that an unknownX-Amz-AlgorithmalongsideX-Amz-SignatureandX-Amz-Credentialstays undetected.test/sandbox/credential-aws-pairs.test.ts: the same URL throughcreateSigv4Plannerdenies by default withcredentials.sigv4.presignednamed in the reason, and returnsundefinedunderpresigned: "passthrough".Both new assertions fail on
mainat 66d35e5 (detectSigv4returnsnull; the planner returnsundefinedinstead of a deny) and pass with the change. Verified on macOS arm64 withbun test(1364 tests),npx eslint .,npm run typecheck,npm run build, andnpx prettier --check. The suite has two failures on this machine that reproduce identically on unmodifiedmain: a 5s timeout intest/sandbox/proxy-deny-violations.test.ts, andmitm-leaf: leaf validity span is <= 99 days, which measures 99.0417 days becauseclampValidityadds 99 calendar days withDate.setDateand my local timezone leaves DST inside that window (UTC CI runners never see it).