Skip to content

feat: Supporting parsing of Accept-Signature header - #176

Merged
dadrus merged 18 commits into
dadrus:mainfrom
rosylilly:feat/parse-accept-signature
Nov 6, 2026
Merged

dadrus merged 18 commits into
dadrus:mainfrom
rosylilly:feat/parse-accept-signature

Conversation

@rosylilly

Copy link
Copy Markdown
Contributor

ParseAcceptSignature returns the signatures a peer requests as SignatureRequest values, so a client can fulfill them without parsing the field itself.

http.Header instead of *Message

#170 discussed taking a *Message to keep the library framework-agnostic. I went with http.Header because parsing this field needs nothing else from a message, and it can then be used without building one. Message users can call ParseAcceptSignature(msg.Header), and http.Header is only a map type from the standard library, so this adds no framework dependency.

Errors per member

A member that can't be used, for example because it names an unsupported component, doesn't affect the others. The usable requests are returned together with a joined error that wraps ErrMalformedData for each unusable member, because RFC 9421 Section 5.2 permits ignoring requests that don't fit. This also matches #174, where a member the caller didn't select can't fail the call. Callers that need every request to be usable can require err == nil. If the field as a whole isn't valid Structured Fields, no requests are returned.

Closes #170

ParseAcceptSignature returns the signatures a peer requests, so a client
can fulfill them without parsing the field itself. A member that can't be
used doesn't affect the others: the usable requests are returned together
with an error for each unusable member.
@codecov

codecov Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.23009% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.71%. Comparing base (77420eb) to head (30c1b09).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
accept_signature.go 97.43% 1 Missing ⚠️
canonicalizer.go 88.88% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #176   +/-   ##
=======================================
  Coverage   97.70%   97.71%           
=======================================
  Files          22       22           
  Lines        1397     1445   +48     
=======================================
+ Hits         1365     1412   +47     
- Misses         32       33    +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@dadrus

dadrus commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Thanks a lot @rosylilly for this PR. Looks very nice. There are however some small issues, which I'm fixing right now. As as soon as these are done, I'll push an update to your branch.

@dadrus
dadrus self-requested a review November 5, 2026 09:04
@dadrus

dadrus commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Your PR made a previously present issue visible: #180.

@dadrus

dadrus commented Nov 5, 2026

Copy link
Copy Markdown
Owner

two things are still open:

  • invalid @query-param identifier - the parser currently accepts e.g., Accept-Signature: sig=("@query-param") and Accept-Signature: sig=("@query-param";name=foo)
  • created/expires flags - the parser currently accepts e.g. Accept-Signature: sig=("@method");created=?0

I'm fixing that now.

@dadrus

dadrus commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

@rosylilly: I'm done with my updates. Here's a short summary of the changes I made beyond merging the latest main branch:

  • Introduced a shared component identifier comparison that considers parameter names, values, and types regardless of their order. This is now also used to detect duplicate identifiers in signature bases and Accept-Signature requests.
  • Moved the static validation of @query-param parameters into canonicalizerFor() and removed the redundant validation during canonicalization.
  • Tightened the validation of created and expires request flags to reject explicit false values.
  • Small update of the example in the README.
  • merged code related to Accept-Signature header creation and parsing into a single file for productive code and test each.
  • moved you test which shows the usage of full signature negotiation incl signing and verifying into one integration_test.go file.

I noticed that you added componentIdentifier.optionValue() to remove quotes from serialized Structured Fields items where possible. Since WithComponents() already accepts fully serialized Structured Fields items in addition to the simplified form, I'm wondering whether it would make more sense to use httpsfv.Marshal() directly when populating SignatureRequest.Components and remove optionValue(). One potential downside is that someone comparing the values returned by SignatureRequest.Components directly against the simplified form would need to account for the different representations. With that said, I'm curious whether there was a particular reason you chose the simplified representation?

I also appreciate your review of my changes. Most of them were related to HMS RFC compliance. Though, not all was possible due to some httpsfv limitations.

@rosylilly

Copy link
Copy Markdown
Contributor Author

Thanks for the updates! LGTM.

On optionValue(): no strong reason. I only wanted to keep Structured Fields syntax out of the result, so I'm fine with removing it and using httpsfv.Marshal().

One nitpick: since the @query-param check moved into canonicalizerFor(), it now runs when Signature-Input is parsed, and getSignatureReferences fails on any label. So a malformed @query-param in a signature that isn't being verified, for example with WithRequiredTag, now fails the whole Verify call. Unsupported component names already behave this way, so it doesn't need to block this PR, but it's worth keeping in mind for #174.

@dadrus

dadrus commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

Thanks @rosylilly. I changed the code to make use of httpsfv.Marshal() directly. While doing that I actually run into yet another challenge - the KeyResolver updated with the last release receives a simplified form as well. I think we should change that to the structured field form as well (in a separate PR). And most probably it would even be better to drop the support for the simplified form entirely. That would made the API much more consistent. What do you think?

Regarding the canonicalizerFor update: Good point. Thank you for raising that. Invalid or malformed signature headers should definitely not lead to a rejection, if the affected signature is irrelevant for the given scope.

@rosylilly

Copy link
Copy Markdown
Contributor Author

LGTM. I agree on both points: changing KeyResolver to the Structured Field form in a separate PR, and dropping the simplified form entirely for a more consistent API.

@dadrus

dadrus commented Nov 6, 2026

Copy link
Copy Markdown
Owner

@rosylilly: The last commits resolve the issue you've reported. If I've not overlooked anything, invalid/malformed signatures are ignored as long as these are not selected for validation. Could you please check as well. I'm now looking whether there are any performance optimizations in the changed code. Other then that, I think the PR is ready for being merged. At least if you don not find anything else, which might be blocking.

@rosylilly

Copy link
Copy Markdown
Contributor Author

I didn't find anything concerning! I think it's good to merge. Performance-wise, I don't think it will cause any problems in practice either.

@dadrus dadrus changed the title feat: Supporting parsing of Accept-Signature feat: Supporting parsing of Accept-Signature header Nov 6, 2026
@dadrus
dadrus merged commit a0fcb76 into dadrus:main Nov 6, 2026
10 checks passed
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.

Parse Accept-Signature on the client side

2 participants