Commit Graph

115 Commits

Author SHA1 Message Date
emozilla
4959198173 fix(redact): mask the sign-in in a Webapp link that reaches a transcript
`hermes webapp` prints a link that signs a browser in as the user: on gateways before the previous
change the browser credential itself after `#hermes-session=`, and now a one-use launch ticket after
`/webapp/launch#ticket=`, which on macOS spends without a check on who opens it. Web URLs pass
through the redactor by design, so when Hermes ran the command through its terminal tool the link
went into the transcript intact.

The redactor now masks the value after `hermes-session=` and the ticket in a `/webapp/launch`
fragment, wherever they appear, and leaves the rest of the link readable. A floor of 20 characters
keeps placeholders and code that builds such a link (`hermes-session=${token}`) unchanged. The
`security.redact_secrets` switch still turns it off with every other pattern.
2026-10-25 03:22:32 -07:00
Sahil Vishnalya
a480a27e76 fix(agent): redact Context7 API keys by their vendor prefix
A Context7 API key uses a fixed vendor prefix, `ctx7sk-`, and the redactor
had no pattern for it. The generic `sk-` family cannot catch one: the
matcher's lookbehind rejects a prefix preceded by a word char, and here the
`sk-` sits INSIDE `ctx7sk-`. So a Context7 key was masked only when a
secret-looking key name sat next to it - in prose, in command output or in a
JSON array it passed through unmasked.

That leaked a real key: the Context7 MCP setup keeps it in a header, and
`read_file` on that block returned it in cleartext (the `://` in the `url:`
line disables the YAML pass for the whole text, so nothing else caught it
either).

Add `ctx7sk-` to the known vendor prefixes, so the key is masked on every
surface - like the other prefix-matched credentials.
2026-10-24 16:02:14 -07:00
Teknium
870633cba7 fix(browser): raise the redaction walk cap so real DOM trees survive
The 100-level cap truncated ordinary pages: CDP DOM.getDocument spends two
JSON levels per element (node -> children[] -> node), so a page only ~50
elements deep already lost its subtree. Chrome itself refuses to serialize
past ~150 elements (~300 JSON levels), so 320 keeps every DOM Chrome can
return intact while still cutting hostile page-JS values off well below the
interpreter limit (>=340 spare frames on 3.11-3.14).

Tests now drive the walkers without importing the new constants, so they fail
with the real RecursionError on main instead of an ImportError, and pin that
the deepest DOM Chrome returns passes through unchanged.

Co-authored-by: KoNit-K <konit.block@protonmail.com>
2026-10-17 09:11:41 -07:00
Mining
440c9b61df fix(browser): cap redaction walks so nested page data cannot crash
A page-controlled JSON tree could recurse without a depth budget in the browser and CDP output redactors and raise RecursionError. The walk now stops at a fixed depth and replaces the unread remainder instead of returning it raw.
2026-10-17 09:11:41 -07:00
Teknium
3bf97898ac perf(prompt): fixed prefix back under the post-diet size (-2.1k tokens per request)
The stock prompt surface regrew ~3.4k tokens after the August diet, almost
all from features added straight into the never-deferred core. This takes
back the biggest pieces:

- browser_vault: the five eager browser_vault_* tools (list, fill, unlock,
  save_login, enter_code) become one browser_vault tool with an action enum,
  deferred behind tool_search by default. It still rides with the browser
  (an empty vault keeps save_login reachable), so discovery holds; only a
  catalog line is paid per request. Results and errors name the new actions;
  the input-tool password note points at it through tool_call.
- terminal: schema re-dieted (1,136 -> 651 Qwen tokens). Description and
  param docs no longer repeat each other; heartbeat / persist_on_release keep
  their rules in one line each; process(...) references name process_manage.
- tool_search / tool_call: the keyword-query rule lives once, in the queries
  param; description and connector hint trimmed.
