Repository navigation
fix(http-signature): check signature time, key id and signed content headers - #12
Merged
Merged
Conversation
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.
Follow-up to #10. It fixes the known gaps listed there.
Summary
The signature validators did not check when a signature was made, did not check that
keyidmatched the key, and did not requirecontent-typeandcontent-lengthto be signed. The signer read some header names with case-sensitive names.Changes
Validators:
Read
createdandexpiresfromSignature-Input. Returnfalsewhen:createdis missingcreatedis older thanmaxAge(default 300 seconds)createdis more thanclockSkew(default 60 seconds) in the futureexpiresis not later than now, or is beforecreatedThis limits replay of old signatures. It does not stop a replay inside the time window, because there is no nonce store.
validateSignatureHeadersandvalidateSignaturetake an optional last argument:['maxAge' => ..., 'clockSkew' => ..., 'now' => ...]. A value that is not a non-negative integer throwsInvalidArgumentException.validateSignaturereturnsfalsewhen thekeyidparameter does not match the JWKkid.When the request has a body,
content-lengthandcontent-typemust be signed, not only present.One strict parser (
parseSigInput) reads the components and the parameters:Before, two parsers read the same header in different ways.
Signer:
AuthorizationandContent-Typewith any name case.createHeadersignores callerContent-*headers with other name cases when it signs.ApiClient:Authorization,Hostand signature headers it sets replace caller headers with the same name in another case, so each header is sent once.Compatibility
@interledger/http-signature-utils) and Rafiki still validate. They signcontent-digest,content-lengthandcontent-typefor requests with a body, and sendkeyidandcreated.alg,nonceandtagparameters, and a futureexpires.ApiClientare the same as before when the caller uses the default headers.Testing
vendor/bin/phpunit tests: 125 tests pass on PHP 8.3.created,expires, bad parameters,keyidandkid, unsigned content headers, hand-signed Node style inputs, bad options, header name case in the signer andApiClient, and key ID characters.lib/Utils, level 1) and Pint pass.