feat(security): add Privacy Shield for PII masking in model context#12050
feat(security): add Privacy Shield for PII masking in model context#120500xRaini wants to merge 9 commits intoopenclaw:mainfrom
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Additional Comments (1)
Consider making Also appears in: src/infra/privacy.ts:89-124 Prompt To Fix With AIThis is a comment left during a code review.
Path: src/agents/pi-embedded-runner/run/attempt.ts
Line: 560:568
Comment:
**Type mismatch in history scrub**
`scrubPIIInMessages()` is declared to return `unknown[]` (`src/infra/privacy.ts:89`), but its result is passed to `activeSession.agent.replaceMessages(...)` here. In this file, messages are typed as `AgentMessage[]` and `replaceMessages` expects `AgentMessage[]`, so this call site either won’t type-check or will silently lose type guarantees (and could allow malformed message objects through).
Consider making `scrubPIIInMessages` accept/return `AgentMessage[]` (or a generic constrained to `{ content: ... }`) so `replaceMessages(scrubbed)` stays type-safe.
Also appears in: src/infra/privacy.ts:89-124
How can I resolve this? If you propose a fix, please make it concise. |
Introduces a privacy protection layer that scans and redacts PII
(Personally Identifiable Information) before sending it to LLMs.
Features:
- Default redactors for Email, Phone, Credit Cards, and IPv4.
- Configurable via openclaw.json (security.privacy.piiScrubbing).
- Support for custom redaction patterns.
- Scrubs both System Prompt and message history.
Configuration:
{
"security": {
"privacy": {
"piiScrubbing": "on",
"piiPatterns": ["my-private-regex"]
}
}
}
lobster-biscuit
The string literal on line 318 used backslash-escaped quotes (\") instead of normal quotes, causing tsgo, lint, format, and build failures across the entire CI pipeline.
Summary
Add a Privacy Shield layer that scans and redacts PII (Personally Identifiable Information) from the agent's outbound responses before they are sent to chat channels.
Motivation
This is specifically designed to combat Prompt Injection attacks. While the model needs access to sensitive info in its context to be helpful, we want to prevent that info from being "leaked" to external chat channels if the model is tricked or "hallucinates" private data into its output.
Features
security.privacy.piiScrubbing.Configuration Example
{ "security": { "privacy": { "piiScrubbing": "on", "piiPatterns": ["\\bsecret-project-code\\b"] } } }Behavior Changes
Files Changed
src/infra/privacy.ts: Core PII scrubbing logic.src/infra/outbound/deliver.ts: Integration into the outbound delivery pipeline.src/config/types.security.ts: New security configuration types.src/config/zod-schema.ts: Configuration schema validation.AI-Assisted Contribution 🤖
lobster-biscuit
Greptile Overview
Greptile Summary
This PR introduces a “Privacy Shield” that redacts PII from agent context before sending it to LLMs. It adds a new
security.privacyconfig section (types + Zod schema), implements PII scrubbing utilities insrc/infra/privacy.ts, and integrates scrubbing into the embedded runner by applying it to the generated system prompt and to the limited message history before callingreplaceMessages().Key integration points are in
src/agents/pi-embedded-runner/run/attempt.ts, where the system prompt override is scrubbed and the session history is scrubbed after validation/limiting.Confidence Score: 3/5
scrubPIIInMessages()returnsunknown[]and is fed intoreplaceMessages(), which is intended to operate onAgentMessage[]. That’s either a TS compile break or a loss of guarantees in the message pipeline. Once the scrubber is typed to preserveAgentMessageshapes, the remaining changes appear low-risk.