Skip to content

fix: strip HTTP-unsafe characters from header values#1410

Open
howardpen9 wants to merge 1 commit intoMoonshotAI:mainfrom
howardpen9:fix/sanitize-http-header-value
Open

fix: strip HTTP-unsafe characters from header values#1410
howardpen9 wants to merge 1 commit intoMoonshotAI:mainfrom
howardpen9:fix/sanitize-http-header-value

Conversation

@howardpen9
Copy link
Contributor

@howardpen9 howardpen9 commented Mar 12, 2026

Summary

  • _ascii_header_value() only filtered non-ASCII characters but allowed HTTP-unsafe ASCII characters like # through unchanged
  • On Linux systems where platform.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 unusable
  • Replace the ASCII-encode check with a single regex that strips all characters outside printable ASCII range (0x20-0x7E) plus #, which some servers/proxies reject

Changes

src/kimi_cli/auth/oauth.py

  • Simplified _ascii_header_value() to use a compiled regex (_UNSAFE_HEADER_RE) that removes control characters, non-ASCII, and # in one pass
  • The new implementation is both shorter and more robust than the previous try/except approach

tests/auth/test_ascii_header.py

Test plan

  • All 9 tests pass in tests/auth/test_ascii_header.py
  • Verified the fix handles the exact platform.version() output from affected systems

Fixes #1389
Related: #1368, #1364, #1321


Open with Devin

`_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
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@renatocron
Copy link

Fixed on 1.20.0 via #1401

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants