Repository navigation
fix(http-signature): fix signature validation and add tests - #10
Merged
Merged
Conversation
2 tasks
adrianboros
force-pushed
the
fix/http-signature-validation-hardening
branch
from
October 7, 2026 07:40
7e25e53 to
dbeb2d9
Compare
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Signature parsing currently accepts malformed colon-delimited forms.
Review effort: Balanced
Findings: 1
What changed in this PR
Fixes HTTP signature validation failures and hardens malformed-input handling.
Changes:
- Corrects content-digest and Ed25519 JWK verification.
- Normalizes headers and aligns body handling between signing and validation.
- Adds signature tests, CI, and release notes.
| File | Description |
|---|---|
lib/Utils/HttpSignature.php |
Fixes and hardens signature handling. |
tests/Http/Signature/ValidateSignatureTest.php |
Adds validation regression coverage. |
.github/workflows/ci.yml |
Adds automated tests and checks. |
CHANGELOG.md |
Documents the fixes and CI. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This was referenced Oct 7, 2026
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 #9 (merged).
Summary
#9 makes
content-digestrequired when a request has a body. That fix is correct. But the validation code around it did not work:verifyContentDigestthrew an exception for every validContent-Digestheader.bakame/http-structured-fieldsreturnsItemobjects, notByteSequence. So no signed request with a body could pass validation.validateSignaturethrew an exception for every JWK. It passed the base64urlxvalue tosodium_crypto_sign_publickey, which expects a 96-byte key pair.There were no tests for this code, so these bugs were not found.
Changes
verifyContentDigest: read the value from theItem. Returnfalsefor an empty, malformed or unsupported header. Compare withhash_equals.validateSignature: decode the JWKxvalue. Checkkty,crvand key length. Acceptsig1=<b64>andsig1=:<b64>:(RFC 9421, used by the Node library). Returnfalseinstead of throwing.Authorizationheader that was not signed was not detected if its name was not lowercase.false(they do not throw) for:methodorurlheadersSignature-Inputwith more than onesig1="0"is now treated as a body, the same as the validator.createHeadersno longer adds unsignedContent-*headers for an empty body.tests/Http/Signature/ValidateSignatureTest.phpwith 23 tests. They cover sign-then-validate round trips, body swap, tampering, bad digests, bad JWKs and malformed input.Known gaps
These are not part of this PR:
createdorexpires, so a signature can be replayed.keyidis not matched to the JWKkid.content-typeandcontent-lengthmust be present, but they do not have to be signed.Content-TypeandAuthorizationwith case-sensitive names.lib/Utilsat level 1. On the fulllib, PHPStan crashes on the exception classes, and level 2 shows errors in old docblocks.tests/Services, which has old style issues.Testing
vendor/bin/phpunit tests: 109 tests pass on PHP 8.3.lib/Utils, level 1) and Pint pass.