Skip to content

fix(web-bot-auth): reject Signature-Agent URIs with an empty host - #163

Merged
thibmeu merged 2 commits into
cloudflare:mainfrom
KonstantinMirin:fix/signature-agent-https
Nov 25, 2026
Merged

thibmeu merged 2 commits into
cloudflare:mainfrom
KonstantinMirin:fix/signature-agent-https

Conversation

@KonstantinMirin

@KonstantinMirin KonstantinMirin commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Revised 2026-11-17: #177 has merged, so this PR now contains only the empty-host change, merged with current main.

draft-ietf-webbotauth-httpsig-protocol-01 Section 5.2.1 requires each Signature-Agent member value to be an absolute URI "whose scheme MUST be https". RFC 9110 Section 4.2.2 says: "A sender MUST NOT generate an "https" URI with an empty host identifier. A recipient that processes such a URI reference MUST reject it as invalid."

After #176 (Rust) and #177 (TypeScript), both parsers check the URL that the WHATWG URL parser returns. That parser takes a host from values that have none, so both parsers accept them, and the verifier fetches a different URL from the one the signer sent:

Value Parsed as
https:///x.test https://x.test/
https:x.test https://x.test/
https:\x.test https://x.test/

This change checks the value as sent in both parsers: it must start with https://, in any case, followed by a host. Otherwise the parser raises Signature-Agent must name a host.

It also adds TypeScript and Rust tests for the Section 5.2.1 rules that #176 and #177 implement without tests:

  • An http member is rejected in the dictionary form, the type=cimd form, a header that mixes it with an https member, and the legacy String form.
  • An http member that carries parameters is ignored, as "A verifier MUST ignore a member that carries parameters" requires.
  • An upper-case HTTPS:// scheme is accepted, because URI schemes are case-insensitive.
  • verify() does not call the resolver for an http member.

Fixes #162 together with #177.

Tests

  • packages/web-bot-auth: 62 passed. Without the source change, the four empty-host cases fail and the others pass.
  • crates/web-bot-auth: 57 passed, with Rust 1.95 because sfv 0.16 requires it. Without the source change, rejects_https_signature_agent_with_an_empty_host fails and the others pass. Every test-rust step in pullrequest.yml passes, including the wasm32-unknown-unknown build, clippy -D warnings, rustfmt, and cargo doc.
  • npm run lint is clean, and the other workspaces' tests pass: http-message-sig 35, jsonwebkey-thumbprint 2, and verification-workers 33.
  • The two parsers return the same outcome for 17 Signature-Agent headers: http and https members, with and without parameters, legacy and dictionary forms, and the empty-host values above.

Compatibility

Both parsers now reject a Signature-Agent value such as https:///x.test or https:x.test. Nothing in the repository's examples, bench fixtures, or test vectors uses one.

@AkshatM

AkshatM commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

@KonstantinMirin Thank you for the contribution! I think this change is safe to make and doesn't affect any users - we at least aren't observing anyone using HTTP for verification.

Kindly fix the merge conflicts, and I will merge and include.

@KonstantinMirin
KonstantinMirin force-pushed the fix/signature-agent-https branch from 517cbd5 to 41b680b Compare November 5, 2026 20:32
@KonstantinMirin

Copy link
Copy Markdown
Contributor Author

Rebased onto main and fixed the conflicts. #176 already makes the Rust parser reject http for every member form, so the Rust source change and the parse_link cleanup are gone from this PR. What remains is the TypeScript fix and a Rust test for the http rejection. I updated the description to match.

@clanky-the-clanker

clanky-the-clanker Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

This pull request's reviews are posted as pull request reviews: see the review of c349088d.

@KonstantinMirin KonstantinMirin changed the title fix(web-bot-auth): require https for directory Signature-Agent members fix(web-bot-auth): reject Signature-Agent URIs with an empty host Nov 5, 2026
@KonstantinMirin

Copy link
Copy Markdown
Contributor Author

Correction to my earlier comment: #176 does not reject http for every member form. Under protocol-01 Section 5.2.1 a member that carries parameters is ignored, whatever its scheme, and #176 does that correctly. The rest of this PR followed protocol-00, so I reworked it on top of #177 for protocol-01. What remains is one source change in both parsers, rejecting an https value with an empty host (RFC 9110 Section 4.2.2), plus Rust and TypeScript tests for the Section 5.2.1 rules. The description has the details. Until #177 merges, the diff includes it; the change here is the last commit.

@KonstantinMirin
KonstantinMirin force-pushed the fix/signature-agent-https branch from 41b680b to c349088 Compare November 5, 2026 21:21
@thibmeu

thibmeu commented Nov 6, 2026

Copy link
Copy Markdown
Member

@clanky-the-clanker review

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 1498264f.

This review, of c349088d

✅ Approved — The empty-host rejection is correct and the same in the Rust and TypeScript parsers, and tests in both languages cover it. No defects found.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No security issues found. The verifier now rejects https values with no host, which the URL parser would otherwise rewrite to a different URL from the one the signer sent.


📖 AGENTS.md: ✅ LGTM

No issues found.


📋 Code Quality: ✅ LGTM

The Rust names_host check uses uri.get(..8), so it cannot panic on a short value or a multi-byte character, and the TypeScript regex behaves the same way. Values with a ?, @ or : right after https:// are rejected by the URL parse that runs first. Tests in both languages cover http rejection, empty hosts, upper-case HTTPS://, and http members with parameters being ignored.


⚡ Performance: ✅ LGTM

No performance issues found.


📝 Documentation: ✅ LGTM

No documentation issues found.


Reviewed commit: c349088d

@thibmeu thibmeu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. thanks for the help. can be merged after #177

@KonstantinMirin

Copy link
Copy Markdown
Contributor Author

@thibmeu #177 has merged, so this is ready. I merged main into the branch, and the diff is now only the empty-host change in the Rust and TypeScript parsers, with its tests. CI has not started on the new commit (762f46f) yet, so it may need a workflow approval. All pullrequest.yml steps pass locally.

@thibmeu

thibmeu commented Nov 25, 2026

Copy link
Copy Markdown
Member

@clanky-the-clanker review

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Out of date: this review is of 1498264f; the pull request is now at 03af03e7. Someone with write access can comment clanky review (or clanker review or @clanky-the-clanker review) to review the new commits.

✅ Approved — Both parsers now check the authority of the value as sent, before URL parsing can repair it. The Rust and TypeScript checks reject the same values, tests cover them, and no defects were found.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No security issues found. Both parsers now fail closed on https values with no host. A tab or newline inside the authority would be stripped by the URL parser, but it cannot reach this check: Structured Field strings and the legacy String form carry only printable ASCII.


📖 AGENTS.md: ✅ LGTM

No issues found.


📋 Code Quality: ✅ LGTM

The reworked validate_discovery_uri in Rust and validateDiscoveryURI in TypeScript both check the scheme without regard to case. They then check that the raw authority is not empty, and only after that run the URL parser, so WHATWG normalisation cannot repair a value first.

  • Rust and TypeScript agree. Rust splits the value on the first :. It then takes the authority after // and up to the first /, \, ? or #. The TypeScript regex /^https:\/\/[^/\\?#]/i rejects the same cases.
  • A value without a colon cannot panic. split_once(':').unwrap_or_default() returns two empty strings, so the parser reports "must use https".
  • Other bad authorities still fail. https://:443 and https://user@/x pass the raw check, and the URL parse that follows rejects them.
  • The new tests are escaped correctly. Both languages test a real https://\host value. The upper-case HTTPS:// legacy case is still covered, and the URI is kept as sent.

⚡ Performance: ✅ LGTM

No performance issues found.


📝 Documentation: ✅ LGTM

No documentation issues found.


Reviewed commit: 1498264f

KonstantinMirin and others added 2 commits November 25, 2026 09:53
RFC 9110 Section 4.2.2 says a recipient that processes an https URI with
an empty host MUST reject it as invalid, and
draft-ietf-webbotauth-httpsig-protocol-01 Section 5.2.1 requires each
member value to be an absolute https URI. Both parsers check the URL that
the WHATWG parser returns, and that parser takes a host from
"https:///x", "https:x", and "https:\x". The verifier then fetched a
different URL from the one the signer sent.

Check the value as sent in both parsers: it must start with "https://",
in any case, followed by a host.

Add matching TypeScript and Rust tests for the Section 5.2.1 rules that
had none: an http member is rejected in the dictionary, type=cimd, mixed,
and legacy forms; an http member that carries parameters is ignored; and
an upper-case https scheme is accepted. A verify() test checks that the
resolver is not called for an http member.
Split the raw scheme and authority without byte offsets. Keep focused
regression cases and reuse the existing mixed-case legacy coverage.
@thibmeu
thibmeu force-pushed the fix/signature-agent-https branch from 1498264 to 03af03e Compare November 25, 2026 08:53
@thibmeu
thibmeu merged commit ab3b4ec into cloudflare:main Nov 25, 2026
5 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.

Signature-Agent parsers accept an http directory member

3 participants