fix: strip HTTP-unsafe characters from header values#1410
Open
howardpen9 wants to merge 1 commit intoMoonshotAI:mainfrom
Open
fix: strip HTTP-unsafe characters from header values#1410howardpen9 wants to merge 1 commit intoMoonshotAI:mainfrom
howardpen9 wants to merge 1 commit intoMoonshotAI:mainfrom
Conversation
`_ascii_header_value()` only checked for non-ASCII characters but allowed ASCII characters like `#` through. On Linux systems where `platform.version()` returns kernel strings starting with `#` (e.g. `MoonshotAI#101~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC ...`), this produced invalid HTTP header values that caused connection errors. Replace the ASCII-encode check with a regex that removes all characters outside printable ASCII range (0x20-0x7E) as well as `#`, which some servers/proxies reject. Fixes MoonshotAI#1389 Related: MoonshotAI#1368, MoonshotAI#1364, MoonshotAI#1321
|
Fixed on 1.20.0 via #1401 |
This was referenced Mar 13, 2026
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
_ascii_header_value()only filtered non-ASCII characters but allowed HTTP-unsafe ASCII characters like#through unchangedplatform.version()returns kernel strings starting with#(e.g.#101~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC ...), this produced invalid HTTP header values causing connection errors that made kimi-cli completely unusable0x20-0x7E) plus#, which some servers/proxies rejectChanges
src/kimi_cli/auth/oauth.py_ascii_header_value()to use a compiled regex (_UNSAFE_HEADER_RE) that removes control characters, non-ASCII, and#in one passtests/auth/test_ascii_header.py#in kernel version strings (the root cause of Kimi-CLI HTTP Headers 污染问题导致LLM provider error: Connection error. || Kimi-CLI HTTP Headers pollution problem causes LLM provider error: Connection error. #1389)TestCommonHeadersto verify no#appears in header valuesTest plan
tests/auth/test_ascii_header.pyplatform.version()output from affected systemsFixes #1389
Related: #1368, #1364, #1321