fix: preserve Unicode headers for request interceptors#10850
Conversation
There was a problem hiding this comment.
1 issue found across 3 files
Confidence score: 3/5
- There is a concrete regression risk in
lib/core/AxiosHeaders.js: preserving non-Latin1 Unicode header values can reach browser platform APIs that may reject them and throw when requests are sent. - The issue is moderately severe (7/10) with fairly high confidence (8/10), so this is more than a cosmetic concern and could impact real user requests at runtime.
- Pay close attention to
lib/core/AxiosHeaders.js- header sanitization changes may allow invalid browser header values that trigger request-time failures.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="lib/core/AxiosHeaders.js">
<violation number="1" location="lib/core/AxiosHeaders.js:45">
P1: Header sanitization now preserves non-Latin1 Unicode values, but browser adapters pass them through to platform APIs that may reject them and throw at request time.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
|
Pushed a follow-up for the browser-adapter concern:
Local verification:
|
There was a problem hiding this comment.
1 issue found across 7 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="lib/adapters/fetch.js">
<violation number="1" location="lib/adapters/fetch.js:288">
P2: Sanitized headers can still be overridden by the second `fetchOptions` argument when `Request` is used, defeating the new header sanitization and allowing invalid header values to re-enter the request.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| signal: composedSignal, | ||
| method: method.toUpperCase(), | ||
| headers: headers.normalize().toJSON(), | ||
| headers: toByteStringHeaderObject(headers.normalize()), |
There was a problem hiding this comment.
P2: Sanitized headers can still be overridden by the second fetchOptions argument when Request is used, defeating the new header sanitization and allowing invalid header values to re-enter the request.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At lib/adapters/fetch.js, line 288:
<comment>Sanitized headers can still be overridden by the second `fetchOptions` argument when `Request` is used, defeating the new header sanitization and allowing invalid header values to re-enter the request.</comment>
<file context>
@@ -284,7 +285,7 @@ const factory = (env) => {
signal: composedSignal,
method: method.toUpperCase(),
- headers: headers.normalize().toJSON(),
+ headers: toByteStringHeaderObject(headers.normalize()),
body: data,
duplex: 'half',
</file context>
There was a problem hiding this comment.
lib/helpers/sanitizeHeaderValue.js:32-43: Please replace per-char concat with a regex pass for bothisValidUnicodeHeaderValueCharandisValidByteStringHeaderValueChar. Same semantics but faster, and matches the prior implementation.- Can you please add a positive regression test to
axiosHeaders.test.jsthat checks thatset('x', '请求用户')roundtrips throughget('x'is unchanged. Will guard against future refactoring ofnormalizeValuethat could silently break #10849. - Would it be possible to add to
/docs/in the English docs a note about this preservation.
|
Pushed a small follow-up for the requested sanitizer implementation change. What changed:
Local verification:
|
Summary
Preserves Unicode request header values until request interceptors run, so callers can encode values such as Chinese names before the request is sent. The Node HTTP adapter still strips unencoded characters that Node cannot accept right before building the request options.
Linked issue
Fixes #10849
Changes
AxiosHeadersnormalization so interceptors can transform them.http.request.Checklist
index.d.tsandindex.d.cts) — N/A, no public API or type changesSummary by cubic
Preserves non-control Unicode header values until request interceptors run, then sanitizes to byte‑safe values in
http,fetch, andxhrright before sending. Centralizes faster regex-based sanitization inhelpers/sanitizeHeaderValue.js.Description
AxiosHeadersnormalization; still strip CR/LF to prevent injection.helpers/sanitizeHeaderValue.jswithsanitizeHeaderValue,sanitizeByteStringHeaderValue, andtoByteStringHeaderObject.toByteStringHeaderObjectinhttp,fetch, andxhradapters at send time.Docs
Docs updated in
/docs/pages/advanced/headers.mdwith a new “Unicode header values” section, explaining preservation inAxiosHeaders, adapter sanitization, and an interceptor example usingencodeURIComponent. No further changes needed.Testing
httpandfetchadapters: interceptor-encoded Unicode headers reach the server encoded; unencoded Unicode headers are sanitized to empty byte-safe values.xhr: same coverage as above.AxiosHeaders: preserves non-control Unicode; still strips CR/LF to prevent header injection.Semantic version impact
Patch: internal bug fix and performance improvement with no breaking changes.
Written for commit e70b317. Summary will update on new commits.