fix(fetch): reject binary responses and harden HTML sniffing#2690
Open
amitksingh1490 wants to merge 5 commits intomainfrom
Open
fix(fetch): reject binary responses and harden HTML sniffing#2690amitksingh1490 wants to merge 5 commits intomainfrom
amitksingh1490 wants to merge 5 commits intomainfrom
Conversation
tusharmath
reviewed
Mar 25, 2026
| } | ||
|
|
||
| /// Returns true if the Content-Type header indicates binary (non-text) content. | ||
| fn is_binary_content_type(content_type: &str) -> bool { |
Collaborator
There was a problem hiding this comment.
There is a util function we created to detect binary.
Contributor
Author
There was a problem hiding this comment.
ok let me find it don't think it was based on contect-type header
Contributor
Author
There was a problem hiding this comment.
there is no binary detection on http-headers, its on file system. I have moved this to util as we don't want to download and then fail we should fail fast.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reject binary responses in
fetchand harden HTML sniffing to avoid UTF-8 boundary panics.Context
The
fetchtool is designed for text-based web content. Binary endpoints (for example archive downloads) can produce unreadable output and confusing failures when treated as text. The initial HTML sniffing logic also sliced by byte index, which could panic on multibyte UTF-8 boundaries.Changes
curl -fLocommandKey Implementation Details
Binary detection is implemented via
is_binary_content_type, which allowlists text-oriented content types (text/*, JSON, XML, JavaScript, YAML, TOML, CSV, HTML, SVG, Markdown, and empty content-type) and treats all others as binary.Use Cases
.tar.gzURL now fails fast with clear guidance instead of trying to parse binary bytes as textTesting
cargo test -p forge_services test_is_binary_content_type -- --nocaptureLinks