Skip to content

fix: keep .env-suffixed names and credentialed source out of the defaults (#51) - #54

Closed
zhongerdeajie wants to merge 1 commit into
dzhng:mainfrom
zhongerdeajie:fix/51
Closed

zhongerdeajie wants to merge 1 commit into
dzhng:mainfrom
zhongerdeajie:fix/51

Conversation

@zhongerdeajie

Copy link
Copy Markdown

Closes #51.

Root cause. A key pasted into an ordinary file left with the source previews, for two
independent reasons:

  1. the name policy (isSensitive) matched only .env and .env.*, so prod.env and
    keys.env were eligible;
  2. the content scan in readSnapshot caught only a -----BEGIN ... PRIVATE KEY----- block,
    so a token pasted into settings.json / config.toml / keys.json went out on every
    request — API keys in ordinary config files are sent to the provider #51 measured 12 of 29 requests carrying one fake value — while never appearing
    in the printed context, so the calling agent had no way to notice.

Fix. Both gaps closed in the place the policy already owns, cheapest first as the issue
proposes:

  • isSensitive treats names ending in .env like .env and .env.* (same
    sensitive_name reason, same includeSensitive override);
  • readSnapshot's content scan also refuses a provider token shape — sk-, sk_live_,
    ghp_, github_pat_, glpat-, xox[abpr]-, AKIA + 16, AIza + 35, each with a
    minimum length past its prefix so prose and identifiers do not trip it — as a new
    api_key reason, behind the same !policy.includeSensitive gate as the private-key
    check, so the existing override admits it unchanged.

Not a guarantee. README's own words stand: the filters narrow what a search sends, they
do not promise secrets are caught. This only closes the specific gap the issue measured.

Tests (packages/core/test/filesystem.test.ts, written first, red/green):

  • prod.env / keys.env → excluded as sensitive_name;
  • one fake token per shape in an ordinary file (settings.json, config.toml, keys.json,
    aws.txt, slack.ts, gitlab.txt, github.txt) → excluded as api_key;
  • near-miss prose (sk- alone, AKIA12345) stays eligible;
  • includeSensitive: true admits all of the above, as before for the private-key case.

The fixture tokens are assembled by string concatenation inside the test so the literal
credential shapes never appear verbatim in committed source (secret scanners match raw
text); the values the assertions exercise are unchanged.

…ults (dzhng#51)

A key pasted into an ordinary file left with the source previews: the name
policy only matched .env and .env.*, and the content scan only caught a
private-key block. Two gaps, closed in the place the policy already owns:

- isSensitive treats names ending in .env like .env and .env.* (prod.env,
  keys.env), still under sensitive_name.
- readSnapshot's content scan now also refuses a provider token shape -
  sk-, sk_live_, ghp_, github_pat_, glpat-, xox[abpr]-, AKIA+16, AIza+35,
  each with a minimum length past its prefix so prose does not trip it -
  as api_key, the same gate and the same includeSensitive override the
  private-key check has.

The filters remain not a guarantee (README's own words); this narrows the
gap the issue measured, where four credential files went out on every
search without ever appearing in the printed context.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@dzhng

dzhng commented Oct 17, 2026

Copy link
Copy Markdown
Owner

Closing this PR because its changes overlap the consolidated secret-filter work in #53 and #59. The review found false positives from unbounded sk- matching and duplicated suffix-policy logic; those fixes will be carried forward in the consolidated successor.

@dzhng dzhng closed this Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API keys in ordinary config files are sent to the provider

2 participants