fix(config): strip control chars from saved credentials - #58074
Closed
tianma-if wants to merge 1 commit into
Closed
Conversation
6 tasks
Collaborator
Duplicate of #55336 (earliest open, canonical) — both strip ASCII control characters in |
Contributor
Author
|
Closing as duplicate of #55336 per triage; the earlier PR covers the same save_env_value control-character fix. Thanks. |
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.
What does this PR do?
Fixes save-time credential normalization so
save_env_value()strips ASCII control characters before writing~/.hermes/.envand before mutatingos.environ. This prevents copied API keys/tokens containing hidden bytes such as NUL, TAB, or DEL from leaving a malformed.envbehind or crashing withValueError: embedded null character.Fixes #55335
Type of Change
Changes
_check_ascii_control_credential()beside the existing non-ASCII credential sanitizer.save_env_value()through the printable-ASCII sanitizer before.envserialization andos.environassignment..envbytes and the process environment..envload-time non-ASCII sanitizer semantics unchanged; this PR targets the save path described in the issue.How to Test
.venv/bin/python -m pytest tests/hermes_cli/test_non_ascii_credential.py -q.venv/bin/python -m pytest tests/hermes_cli/test_env_load_cache.py tests/hermes_cli/test_env_loader.py tests/hermes_cli/test_config.py -q -k "env or credential or API_KEY or denylisted".venv/bin/python -m ruff check hermes_cli/config.py tests/hermes_cli/test_non_ascii_credential.pygit diff --checkPlatform: macOS, Python 3.13, local
.venv.