Skip to content

fix(http-signature): check signature time, key id and signed content headers - #12

Merged
adrianboros merged 1 commit into
mainfrom
fix/http-signature-known-gaps
Oct 7, 2026
Merged

adrianboros merged 1 commit into
mainfrom
fix/http-signature-known-gaps

Conversation

@adrianboros

Copy link
Copy Markdown
Collaborator

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 keyid matched the key, and did not require content-type and content-length to be signed. The signer read some header names with case-sensitive names.

Changes

Validators:

  • Read created and expires from Signature-Input. Return false when:

    • created is missing
    • created is older than maxAge (default 300 seconds)
    • created is more than clockSkew (default 60 seconds) in the future
    • expires is not later than now, or is before created

    This limits replay of old signatures. It does not stop a replay inside the time window, because there is no nonce store.

  • validateSignatureHeaders and validateSignature take an optional last argument: ['maxAge' => ..., 'clockSkew' => ..., 'now' => ...]. A value that is not a non-negative integer throws InvalidArgumentException.

  • validateSignature returns false when the keyid parameter does not match the JWK kid.

  • When the request has a body, content-length and content-type must be signed, not only present.

  • One strict parser (parseSigInput) reads the components and the parameters:

    • components must be quoted lowercase names
    • parameter values must be integers or strings without escapes
    • a parameter must not repeat

    Before, two parsers read the same header in different ways.

Signer:

  • Reads Authorization and Content-Type with any name case.
  • Throws when header names differ only by case, because it is not clear which value to sign.
  • Throws for a key ID with a quote, a backslash or a character outside printable ASCII.
  • createHeaders ignores caller Content-* headers with other name cases when it signs.

ApiClient:

  • Merges headers without regard to name case. The Authorization, Host and signature headers it sets replace caller headers with the same name in another case, so each header is sent once.

Compatibility

  • Signatures from the Node SDK (@interledger/http-signature-utils) and Rafiki still validate. They sign content-digest, content-length and content-type for requests with a body, and send keyid and created.
  • Tests cover parameters in another order, extra alg, nonce and tag parameters, and a future expires.
  • Requests signed by ApiClient are the same as before when the caller uses the default headers.

Testing

  • vendor/bin/phpunit tests: 125 tests pass on PHP 8.3.
  • New tests cover age and future created, expires, bad parameters, keyid and kid, unsigned content headers, hand-signed Node style inputs, bad options, header name case in the signer and ApiClient, and key ID characters.
  • PHPStan (lib/Utils, level 1) and Pint pass.

@adrianboros adrianboros self-assigned this Oct 7, 2026
@adrianboros
adrianboros merged commit 5196efe into main Oct 7, 2026
1 check passed
@adrianboros
adrianboros deleted the fix/http-signature-known-gaps branch October 7, 2026 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant