Reject CR in quoted-string parameter values per RFC 7230 - #28
Merged
Conversation
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.
Problem
parse_quoted_valuespecial-cases'\n'(LF) and returnsErr(InvalidParamValue), but the catch-all_ => ()arm accepts'\r'(CR) and all other CTLs asqdtext-- an incomplete control-character filter. Per RFC 7230 section 3.2.6,qdtextexcludes all CTLs except HTAB (CR is forbidden); per RFC 2045 section 5.1qtextexplicitly excludes CR.Because the parser is zero-copy,
Display/to_stringround-trips the raw CR byte verbatim:text/plain; x="foo\rbar"parses toOkand re-serializes with the raw CR intact -- a CRLF/header-splitting vector when a parsedMediaTypeis written into a response header.Evidence
text/plain; x="foo\rbar"-> Ok,to_string()preserves raw CR.mime.ParseMediaType-> REJECT ("mime: invalid media parameter").x="foo\nbar"(LF) but acceptsx="foo\rbar"(CR); RFC treats CR and LF identically, so the split is unambiguously the incomplete filter.Fix
Widen the existing reject arm to also reject
'\r':'\n' | '\r' => return Err(MediaTypeError::InvalidParamValue). Minimal, style-matching, with an RFC-citing comment. Catch-all and quoted-pair arms unchanged (out of scope).Tests
cargo test --all-features: 42 passed (27 unit incl. new test + 1 codegen + 14 doc-tests).cargo fmt --checkclean on touched file. Clippy: 0 new warnings/errors vs HEAD. New testparse_quoted_value_ctl_filter(HTAB/SP/VCHAR valid -> Ok; raw CR/LF/CRLF -> Err). Pre-fix: fails (Ok(...)whenErrexpected for CR); post-fix: pass. Harness re-run on fixed code: CR and LF both rejected symmetrically; 0 accepts of raw CR (was 1).Out of scope: NUL/DEL among CTLs (Go
mimeis also lenient on those).