Multi-region async PII detection engine for OpenClaw sessions. Detects 8 categories of sensitive personal data across 10 country/region jurisdictions and logs audit events locally as NDJSON.
openclaw-security
PHONE / EMAIL / PERSON_NAME / ADDRESS / PASSPORT / BANK_CARD / NATIONAL_ID / SOCIAL_ACCOUNT
+CC 国际手机号)
input / prompt / context / knowledge_base
high(证件/银行卡或组合信息),low(单一弱标识)
input 100%(5m),prompt 20%(24h),context 20%(1h),knowledge_base 100%(24h)
--no-cache
--text,请使用 --file + --delete-after-read
truncated: true
cleanup.py --dry-run 先演练
Scan via file (recommended for background / automated scans):
python scripts/audit_worker.py --session-id SESSION_001 --source-type input --file content.txt
Scan via file + auto-delete (secure temp-file workflow):
python scripts/audit_worker.py --session-id SESSION_001 --source-type input --file tmp_scan.txt --delete-after-read
Scan via stdin:
echo "张三的手机号是13812345678" | python scripts/audit_worker.py --session-id SESSION_001 --source-type input
Quick manual test (WARNING: content visible in process list):
python scripts/audit_worker.py --session-id S001 --source-type input --text "short test" --json
input — User input text
prompt — System or user prompts
context — Conversation context
knowledge_base — Knowledge base content
PHONE, EMAIL, PERSON_NAME, ADDRESS, PASSPORT, BANK_CARD, NATIONAL_ID, SOCIAL_ACCOUNT
CN, US, AU, SG, MY, TH, ID, DE, UK, FR (+ INTL via +CC phone prefix)
The audit worker includes built-in smart sampling to efficiently handle large contexts:
input): 100% scan rate, 5-min cache TTL — every user message is scanned, but identical repeats within 5 minutes are skipped.
prompt): 20% scan rate, 24-hour cache TTL — prompts rarely change; first scan is cached for 24 hours.
context): 20% scan rate, 1-hour cache TTL — context overlaps heavily; only sample 1 in 5 submissions.
knowledge_base): 100% first-scan rate, 24-hour cache TTL — static content is fully scanned once, then deduped for 24 hours.
Bypass sampling for manual / forced scans:
python scripts/audit_worker.py --session-id S001 --source-type context --text "text" --no-cache
When auditing session content as a background task:
--delete-after-read — NEVER pass content via --text in background scans. Write content to a temp file, pass --file, and let the script auto-delete it.
# Step 1: Write content to temp file (no PII in command-line args)
$tmpFile = [System.IO.Path]::GetTempFileName()
[System.IO.File]::WriteAllText($tmpFile, $userInput, [System.Text.Encoding]::UTF8)
# Step 2: Background scan — script reads and deletes the temp file
Start-Process -NoNewWindow -FilePath python -ArgumentList "scripts/audit_worker.py --session-id $sid --source-type input --file $tmpFile --delete-after-read"
# Same pattern for other source types:
$tmpPrompt = [System.IO.Path]::GetTempFileName()
[System.IO.File]::WriteAllText($tmpPrompt, $systemPrompt, [System.Text.Encoding]::UTF8)
Start-Process -NoNewWindow -FilePath python -ArgumentList "scripts/audit_worker.py --session-id $sid --source-type prompt --file $tmpPrompt --delete-after-read"
openclaw-security-audit/YYYY-MM-DD/events.ndjson
Default: 7 days. Cleanup:
python scripts/cleanup.py --days 7
Dry run first:
python scripts/cleanup.py --days 7 --dry-run
Maximum input: 32,768 characters (32K). Content exceeding this limit is truncated to the first 32K characters. The audit record carries truncated: true and original input_chars count.
Every scan invocation writes an NDJSON record — including clean and skipped outcomes.
Each NDJSON line contains:
event_id — UUID
session_id — Caller-provided session ID (required)
source_type — One of: input, prompt, context, knowledge_base
status — detected, clean, or skipped
labels — Array of detected PII types (detected only)
regions — Array of matched regions/country codes (detected only)
risk_level — high or low (detected only)
matched_count — Number of PII matches
matches — Array of {label, confidence, masked_preview, region} (detected only)
content_hash — SHA256 prefix for dedup (no raw content stored)
input_chars — Original input size in characters
truncated — Whether input was truncated to 32K
created_at — ISO 8601 UTC timestamp
--text in background scans — use --file + --delete-after-read
Environment variable override for audit output directory:
$env:OPENCLAW_AUDIT_DIR = "C:\path\to\custom\audit\dir"
See references/patterns.md for detection pattern details.
共 1 个版本