Skip to content

feat(hmac-auth): default signed_headers to ["date"]#13388

Open
shreemaan-abhishek wants to merge 3 commits into
apache:masterfrom
shreemaan-abhishek:fix-hmac-auth-default-signed-headers
Open

feat(hmac-auth): default signed_headers to ["date"]#13388
shreemaan-abhishek wants to merge 3 commits into
apache:masterfrom
shreemaan-abhishek:fix-hmac-auth-default-signed-headers

Conversation

@shreemaan-abhishek
Copy link
Copy Markdown
Contributor

Description

This PR defaults the hmac-auth plugin's signed_headers to ["date"].

Previously, signed_headers had no default. When a route operator did not configure it, the plugin's generate_signature reduced the signing string to just keyId. The Date header was therefore not bound into the HMAC, even though clock_skew is enabled by default and the documentation describes it as protection against stale requests. Defaulting signed_headers to ["date"] ensures the request's Date value is always part of the signing string unless the operator explicitly opts out.

Documentation in docs/en/latest/plugins/hmac-auth.md and docs/zh/latest/plugins/hmac-auth.md has been updated to reflect the new default and to clarify how clock_skew and signed_headers interact.

Which issue(s) this PR fixes:

Fixes # N/A

Breaking change

Clients whose Authorization: Signature ... value does not currently list date in its headers="..." clause will start receiving 401 responses from routes whose hmac-auth plugin does not explicitly override signed_headers. The documented Python example in docs/en/latest/plugins/hmac-auth.md already binds date, so clients following the docs are unaffected. Operators who need the prior behavior can set signed_headers: [] explicitly.

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

Previously signed_headers had no default. With no operator
configuration, the signing string degenerated to just keyId and
the Date header was not bound into the HMAC. Defaulting to ["date"]
ensures the request's Date value is part of the signing string by
default, so a refreshed Date on an existing Authorization causes
HMAC verification to fail.

Existing routes that explicitly set signed_headers keep their
configuration unchanged.
Add a regression case that locks in the documented compatibility
fallback: when an operator sets signed_headers to an empty array,
a request whose Authorization declares only @request-target is
accepted.
@shreemaan-abhishek shreemaan-abhishek marked this pull request as ready for review May 19, 2026 07:27
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels May 19, 2026
When a route's signed_headers requires a specific header (e.g. the
new ["date"] default) but the client's Authorization carries no
headers="..." clause at all, the plugin previously returned the
opaque "headers missing" diagnostic. Treat the absent clause as
an empty declared-headers list and walk conf.signed_headers so the
emitted error names the specific header the client must add.

Update TEST 36 to use ngx.print so the asserted body does not pick
up an extra trailing newline.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant