Skip to content

fix(http-message-sig): exclude the fragment from the target URI - #200

Merged
thibmeu merged 2 commits into
cloudflare:mainfrom
konippi:fix/target-uri-empty-fragment
Nov 25, 2026
Merged

thibmeu merged 2 commits into
cloudflare:mainfrom
konippi:fix/target-uri-empty-fragment

Conversation

@konippi

@konippi konippi commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #194.

The fragment check used url.hash, which is empty for a bare #, so the # ended up in @target-uri, @path and @query.

RFC 9110 Section 7.1 excludes the fragment from the target URI, so:

  • Request: the fragment is dropped, as fetch does on the wire.
  • Descriptor targetUri: any # is rejected, since servers handle a raw # differently.

Behavior change: a Request with a fragment now signs without it instead of throwing. Easy to revert if that's not wanted.

@clanky-the-clanker

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

Copy link
Copy Markdown
Contributor

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

@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.

💬 Approved with comments — The fix is correct and consistent with RFC 9110. The only note is an optional test for descriptors with a non-empty fragment.

Findings: 1 suggestion (1 is an inline comment on the diff)

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


📋 Code Quality: 💬 1 suggestion

The fix is correct for bare and non-empty fragments. There is one optional test suggestion.

Recommendation: 💬 Optional Nits

  • [SUGGESTION] Add a descriptor test for a non-empty fragment (and for @target-uri) (packages/http-message-sig/test/core.spec.ts:326)
View full review

What I checked and found correct:

  • url.hash = "" clears both a bare # and a non-empty fragment. url.href keeps a trailing ?, so @query is still ?.
  • The fragment is removed before indexOf("?"), so a ? inside a fragment can't be mistaken for the start of the query.
  • native is set at both places that build a RequestSnapshot.

Optional: the descriptor rejection path is tested only with a bare # and @path.


✅ All other checks passed

🔒 Security: ✅ LGTM

Descriptor target URIs that contain # are still rejected, and the check is stricter than before because it now catches a bare #. For a native Request, the fragment is stripped once and @target-uri, @path and @query are all derived from that stripped string. The signed values therefore match what fetch actually sends.


📝 Documentation: ✅ LGTM

No documentation problems in the changed lines.


Reviewed commit: 5b029d1c

);
});

it("rejects a bare fragment in a descriptor target URI", async () => {

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.

💬 SUGGESTION · Code Quality

Add a descriptor test for a non-empty fragment (and for @target-uri)

The only descriptor rejection test uses a bare # with @path. Add a case with https://example.com/path#frag, and one that requests @target-uri. Together they would show that the new includes("#") check rejects non-empty fragments too, and that every derived component goes through it.

@thibmeu
thibmeu merged commit 6f5d2e5 into cloudflare:main Nov 25, 2026
5 checks passed
@thibmeu

thibmeu commented Nov 25, 2026

Copy link
Copy Markdown
Member

@konippi good catch. thanks for the fix

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.

http-message-sig: trailing "#" in the target URI ends up in @path / @query

2 participants