Skip to content

feat(llm): add secret shield for outbound credential redaction - #50905

Closed
GiacomoSaccaggi wants to merge 4 commits into
anomalyco:devfrom
GiacomoSaccaggi:secret-shield
Closed

GiacomoSaccaggi wants to merge 4 commits into
anomalyco:devfrom
GiacomoSaccaggi:secret-shield

Conversation

@GiacomoSaccaggi

@GiacomoSaccaggi GiacomoSaccaggi commented Sep 23, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #50904

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds opt-in credential scanning for outbound LLM requests. When enabled via secret_shield in config (or OPENCODE_SECRET_SHIELD env var), it scans messages, system parts, and tool descriptions for credential patterns before they reach llm.stream().

Four modes: off (default, zero overhead), warn (log count, send original), mask (replace with [REDACTED]), block (fail the step).

Detection covers 16 API key prefix families (OpenAI, Anthropic, GitHub, AWS, Stripe, etc.), JSON sensitive fields (password, api_key, token), HTTP auth headers, connection string URIs, and JWTs.

applySecretShield() returns a ShieldResult discriminated union (ok | blocked) instead of throwing, so the runner surfaces blocks as Step.Failed in the UI via the existing publisher. Detections are logged through Effect.logWarning.

Files changed:

  • packages/llm/src/secret-shield.ts — redaction engine + applySecretShield()
  • packages/llm/src/index.ts — exports
  • packages/core/src/config.ts — secret_shield config field
  • packages/core/src/session/runner/llm.ts — shield wired after publisher setup
  • packages/llm/test/secret-shield.test.ts — 85 tests

How did you verify your code works?

cd packages/llm && bun test test/secret-shield.test.ts  # 85 pass
cd packages/llm && bun typecheck                         # clean
cd packages/core && bun typecheck                        # clean

Full monorepo typecheck also passes (30/30 packages via pre-push hook).

Screenshots / recordings

N/A — no UI changes. This is a transport-layer feature.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

GiacomoSaccaggi and others added 2 commits September 23, 2026 14:55
Scan LLM requests for credential patterns before sending to providers.
Four opt-in modes: off (default), warn, mask, block.

Detects 16 API key prefix families, JSON sensitive fields, HTTP auth
headers, connection string URIs, and JWT tokens. Returns ShieldResult
discriminated union so callers handle errors in their own channel.
85 tests: prefix patterns, JSON fields, headers, URIs, JWTs,
idempotency, overlap, false positives, edge cases, tool description
scanning, and full request-level ShieldResult handling.

Runner: shield applied after publisher so block surfaces as
Step.Failed in the UI. Detections logged via Effect.logWarning.
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Sep 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Sep 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@thdxr

thdxr commented Oct 10, 2026

Copy link
Copy Markdown
Member

This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2.

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

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.

[FEATURE]: Opt-in credential redaction before outbound LLM requests

3 participants