Sanitize HTTP header values to strip CR/LF (RFC 7230 §3.2.4)#38744
Open
Copilot wants to merge 3 commits into
Open
Sanitize HTTP header values to strip CR/LF (RFC 7230 §3.2.4)#38744Copilot wants to merge 3 commits into
Copilot wants to merge 3 commits into
Conversation
Co-authored-by: jeremymeng <7583839+jeremymeng@users.noreply.github.com>
Co-authored-by: jeremymeng <7583839+jeremymeng@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Sanitize header values in createHttpHeaders function
Sanitize HTTP header values to strip CR/LF (RFC 7230 §3.2.4)
May 29, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Sanitizes HTTP header values in @typespec/ts-http-runtime's HttpHeadersImpl to strip CR/LF characters, preventing potential header injection / obs-fold sequences forbidden by RFC 7230 §3.2.4.
Changes:
- Add
normalizeValuehelper that trims whitespace and removes\r/\ncharacters, used byHttpHeadersImpl.set(). - Add a vitest case covering CR, LF, CRLF, and trailing CRLF stripping.
- Document the fix in the
0.3.6 (Unreleased)changelog entry.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| sdk/core/ts-http-runtime/src/httpHeaders.ts | Introduces normalizeValue and routes set() through it to strip CR/LF. |
| sdk/core/ts-http-runtime/test/public/httpHeaders.spec.ts | Adds a test verifying CR/LF/CRLF stripping behavior. |
| sdk/core/ts-http-runtime/CHANGELOG.md | Adds a Bugs Fixed entry describing the sanitization behavior. |
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.
Packages impacted by this PR
@typespec/ts-http-runtimeIssues associated with this PR
Describe the problem that is addressed by this PR
HttpHeadersImpl.set()stored header values viaString(value).trim(), which trims surrounding whitespace but does not remove illegal CR (\r) / LF (\n) characters. Per RFC 7230 §3.2.4, senders MUST NOT generate field-values containing obs-fold (line folding) sequences; leaving these in place allows accidental multi-line values to produce malformed HTTP messages.What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen?
The issue suggested either stripping the offending characters silently or throwing on invalid input. Silent stripping was chosen for consistency with the existing whitespace
trim()behavior and to avoid introducing a breaking change for callers.normalizeValuehelper that trims whitespace and removes\r/\nvia.replace(/[\r\n]/g, "").HttpHeadersImpl.set()now routes values throughnormalizeValue. The constructor delegates toset(), so all entry points are covered.@azure/core-rest-pipeline'screateHttpHeadersdelegates to@typespec/ts-http-runtime, so it inherits this behavior without separate changes.Are there test cases added in this PR? (If not, why?)
Yes. Added a test in
httpHeaders.spec.tscovering CR, LF, CRLF, and trailing CRLF stripping.Provide a list of related PRs (if any)
Command used to generate this PR:**(Applicable only to SDK release request PRs)
Checklists