Skip to content

fix(uri): reject unconsumed trailing bytes in Authority::from_static - #882

Merged
seanmonstar merged 1 commit into
hyperium:masterfrom
duongynhi000005-oss:fix/authority-from-static-full-len-879
Nov 17, 2026
Merged

seanmonstar merged 1 commit into
hyperium:masterfrom
duongynhi000005-oss:fix/authority-from-static-full-len-879

Conversation

@duongynhi000005-oss

Copy link
Copy Markdown
Contributor

Fixes #879

Summary

validate_authority_bytes stops scanning at the first /, ?, or # delimiter and returns the byte index where the authority segment ended. create_authority (used by FromStr / TryFrom) checks authority_end != s.len(), whereas Authority::from_static matched Ok(_) and ignored the returned end index—accepting inputs like "https://127.0.0.1" or "example.com/path" that parse::<Authority>() rejects.

Changes

  • Guard Authority::from_static with Ok(end) if end == src.len().
  • Clarify # Panics rustdoc on Authority::from_static.
  • Add unit tests covering scheme prefixes and trailing path, query, and fragment delimiters.

`validate_authority_bytes` stops at the first `/`, `?`, or `#` delimiter and
returns the end index of the authority segment. While `create_authority` checks
`authority_end != s.len()`, `Authority::from_static` matched `Ok(_)` and
discarded the returned offset, allowing strings with a scheme prefix or
trailing path/query/fragment (such as `"https://127.0.0.1"`) to construct an
invalid `Authority`.

Require `Ok(end) if end == src.len()` in `Authority::from_static` so its
validation matches `Authority::from_str`.

Fixes hyperium#879

Signed-off-by: duongynhi000005-oss <[email protected]>

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

Thanks!

@seanmonstar
seanmonstar merged commit a8309a9 into hyperium:master Nov 17, 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.

Authority::from_static does not perform adequate validation

2 participants