Skip to content

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

Open
duongynhi000005-oss wants to merge 1 commit into
hyperium:masterfrom
duongynhi000005-oss:fix/authority-from-static-full-len-879
Open

duongynhi000005-oss wants to merge 1 commit into
hyperium:masterfrom
duongynhi000005-oss:fix/authority-from-static-full-len-879

Conversation

@duongynhi000005-oss

Copy link
Copy Markdown

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 <duongynhi000005@gmail.com>

This branch has not been deployed

No deployments
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

1 participant