pii-redaction-logging-policy-builder
Prevents logging sensitive user data with redaction rules, logging policies, and safe log formatting. Use for "PII redaction", "log privacy", "GDPR logging", or "data privacy".
When & Why to Use This Skill
This Claude skill automates the creation of robust PII redaction rules and comprehensive logging policies to ensure data privacy and regulatory compliance. It provides developers with ready-to-use TypeScript patterns and a structured framework to prevent sensitive user information, such as emails, SSNs, and credit card numbers, from leaking into application logs, effectively supporting GDPR and CCPA requirements.
Use Cases
- GDPR & CCPA Compliance: Automatically generate regex-based redaction rules for sensitive data like emails, phone numbers, and government IDs to meet international data protection standards.
- Secure System Logging: Implement a 'Safe Logger' wrapper and standardized logging policies that define exactly what data can and cannot be recorded in production environments.
- Data Leakage Prevention: Establish automated checklists and code snippets to sanitize application logs before they are transmitted to third-party monitoring or cloud logging platforms.
- Security Policy Documentation: Create clear, actionable 'DO and DON'T' logging guidelines for engineering teams to maintain consistent security practices across microservices.
| name | pii-redaction-logging-policy-builder |
|---|---|
| description | Prevents logging sensitive user data with redaction rules, logging policies, and safe log formatting. Use for "PII redaction", "log privacy", "GDPR logging", or "data privacy". |
PII Redaction & Logging Policy Builder
Protect user privacy in application logs.
PII Redaction
const PII_PATTERNS = {
email: /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g,
ssn: /\b\d{3}-\d{2}-\d{4}\b/g,
phone: /\b\d{3}[-.]?\d{3}[-.]?\d{4}\b/g,
creditCard: /\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/g,
};
function redactPII(message: string): string {
let redacted = message;
Object.entries(PII_PATTERNS).forEach(([type, pattern]) => {
redacted = redacted.replace(pattern, `[REDACTED_${type.toUpperCase()}]`);
});
return redacted;
}
// Safe logging
logger.info(redactPII(\`User registered: \${email}\`));
// Output: "User registered: [REDACTED_EMAIL]"
Logging Policy
# Logging Policy
## ✅ DO Log
- Request IDs
- User IDs (hashed)
- HTTP status codes
- Response times
- Error types
- Feature flags
## ❌ DON'T Log
- Passwords
- Credit card numbers
- SSNs
- API keys
- Full emails (hash first)
- Full names
- Addresses
Output Checklist
- Redaction rules defined
- Logging policy documented
- Safe logger wrapper
- Team trained
- Log monitoring ENDFILE