fix(cli): strip ASCII control characters in save_env_value - #55767
fix(cli): strip ASCII control characters in save_env_value#55767GauravPatil2515 wants to merge 1 commit into
Conversation
save_env_value() only removed '\n' and '\r' from credentials written to ~/.hermes/.env. Other ASCII control characters (C0 range, 0x00-0x1F, and DEL, 0x7F) could still be persisted in API keys and tokens. On Windows, saving a copied key containing a NUL byte causes os.environ[key] = value to crash with ValueError: embedded null character, leaving a partially written and dirty .env file. On other systems, control bytes such as TAB or DEL survive, resulting in confusing request authorization failures. Fix: strip all ASCII control characters (0x00-0x1F and 0x7F) from values in save_env_value() before performing other validations or writes. This also subsumes the previous '\n' and '\r' removal. Adds test_save_env_value_strips_ascii_control_characters to verify NUL, TAB, CR, LF, DEL, etc. are stripped cleanly from both process env and loaded env. Fixes NousResearch#55335
Duplicate of #55336 — same code site ( |
|
Thanks for the focused regression fix. The premise is confirmed on current The surrounding file moved since the PR base, but the target statement remains materially unchanged, so salvage is a small mechanical reapplication. The member triage comment and #55336 identify an earlier competing implementation of the same fix; that consolidation choice remains for maintainers. Automated hermes-sweeper review. |
Summary
save_env_value()only removed\\nand\\rbefore writing credential values to~/.hermes/.env. Other ASCII control characters (C0 range, 0x00-0x1F, and DEL, 0x7F) could still be persisted.os.environ[key] = valueto crash withValueError: embedded null character, leaving a partially written and dirty.envfile.Fix
Strip all ASCII control characters (0x00-0x1F and 0x7F) from values in
save_env_value()before performing other validations or writes. This also handles the previous\\nand\\rremoval.Tests
Adds
test_save_env_value_strips_ascii_control_charactersto verify NUL, TAB, CR, LF, DEL, etc. are stripped cleanly from both process env and loaded env.Fixes #55335