
Security News
Happy Birthday, Shai-Hulud
It has been one year since Shai-Hulud made its first appearance on npm.
@sylphx/cat-redaction
Advanced tools
OWASP-compliant redaction plugin for @sylphx/cat logger
1.49 KB • OWASP 2024 compliant • PII detection • Log injection prevention
npm install @sylphx/cat @sylphx/cat-redaction
Automatically redacts sensitive data from logs to prevent data leaks and comply with security standards. Includes field-based redaction with glob patterns, built-in PII detection (credit cards, SSNs, emails, phones), and log injection attack prevention. Follows OWASP Top 10 2024 security guidelines.
import { createLogger } from '@sylphx/cat'
import { redactionPlugin } from '@sylphx/cat-redaction'
const logger = createLogger({
plugins: [redactionPlugin()]
})
logger.info('User login', {
username: 'alice',
password: 'secret123', // Will be redacted
email: 'alice@example.com'
})
// {"level":"info","message":"User login","data":{"username":"alice","password":"[REDACTED]","email":"[REDACTED]"}}
import { redactionPlugin } from '@sylphx/cat-redaction'
const logger = createLogger({
plugins: [
redactionPlugin({
fields: [
'password',
'apiKey',
'creditCard',
'user.ssn', // Nested field
'*.token', // Glob pattern
'auth.**' // Match any nested field under auth
]
})
]
})
logger.info('Payment processed', {
user: { name: 'Alice', ssn: '123-45-6789' },
auth: { token: 'abc123', secret: 'xyz789' }
})
// SSN, token, and secret are redacted
import { redactionPlugin } from '@sylphx/cat-redaction'
const logger = createLogger({
plugins: [
redactionPlugin({
redactPII: true,
piiPatterns: ['creditCard', 'ssn', 'email', 'phone', 'ipv4']
})
]
})
logger.info('User submitted: 4532-1234-5678-9010 and ssn 123-45-6789')
// {"level":"info","message":"User submitted: [REDACTED] and ssn [REDACTED]"}
logger.info('Contact', {
message: 'Call me at (555) 123-4567 or email test@example.com'
})
// Both phone and email redacted from message
import { redactionPlugin } from '@sylphx/cat-redaction'
const logger = createLogger({
plugins: [
redactionPlugin({
fields: ['*'], // Redact all fields
excludeFields: ['userId', 'timestamp', 'requestId'] // Except these
})
]
})
redactionPlugin(options?: RedactionPluginOptions): PluginCreates a redaction plugin instance.
Options:
enabled?: boolean - Enable redaction (default: true)fields?: string[] - Field paths to redact with glob pattern support (default: common sensitive fields)redactPII?: boolean - Enable PII detection and redaction (default: true)piiPatterns?: Array<'creditCard' | 'ssn' | 'email' | 'phone' | 'ipv4' | 'ipv6'> - PII patterns to detect (default: ['creditCard', 'ssn', 'email', 'phone'])customPatterns?: Array<{ name: string, pattern: RegExp, replacement?: string }> - Custom regex patternsreplacement?: string - Redaction replacement text (default: '[REDACTED]')preventLogInjection?: boolean - Prevent log injection attacks (default: true)excludeFields?: string[] - Fields to exclude from redactionThe following fields are redacted by default:
password, passwd, pwdsecrettokenapiKey, api_keyapiSecret, api_secretauth, authorizationbearercookiesession, sessionId, session_idprivateKey, private_keyaccessToken, access_tokenrefreshToken, refresh_tokencsrfToken, csrf_tokenDetects major credit card formats (Visa, MasterCard, Amex, Discover):
4532-1234-5678-9010 → [REDACTED]
Detects US SSN format:
123-45-6789 → [REDACTED]
Detects email addresses:
user@example.com → [REDACTED]
Detects US phone number formats:
(555) 123-4567 → [REDACTED]
555-123-4567 → [REDACTED]
+1-555-123-4567 → [REDACTED]
Detects IP addresses:
192.168.1.1 → [REDACTED]
2001:0db8:85a3::8a2e:0370:7334 → [REDACTED]
import { redactionPlugin } from '@sylphx/cat-redaction'
const logger = createLogger({
plugins: [
redactionPlugin({
customPatterns: [
{
name: 'employeeId',
pattern: /EMP-\d{6}/g,
replacement: 'EMP-XXXXX'
},
{
name: 'apiKey',
pattern: /sk-[a-zA-Z0-9]{32}/g
}
]
})
]
})
logger.info('Employee EMP-123456 used key sk-abcdef1234567890abcdef1234567890')
// "Employee EMP-XXXXX used key [REDACTED]"
const logger = createLogger({
plugins: [
redactionPlugin({
fields: ['user.password', 'payment.*.cardNumber']
})
]
})
logger.info('Payment', {
user: {
id: 123,
password: 'secret' // Redacted
},
payment: {
method: {
cardNumber: '4532-1234-5678-9010' // Redacted
}
}
})
The plugin automatically sanitizes logs to prevent injection attacks:
const logger = createLogger({
plugins: [redactionPlugin({ preventLogInjection: true })]
})
// Malicious input with newlines and ANSI codes
const maliciousInput = 'Normal log\n\x1b[31mFAKE ERROR\x1b[0m'
logger.info(maliciousInput)
// "Normal log\\nFAKE ERROR" (newlines escaped, ANSI codes removed)
This prevents:
This plugin helps meet OWASP Top 10 2024 requirements:
MIT © Kyle Zhu
FAQs
OWASP-compliant redaction plugin for @sylphx/cat logger
We found that @sylphx/cat-redaction demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.

Security News
It has been one year since Shai-Hulud made its first appearance on npm.

Research
/Security News
Operators behind PolinRider used a compromised GitHub account to plant malware in four development versions of a Packagist package with 700,000+ downloads.

Security News
GitHub Actions now supports cache-mode, a least-privilege control on the Actions cache aimed at the cache poisoning technique behind recent compromises.