#22873: fix(tools): enforce global inline-secret blocking for tool inputs
docs
gateway
scripts
agents
size: L
## Summary
- Problem: tools could receive inline credential-like params (`apiKey`, `password`, `accessToken`, etc.) from model/user calls.
- Why it matters: inline secrets increase leakage risk and bypass config/env/auth-profile boundaries.
- What changed:
- Added global detector: `src/agents/tool-inline-secret-policy.ts`.
- Enforced in runtime hook gate: `src/agents/pi-tools.before-tool-call.ts`.
- Enforced in HTTP gateway path: `src/gateway/tools-invoke-http.ts`.
- Added tests for detector, hook blocking, and gateway rejection.
- Scope boundary: no provider/plugin credential storage changes; this is execution-time input enforcement.
## Change Type
- [x] Bug fix
- [ ] Feature
- [ ] Refactor
- [ ] Docs
- [x] Security hardening
- [ ] Chore/infra
## Scope
- [x] Skills / tool execution
- [x] API / contracts
- [ ] Gateway / orchestration
- [ ] Auth / tokens
- [ ] Memory / storage
- [ ] Integrations
- [ ] UI / DX
- [ ] CI/CD / infra
## Security Impact
- New permissions/capabilities? (No)
- Secrets/tokens handling changed? (Yes)
- New/changed network calls? (No)
- Command/tool execution surface changed? (Yes)
- Data access scope changed? (No)
If any Yes, explain risk + mitigation:
- Runtime now blocks inline secret-like args and returns explicit errors to force safer credential sources.
## Repro + Verification
Steps:
1. Call a tool with inline secret-like args (e.g. `{ "apiKey": "..." }`).
2. Observe tool call is blocked before execution.
Expected:
- 400/tool_error in HTTP path and blocked execution in runtime path.
Actual:
- Inline secret-like params are rejected with a clear remediation message.
Evidence:
- `pnpm vitest run src/agents/tool-inline-secret-policy.test.ts src/gateway/tools-invoke-http.test.ts`
- `pnpm vitest run --config vitest.e2e.config.ts src/agents/pi-tools.before-tool-call.e2e.test.ts`
- `pnpm check`
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR adds global inline-secret blocking for tool inputs to prevent credential leakage risks. The implementation introduces a new detector (`tool-inline-secret-policy.ts`) that scans tool parameters for sensitive keys like `apiKey`, `password`, `token`, etc., and enforces blocking at two critical execution points:
- **Runtime hook path**: enforced in `pi-tools.before-tool-call.ts` via `wrapToolWithBeforeToolCallHook`
- **HTTP gateway path**: enforced in `tools-invoke-http.ts` before tool execution
The detector uses a comprehensive heuristic approach with case-insensitive normalized key matching, recursive traversal of nested objects/arrays, and circular reference protection. It includes an allowlist for non-secret resource identifiers (e.g., `fileToken`, `pageToken`) and an emergency bypass via environment variable.
The PR also includes a clean refactor that extracts gateway startup config logic into `startup-config.ts` and adds a method catalog consistency test to ensure all gateway handlers are properly tracked.
Test coverage is thorough with unit tests for the detector, E2E tests for runtime hook blocking, and HTTP integration tests for gateway rejection.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The implementation is well-designed with dual enforcement paths (runtime hook + HTTP gateway), comprehensive test coverage, and defensive coding patterns. The detector logic is sound with proper circular reference handling, and the refactor cleanly extracts startup config without changing behavior. No bypass paths exist, and the emergency escape hatch is properly gated.
- No files require special attention
<sub>Last reviewed commit: 520f616</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#21120: Security/Gateway: guard dangerous HTTP /tools/invoke re-enables
by bmendonca3 · 2026-02-19
79.2%
#8846: fix(tools): block LLM writes to hooks directories
by yubrew · 2026-02-04
78.5%
#21136: fix(security): harden agent autonomy controls
by novalis133 · 2026-02-19
77.7%
#22068: Add tool:before/tool:after internal hook events
by yhindy · 2026-02-20
77.6%
#23814: Gateway: block unauthenticated tool-invocation HTTP surfaces
by bmendonca3 · 2026-02-22
76.9%
#23174: feat(security): credential leak prevention — exfiltration patterns,...
by ihsanmokhlisse · 2026-02-22
76.9%
#23743: Auto-reply: enforce tools.allow/tools.deny on deterministic skill t...
by bmendonca3 · 2026-02-22
76.4%
#6405: feat(security): Add HTTP API security hooks for plugin scanning
by masterfung · 2026-02-01
76.1%
#12260: fix: redact secrets in tool results before persisting to session tr...
by Yida-Dev · 2026-02-09
75.8%
#16320: security: harden default tool policies and secure shell execution
by SuccessSoham · 2026-02-14
75.4%