Skip to content

fix(cli): prevent .env sanitizer from splitting GLM_API_KEY by LM_API_KEY suffix#17288

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-48179c82
Apr 29, 2026
Merged

fix(cli): prevent .env sanitizer from splitting GLM_API_KEY by LM_API_KEY suffix#17288
teknium1 merged 1 commit into
mainfrom
hermes/hermes-48179c82

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Salvage of #17141 by @jackjin1997 onto current main.

Fixes #17138.

_sanitize_env_lines searched every registered env key name as a substring with no word-boundary check. LM_API_KEY= (LM Studio) is a literal suffix of GLM_API_KEY= (Z.AI/GLM), so doctor — or any code path that sanitizes .env — rewrote user files from GLM_API_KEY=... into G\nLM_API_KEY=..., silently killing Z.AI auth. Same shape for GLM_BASE_URL vs LM_BASE_URL.

Fix collects full (start, end) ranges per match and drops ranges fully contained inside a longer overlapping match. Real concatenations (no nesting) still split.

Validation

Before After
GLM_API_KEY=glm-secret G\nLM_API_KEY=glm-secret unchanged
GLM_API_KEY=glmLM_API_KEY=lm-key (genuine concat) splits splits
tests/hermes_cli/test_config.py::TestSanitizeEnvLines 11 passing 13 passing (2 new regressions)

Contributor authorship preserved via rebase-merge.

…_KEY suffix

The known-key splitter in `_sanitize_env_lines` used substring matching
to find concatenated KEY=VALUE pairs. When a registered key was a suffix
of another (LM_API_KEY is a suffix of GLM_API_KEY), the shorter key's
needle would match inside the longer one, causing the sanitizer to
rewrite `GLM_API_KEY=...` as `G\nLM_API_KEY=...` and silently break
Z.AI/GLM auth (and similarly `GLM_BASE_URL` -> `G\nLM_BASE_URL`).

Drop matches whose needle range is fully contained within a longer
overlapping match. Two regression tests cover the suffix-collision case
and confirm a real concatenation that happens to start with the longer
key still splits where it should.

Fixes #17138
@teknium1 teknium1 merged commit 88e07c4 into main Apr 29, 2026
10 of 11 checks passed
@teknium1 teknium1 deleted the hermes/hermes-48179c82 branch April 29, 2026 05:22
@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/cli CLI entry point, hermes_cli/, setup wizard area/config Config system, migrations, profiles labels Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles comp/cli CLI entry point, hermes_cli/, setup wizard P1 High — major feature broken, no workaround type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: On start, Hermes Agent is santizing GLM_API_KEY/GLM_BASE_URL into G\nLM_API_KEY and G\nLM_BASE_URL

3 participants