- system prompt: the "Async handoff" block is removed. Its rule ships in the
  delegate_task description and in the background dispatch result the model
  reads at the moment it matters, and the polling loop it targeted is guarded
  structurally (#124724).

Stock CLI surface (prompt-surface render, chars/4): 18,612 -> 16,524.
Fresh install, Qwen3 tokenizer: 14,962 -> 13,120 (Sep 7 post-diet: 11,595).

Live A/B harness: evals/prefix_rediet/.
2026-10-12 03:18:48 -07:00
Maciej Lisiewski
2ff58849f4 ci: ruff UP037 fixes 2026-10-09 17:34:38 +02:00
Maciej Lisiewski
d76cce4f11 ci: apply all automatic linter fixes available 2026-10-08 17:22:54 +02:00
Aniruddha Adak
88704223d2 fix(memory): scrub secrets on every memory-provider hand-off (#115104)
MemoryManager forwarded turns, transcripts and tool output to external
memory providers without the egress scrub, so a key echoed into tool
output was archived verbatim in the provider's store.

Every fan-out now goes through redact_for_egress (the chat/cron delivery
scrub; holds with security.redact_secrets off, fails closed): sync_all
(turn strings + messages), prefetch_all / queue_prefetch_all,
on_turn_start, on_session_end, on_pre_compress (both transcripts),
on_memory_write (content + metadata), on_delegation and provider
handle_tool_call args. Nested dicts/lists (tool-call arguments,
multimodal parts) are walked; data: URLs pass; the live transcript is
never mutated. A value masked anywhere in one hand-off is masked
everywhere in it, so a key the model repeats bare in prose is caught.

redact.py: the JSON-field rule now also matches inside JSON-encoded
strings (tool results wrap config dumps in escaped JSON), which is how
the reported opaque AQ.-prefixed key slipped past.

Co-authored-by: Teknium <teknium1@gmail.com>
2026-10-07 02:06:15 -07:00
kshitijk4poor
26f0ed2e42 refactor(debug): reuse agent.redact lists in support redaction
The support scrub re-listed agent.redact's sensitive query params and
secret header names; two copies of one pattern list drift. Derive the
support-only compact names from _SENSITIVE_QUERY_PARAMS (plus the five
support-only extras) and expose the header names as a tuple that both
the agent regex and the support module build from. agent.redact is a
hard dependency, so import it at module level and drop the try/except
around is_secret_field_name.
2026-10-03 21:15:17 +05:30
kshitijk4poor
c900b1df58 refactor(agent): simplify strict URL userinfo substitution
The replacement no longer depends on any captured group, so drop the
groups from _STRICT_URL_USERINFO_RE and substitute a constant string.
Update the redact_sensitive_text docstring to say the entire userinfo
is masked, and fold the standalone opaque-username test into the
existing parametrize so it also checks redaction stays off by default.
2026-10-02 00:52:27 +05:30
Yuan Li
00227371f2 fix(agent): redact strict URL userinfo credentials
(cherry picked from commit 526f376c3ccafcbe44f1398bf5f65926216f95ed)
2026-10-02 00:52:27 +05:30
unsupportedpastels
536802c00e fix(debug): mask every secret fallback field per agent.redact policy, not only api_key
Reuses the repr-field secret-name policy (is_secret_field_name) so token, password, secret and credential-suffixed fields are masked by field in hermes dump, debug share and /debug. The regression test asserts on what actually reaches the paste service first.
2026-09-29 05:59:25 -04:00
John Paul Soliva
cf94e3eea3 fix(redact): GCS and Azure SAS signatures count as URL credentials
The strict URL-credential pass that hermes dump and debug uploads use
redacted X-Amz-Signature but not X-Goog-Signature (GCS V4 signed URLs)
or sig (Azure SAS), so a fallback base_url signed that way still reached
the dump and the upload. The documented promise is signed-URL signatures
in general.
2026-09-29 05:59:25 -04:00
JoaoMarcos44
205d5d78f1 fix(debug): strict URL-credential redaction for the system dump
A fallback_providers base_url can carry its credential in the URL (userinfo, ?key=, #access_token=, X-Amz-Signature=). The force pass leaves those to the log policy, which spares OAuth/magic-link URLs, so hermes dump printed them and debug share / gateway /debug uploaded them. The dump's fallback rendering and the upload copy of the dump now opt into redact_url_credentials.

The strict canonicalizer also turned x-amz-signature into x_amz_signature before the policy lookup, so strict mode never masked it; hyphenated policy names now match as stored.

Ported from #126168.
2026-09-29 05:59:25 -04:00
Israel Lot
70f79c8cde fix(agent): anchor the Telegram token regex to a digit-run start (ReDoS)
`_TELEGRAM_RE` (`(bot)?(\d{8,}):([-A-Za-z0-9_]{30,})`) runs over every
redacted surface that contains a colon. On a long digit run with no
`:<token>` after it, the unanchored greedy `\d{8,}` is retried from every
digit of the run, so the scan is quadratic in the run length and holds
the GIL for its whole duration.

Real trigger: the foreground terminal tool spills a 2 MB `gh pr diff`
to disk and redacts the full spill (`_redact_spill_file`); the diff
carried a Unity `_typelessdata: 000...` line with ~1.5M consecutive
digits. That redaction pinned one core at 100% for hours after the
subprocess had already exited, so the command timeout could not fire,
and every session in the same `hermes acp` worker stalled. Any tool
output the agent reads (hex/decimal dumps, minified assets, logs) can
reach the same path.

A `(?<!\d)` lookbehind pins the bot id to the start of its digit run,
which is the only place a real token id can begin, so a non-matching
run is scanned once. Matching is unchanged for real tokens.

Measured on the unpatched pattern, `_typelessdata: ` + N zeros:
10k 0.41s, 20k 1.55s, 40k 6.2s (x4 per doubling); patched: 0.004s,
0.003s, 0.006s, 80k 0.014s.

(cherry picked from commit c48cb6bf93a15cd28fd253c5293413d72081fdc4)
2026-09-23 21:28:38 +05:30
John Paul Soliva
d9199d8e8d fix(logging): a routed profile's own log files follow its own redaction policy
Under multiplex (and the Desktop/dashboard backend) every record is
formatted on the log QueueListener thread, after the profile scope that
produced it is gone. _ProfileRoutingFileHandler still writes a routed
profile's records to <profile>/logs/*.log, but RedactingFormatter ran
there with no home override, so _redact_enabled() returned the LAUNCH
profile's import-time snapshot and the vault scrub keyed on the launch
home. A launch profile with security.redact_secrets: false (or
HERMES_REDACT_SECRETS=false) therefore wrote every routed profile's
credentials raw into that profile's agent.log/errors.log/gateway.log,
and a routed profile's own opt-out was ignored.

The routing handler now binds the record's stamped home while a record
for another profile is formatted. Launch-profile records are untouched.
With no live secret scope (that thread has none), _redact_enabled reads
the profile's own .env for HERMES_REDACT_SECRETS, as its scope would;
without it the first call there cached a config-only answer for the
process.
2026-09-23 08:09:47 -07:00
teknium1
aebc71d78c fix(redact): dotted sk- body cannot span "..", so display masks survive a second pass; Zhipu matcher is 32-hex.16+alnum
CI regression on the previous head: tool_executor redacts browser_type
args to `sk-pro...EFGH`, then build_tool_preview redacts them again; the
widened dotted `sk-` matcher consumed the `...` and collapsed the mask to
`***` (tests/agent/test_run_agent.py::test_sequential_browser_type_callbacks_redact_api_key).
Each body unit is now one char optionally preceded by a single dot, so a
run of dots ends the match and a masked token is a no-op on re-redaction.
Invariant test added to the dotted-key test.

Review follow-up (minor): the prefix-less Zhipu matcher over-matched
content-hash filenames (`<40-hex>.bundle`, `<32-hex>.sqlite3`,
`<36-alnum>.example`). It now requires the provider shape — a 32-char
lowercase-hex id and a 16+ alphanumeric secret — and those filenames are
negative controls.
2026-09-18 09:58:12 -07:00
teknium1
c2aa2ff25f fix(redact): dotted sk- pattern without nested repeats; tests cover terminal + file_read surfaces
Follow-up to the salvaged commit:

- The dotted `sk-` pattern is rewritten as
  `sk-(?=[A-Za-z0-9_.-]{10,}(?![A-Za-z0-9_.-]))[A-Za-z0-9_.-]*[A-Za-z0-9_-]`:
  same matches (whole dotted body, 10-char floor, trailing sentence dot never
  consumed) but no nested unbounded repeat, so the built-in passes the same
  structural gate `register_redaction_patterns` applies to plugin patterns
  (`_has_nested_unbounded_repeat` flagged the salvaged form).
- Tests trimmed to two invariants: the reporter's YAML through
  `redact_terminal_output` (the terminal tool's code_file path) and through
  `file_read=True` (non-reusable sentinel), plus the multi-dot DashScope shape
  from #106508; and a negative control keeping content-hash filenames, bare git
  shas, short `sk-` fragments and a 31-char id byte-identical on both surfaces.

Co-authored-by: itskaism <130876697+itskaism@users.noreply.github.com>
2026-09-18 09:58:12 -07:00
KoNit-K
7b57cda6d9 fix(agent): redact dotted and Zhipu API keys
(cherry picked from commit 1ec3c141be6d26a666b55ed815a970f448150ba5)
2026-09-18 09:58:12 -07:00
teknium1
60f436b5f6 fix: redact '/'- and '~'-led secrets whose segments cannot be a path
Review finding (agent/redact.py::_should_redact_assignment): a '/'-prefixed
secret with a second '/' (`AWS_SECRET_ACCESS_KEY=/wJalrXUtnFEMIK7MDENG/bPx…`)
still parsed as a multi-segment path and leaked under a strong key; the same
held for a '~'-led value. Apply the opaque bar per segment (16+ chars, no
'.', mixed case and digits) to every '/' or '~' value instead of only to
single-segment ones, so `/home/u/.docker`, `~/.ssh/id_rsa` and
`S.gpg-agent.ssh`-style paths stay readable while base64 secrets mask.
2026-09-15 18:59:55 -07:00
teknium1
34067a7b6d fix: keep $(cmd) substitutions readable under strong-key assignments
Review finding (agent/redact.py::_PATH_OR_VAR_VALUE_RE): anchoring the
path/var exemption regressed `export SSH_AUTH_SOCK=$(gpgconf --list-dirs
agent-ssh-socket)` vs main — the `$(gpgconf` token no longer parsed as a
reference and was masked. Accept a leading `$(` as a reference atom in the
grammar and pin the gpg-agent line in
test_real_path_and_var_references_stay_readable.
2026-09-15 18:59:55 -07:00
teknium1
93a269c026 fix(redact): keep $VAR interpolations inside rc path values readable
The anchored path/variable grammar from the salvaged fix only allowed one
leading $VAR; a strong-key rc line such as SSH_AUTH_SOCK=/run/user/$UID/ssh or
SSH_AUTH_SOCK=$XDG_RUNTIME_DIR/agent.$USER.sock no longer parsed as a reference
and was masked, undoing the readability contract from 979576d938 for exactly
the lines it was written for.

Allow $VAR / ${VAR...} anywhere in the value (and ':' list separators). Crypt
digests still fall through to the credential checks: their '$' fields start
with a digit or carry '=' / ',', which the grammar rejects.
2026-09-15 18:59:55 -07:00
beardthelion
93a0ec705a fix(redact): anchor the path/var exemption so leading-/ and $ secrets still mask
_PATH_OR_VAR_VALUE_RE was an unanchored character class, so re.match made it a
first-character test: any assignment value beginning with '$', '/', or '~'
returned early from _should_redact_assignment, ahead of the strong-key and
opaque-credential checks. AWS secret access keys (~1 in 64 begin with '/') and
argon2/bcrypt digests (always '$'-prefixed) leaked verbatim through
redact_sensitive_text.

Anchor the pattern on both ends so the exemption only fires on a complete
$VAR/${VAR}/~/path//abs/path reference, and require a single-segment absolute
path — indistinguishable by shape from a high-entropy secret — to clear the
opaque-credential bar first. $VAR and ~/ references stay exempt
unconditionally, preserving the rc-readability contract that motivated the
exemption (SSH_AUTH_SOCK=$HOME/.ssh/agent.sock,
DOCKER_AUTH_CONFIG=/home/u/.docker).
2026-09-15 18:59:55 -07:00
teknium1
979576d938 fix: linear gutter anchors, cat -n/grep-context gutters, keep rc path references readable
The optional line-number gutter was written as `^(?:[ \t]*GUTTER)?[ \t]*`,
stacking two adjacent whitespace runs so _CFG_ANCHORED_RE / _YAML_ASSIGN_RE
went quadratic on any indented line with a secret keyword and no `=` (2s per
5k spaces, 50s at 20k) — and these run on every terminal output and file read.
The gutter now carries the single optional group and callers own the one
leading whitespace run. It also accepts `cat -n` / `nl` (number + TAB) and
`grep -A/-B/-C` (`5-`) gutters, which the comment claimed but leaked.

The strong-key branch masked SSH_AUTH_SOCK=$HOME/..., DOCKER_AUTH_CONFIG=/...
on shell rc reads, leaving the agent unable to edit them; a value starting with
$, / or ~ is a variable or path reference and is now kept unless the key is
password-class. _is_secret_file_arg only extends config.yaml to the
backups/config .good./.corrupt. copies, not config.yaml.pdf/.bak.

Review finding: quadratic gutter regex; cat -n/nl TAB and grep context gutters leaked; over-redaction of rc path references.
2026-09-15 06:26:29 -07:00
teknium1
f5907fd052 fix(redact): config.yaml backup copies under HERMES_HOME are secret-bearing too
search_files over $HERMES_HOME returned the token from backups/config/config.yaml.good.<stamp>
in cleartext while config.yaml itself was masked; the predicate only matched the exact basename.
Same predicate serves the terminal side, so `cat backups/config/config.yaml.good.*` is covered too.
2026-09-15 06:26:29 -07:00
shehjaddev
d205cef418 fix(redact): mask assignments in secret-bearing file reads
read_file/search_files passed file_read=True, which folded into code_file=True and skipped
the ENV/JSON/YAML assignment passes, so an opaque prefix-less credential under a
credential-shaped key reached the model in cleartext from a secret-bearing file — the
file-read half of the #110228 gate (#110567).

Two defects on that path, both fixed here:

- The rendered line-number gutter ("5|      ADS_API_TOKEN: ..." from read_file,
  "6:      ADS_API_TOKEN: ..." from grep -n / cat -n) defeated the line-anchored patterns,
  so the real rendered read leaked exactly what the raw text masked. A gutter-free fixture
  cannot see this, which is why the tool-level tests carry the real render shape.
- _is_secret_file_arg() could not see the RESOLVED Hermes home: the default home's basename
  is an installation detail (".hermes" on POSIX, "hermes" under AppData/Local on Windows) and
  a resolved path never spells $HERMES_HOME, so the managed Windows home's config.yaml was
  classified as ordinary YAML on both the file-read and the terminal surface.

Changes:

- redact_sensitive_text(): secret_file= re-enables the assignment passes for content the
  caller classified with _is_secret_file_arg, keeping code_file behaviour everywhere else.
  It is authoritative over code_file, so a caller cannot be fail-open on the security flag
  by setting both.
- _redact_assignments(): mask_nonreusable selects the non-reusable sentinel for file reads,
  so the #35519 write-back hazard stays closed.
- _should_redact_assignment(): no longer re-masks an already-masked value, which was erasing
  the vendor label the sentinel deliberately keeps.
- _is_secret_file_arg(): consult the resolved Hermes home for the config.yaml arm.
- _CFG_ANCHORED_RE / _YAML_ASSIGN_RE: tolerate a rendered line-number gutter.
- file_tools.py: classify the resolved path at all three file-read call sites.

Closes #110567
2026-09-15 06:26:29 -07:00
teknium1
5280dec0ee fix(redact): repr pass leaves already-masked values alone
The Python-repr pass ran after the MCP probe header scrub and collapsed
'Authorization': 'Digest ***' to '***', erasing the scheme word that scrub
deliberately keeps (tests/hermes_cli/test_mcp_probe_redaction.py went red
on rebase). Skip values that already carry a mask marker.
2026-09-13 21:30:40 -07:00
Teknium
92d4c0233e fix(redact): widen repr-field key class to mixed-case credential suffixes
Port from OpenHands/software-agent-sdk#4508: their dict-entry secret
redaction was uppercase-only and leaked mixed-case keys (UserPassword,
sessionToken). Apply the same case-insensitive treatment to the Python
mapping-repr pass: a casefolded credential suffix (apikey/token/secret/
password/passwd/credential) now qualifies a key, while metadata names
(TOKEN_COUNT, password_policy, tokenizer) stay untouched.
2026-09-13 21:30:40 -07:00
Demerzel (backend-eng)
47668280e7 fix(redact): mask secrets in Python mapping reprs 2026-09-13 21:30:40 -07:00
teknium1
f80ea9987b fix: grep/awk/sed gate on file operands only; strip $HOME prefixes
Adding grep/awk/sed to _FILE_READ_COMMANDS made the PATTERN operand
participate in the secret-file predicate, so `grep .bashrc app.py` or
`grep -n .env src/settings.py` — reads of SOURCE files — ran the
ENV/YAML assignment pass and masked opaque values that main leaves
alone. Skip the first non-flag positional for the pattern-first
readers, as #109369 originally did, so only real file operands gate.

`cat $HOME/.hermes/config.yaml` was ungated because the `$` bail-out
fired before the `.hermes` segment was inspected; strip `$HOME/` and
`${HOME}/` like the HERMES_HOME prefixes.

Review follow-up on #110228.
2026-09-13 14:47:12 -07:00
teknium1
6e7ea9cbdc refactor(redact): one secret-file predicate for .env, shell rc and Hermes config.yaml
Fold KoNit-K's `_command_reads_secret_bearing_file` and the pre-existing
`_command_reads_env_file` into a single `_command_reads_secret_file` so the
`code_file` gate in `redact_terminal_output` has one owner: `.env`-style
basenames and shell rc/profile files anywhere, `config.yaml` only under a
`.hermes` directory or `$HERMES_HOME` (arbitrary project YAML stays on the
code_file path). `grep`/`awk`/`sed` join the reader set instead of a second
table with a positional-argument special case: on a file read, any non-flag
operand that names a secret-bearing file is enough — the pattern/program
operand never matches a basename, so the extra rule bought nothing.

Tests: the negative parametrization now uses an opaque credential-shaped value
(the placeholder it used before would never have been masked on either path,
so the "stays unredacted" half proved nothing) and asserts the same value IS
masked under `cat .env` in the same test.
2026-09-13 14:47:12 -07:00
KoNit-K
8ab9e79d0a fix(redact): recognize quoted HERMES_HOME config reads
Keep the narrow basename allowlist, but do not treat $HERMES_HOME as an
unresolved path, and split pipelines only on unquoted |;&.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-13 14:47:12 -07:00
KoNit-K
0997a23e57 fix(security): redact secrets from config file reads 2026-09-13 14:47:12 -07:00
teknium1
f680431f2e fix(redact): bearer residue sweep needs a 20-char token floor
redact_for_egress's bearer sweep matched any run of token characters after
the word "Bearer", so ordinary prose ("I'm the bearer of bad news") came
back as "Bearer [redacted] bad news" on every chat and A2A reply. The
gateway and A2A sweeps this PR replaced always required 20+ chars; only
monitoring was floor-less. Restore the floor on the opaque branch and keep
the bracket branch that folds an already-masked residue to one marker.
2026-09-13 05:07:50 -07:00
teknium1
226df89f74 refactor(redact): one secret-pattern source; a2a, gateway chat and monitoring egress scrub through redact_for_egress
plugins/platforms/a2a/security.py::redact_outbound shipped text to a REMOTE peer
through 8 private regexes (sk-, sk-ant-, ghp_ only, xox[bap] only, AKIA, JWT,
Bearer, email) and never called redact_sensitive_text, so every prefix added to
agent/redact.py (hf_, glpat-, xapp-, npm_, Telegram bot tokens, private keys,
DB URLs, env assignments, auth headers, plugin-registered patterns) was absent
on the A2A path. gateway/run.py::_GATEWAY_SECRET_PATTERNS and
agent/monitoring/redaction.py::_TOKEN_RE/_BEARER_RE were two more parallel
"fallback" lists to maintain.

Now agent/redact.py::redact_for_egress is the one egress scrub:
redact_sensitive_text(force=True) + a bearer sweep for prefix-less opaque
tokens, fail-closed ("[redaction-unavailable]"). Gateway user-facing text,
monitoring export and A2A outbound call it; A2A keeps only its e-mail pass.

Behavior changes: a2a egress now masks the full canonical set; the gateway
chat path returns the fail-closed sentinel instead of a raw string when the
redactor raises; honcho plugin registers hch-at-/hch-rt- with
register_redaction_patterns (masked on every surface; mask shape is the
shared head/tail form instead of "hch-at-[redacted]"); proxy_cli token
display uses mask_secret (4 visible prefix chars instead of 12).

Invariant test: redact_outbound masks a synthesized token for every
registered prefix pattern (fails when reverted to the private list).
2026-09-13 05:07:50 -07:00
teknium1
848075c501 fix(redact): AgentMail prefix rule matches any opaque key body, not only hex
Review finding: the salvaged rule assumed a lowercase-hex grammar that
AgentMail's docs do not establish (only the `am_` / `am_org_` prefix is
documented), so a non-hex key would have gone unmasked. Discriminate on
what actually separates keys from identifiers: an alphanumeric body with
no `_`/`-` and a 20-char floor. `am_example_identifier_123` still passes.
2026-09-12 08:37:14 -07:00
nightq
cc885b8b19 fix: tighten AgentMail API key regex to avoid false positives
The pattern am_[A-Za-z0-9_-]{10,} was too broad and matched ordinary
identifiers like 'am_example_identifier' that happen to start with 'am_'.

Changed to am_[a-f0-9]{32,} which:
- Requires lowercase hex characters only (real AgentMail keys are hex)
- Requires 32+ characters after the prefix (reducing false positives)

Fixes NousResearch/hermes-agent#10983
2026-09-12 08:37:14 -07:00
Teknium
9c9e7ab6e5 fix(multiplex): a served profile's turn sees its own cwd, approvals, redaction and tool policy
Under gateway.multiplex_profiles a secondary profile's turn ran with the LAUNCH
profile's working directory, command allowlist, redact_secrets switch, credential
file mounts, browser engine/headed flags, LSP service, auxiliary-provider health
marks and MCP stderr log, and several TERMINAL_ENV consumers read the process env
instead of the routed profile's terminal scope. A standalone `hermes -p X gateway
run` never behaved that way.

- tools/terminal_scope.py: resolve the terminal.cwd placeholder inside the
  profile scope with the same rule gateway/run.py applies at import (local ->
  $HOME, sandbox default otherwise) so the system prompt, context files and the
  terminal of a routed turn start where the profile's standalone gateway would.
- tools/image_source.py, credential_files.py, image_generation_tool.py,
  skills_tool.py, delegate_tool_progress.py, agent/tool_executor.py: read
  TERMINAL_ENV / TERMINAL_CWD through the terminal scope.
- tools/approval.py (+ approval_floors.py): one permanent allowlist per routed
  profile home; the unscoped module set stays for single-profile processes.
- agent/redact.py: `_redact_enabled()` resolves security.redact_secrets for the
  routed profile (scope .env, then config); launch snapshot kept when unscoped.
- tools/credential_files.py, agent/auxiliary_health.py, agent/lsp/__init__.py,
  tools/browser_tool_cloud.py, tools/mcp_tool_config.py,
  tools/tool_result_storage.py: key process caches by profile home (or bypass
  the slot under an override).

Tests: tests/tools/test_multiplex_turn_parity.py (4, red on base).
Docs: multi-profile-gateways.md isolation table.
2026-09-11 19:39:12 -07:00
Teknium
27ca97e469 fix(vault): cross-process store lock + fsync; profile-scoped, bounded redaction registry
Two review findings on #96988/#106480 that were still open:

- VaultStore serialized read-modify-write with a threading.Lock only. The Desktop gateway,
  a CLI `hermes vault add` and a TUI slash worker are separate processes writing the same
  vault.json.enc, so two adds could drop each other's items, and the temp file was renamed
  into place without fsync (a crash between rename and the next sync loses the vault).
  Writes now take an flock/msvcrt lock on <vault>/.vault.lock and fsync file + directory.
- The vault redaction registry was one process-global, unbounded set. Under gateway
  multiplexing profile A's passwords scrubbed profile B's browser output (and confirmed to
  B that those bytes exist). It is now keyed by profile home, capped at the 64 most recent
  values per profile, and clearable (clear_vault_redaction_values).

Also canonicalizes payment/address payloads (PAYMENT_FIELDS / ADDRESS_FIELDS, required
fields enforced, stray keys dropped) so the checkout fill in the next commit never has to
guess a user's ad-hoc field names; the Desktop dialog already wrote these names.
2026-09-10 10:35:07 -07:00
Teknium
5aa9e7f033 fix(vault): independent-review findings — vendor contracts, profile scope, transport, target binding
Bitwarden unlock now uses the CLI's documented non-interactive channel:
`bw unlock --raw --nointeraction --passwordenv VAR`, VAR set on the child
environment only (bw 2026.x rejects a piped password with "Master password
is required"). Verified against the real published binary.

Manager session tokens are keyed by (profile home, backend): a Desktop
gateway hosting several profiles can no longer reuse or lock another
profile's session. Status probes (`vault.sources`, is_unlocked) no longer
refresh the idle TTL; only real manager calls do. Gateway session teardown
locks the profile's managers (a per-session unlock ends with the session).

1Password service-account token comes from the profile-scoped secret store
(get_secret), not ambient os.environ.

`vault.source.set` no longer references a module constant (bind_module
rebinding dropped it → NameError on every Settings toggle).

Fill target binding: inspection stamps each input with a per-inspection
slot attribute; the fill resolves by stamp and requires type=password, then
strips every stamp. A DOM reflow between inspect and fill can no longer
redirect the password into a text field (reproduced in real Chrome before,
0 filled after).

Redaction boundary: no 4-char floor, CR/LF-normalized form registered
(what a text input actually stores), JSON object KEYS scrubbed in both
browser redactors; longest value first. Docs now state the real trust
model: accidental-disclosure protection, not an execution sandbox.

Desktop: the mid-turn card sends the master password through the owning
session's socket (requestForOwnedSession), never the ambient foreground
gateway; `vault.unlock.expire` clears a stale card; Settings keeps the
master password out of react-query mutation variables (ref consumed by the
mutationFn). One renderer invariant test for the routing.
2026-09-10 10:35:07 -07:00
Teknium
cde0ad0edd feat: agent signs into sites from an encrypted local vault (CLI, browser fill, Desktop Settings)
Consolidated re-apply of #96988 onto current main. Ported from
Merit-Systems/OpenInstinct (MIT) opaque-handle autofill design: the model
sees vault handles + login metadata, the password is resolved and filled
server-side over the supervised CDP socket, and filled values are scrubbed
from every browser tool result by an unconditional redaction registry.

Rebase adaptations to the Sep-2026 facade/sibling layout:
- toolsets: one _HERMES_CORE_TOOLS entry (the browser toolset derives from it)
- hermes_cli/main.py: vault parser registered via the subcommand owner table
- file_safety: vault/ joins the _READ_DENIED_DIRS credential-dir table
- redact: registry scrub runs before the redact_secrets early-return
- browser_vault_tool: _run_browser_command now lives in browser_tool_session
2026-09-10 10:35:07 -07:00
Teknium
e83816a4d1 review-fix(comments): restore lost #NNNN rationale comments across non-test source (mechanical sweep, condensed, code unchanged)
For each issue anchor present in BASE 63279301bc non-test .py and absent on HEAD, the BASE comment/docstring block was re-attached at the HEAD location of the code it explained (matched by the distinctive code line / enclosing def). Sentences already covered by an existing HEAD comment were deduped; the issue number always survives. Insert-only: no code lines changed.
2026-09-03 09:44:26 -07:00
Teknium
8aba2fe9f2 refactor(agent/secrets): collapse defensive branches (alias target, ordered sources, zip containment, find_op, query-string sub) 2026-09-02 19:25:11 -07:00
Teknium
9d97a255f1 refactor(agent/secrets): hand-compact docstrings and rationale comments (WHY kept) 2026-09-02 19:23:12 -07:00
Teknium
5f5d094f6e refactor(agent/redact.py): inline single-caller helpers, compact regex rationale comments by hand 2026-09-02 19:12:32 -07:00
Teknium
5ee79d5dc9 refactor(agent/redact.py): one _assignment_sub factory for ENV/JSON/YAML passes, single-scan _pattern_structure, shared _command_segments 2026-09-02 19:02:38 -07:00
Teknium
92aaf61462 refactor(agent/redact.py): collapse single-use regex wrappers, fold prose comments, next()-based lookups 2026-09-02 18:31:51 -07:00
Teknium
be5c6a2fd8 refactor(agent/prompt): remove dead code, unify duplicated helpers, compact docstrings across prompt/skill/redaction modules
Dead (zero refs): coding_system_blocks, get_friendly_tool_labels, get_scan_ordered_skills_dirs,
_project_quarantine_cache_clear, clear_stable_prefixes, _redact_http_request_target_query_params,
_has_http_method_substring, PromptCachePlan.marker_count, display _diff_* colour thunks (-> _diff_ansi),
pass-through RedactingFormatter.__init__.
Unified: _slugify -> slugify_skill_name; reload diff -> diff_command_snapshots; _is_summary_item ->
is_compaction_summary_message alias; sanitizer walkers -> _sanitize_messages/_sanitize_structure;
assignment redaction passes -> _redact_assignments/_should_redact_assignment; quiet-mode tool lines -> _CUTE_LINES table.
2026-09-02 13:53:57 -07:00
fangliquanflq
a8ddb231aa fix(redaction): gate ambiguous assignment values 2026-09-01 12:07:16 -07:00
kshitijk4poor
fe0cfdf99c fix(redact): keep dotted config-key scans linear past the keyword pre-gate
The _CFG_SECRET_WORD_RE pre-gate only skips secret-FREE text. A compaction
payload containing one real secret assignment plus a long opaque dotted run
still reaches _CFG_DOTTED_RE's backtrackable '*' prefix, which re.sub retries
from every byte of the run — quadratic while holding the GIL (same class as
the _ENV_ASSIGN_LOWER_RE fix in this branch, #99255).

Anchor each attempt to the start of a key run with a negative lookbehind.
Match set is unchanged: any match starting mid-run implies a leftmost match
at the run start, verified 20/20 identical over a dotted-config corpus.
30k-char adversarial run: 102s -> 0.015s.
2026-09-01 00:25:45 +05:30