Skip to content

Commit ff65138

Browse files
committed
Integrate Redactor
1 parent 01ce549 commit ff65138

File tree

5 files changed

+121
-1648
lines changed

5 files changed

+121
-1648
lines changed

README.md

Lines changed: 14 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -414,89 +414,30 @@ class DataProcessor
414414

415415
### Log Redaction
416416

417-
**What it does:** Automatically scrubs sensitive data from log context using a priority-based system to ensure compliance and security while preserving important data.
417+
**What it does:** Automatically scrubs sensitive data from log context using [Kirschbaum Redactor](https://github.com/kirschbaum-development/redactor) to ensure compliance and security while preserving important data.
418418

419-
**Priority System:**
420-
1. **Safe Keys** (highest) - Never redacted, always shown
421-
2. **Blocked Keys** - Always redacted, regardless of content
422-
3. **Regex Patterns** - Redacts values matching specific patterns
423-
4. **Shannon Entropy** (lowest) - Detects high-entropy secrets like API keys
424-
425-
**Configuration:** Redaction options in `config/monitor.php`:
419+
**Configuration:** Simple redaction configuration in `config/monitor.php`:
426420

427421
```php
428-
'log_redactor' => [
422+
'redactor' => [
429423
'enabled' => true,
430-
431-
// Priority 1: Keys that should NEVER be redacted
432-
'safe_keys' => [
433-
'id', 'uuid', 'created_at', 'updated_at', 'timestamp',
434-
'user_id', 'order_id', 'status', 'type', 'name'
435-
],
436-
437-
// Priority 2: Keys that should ALWAYS be redacted
438-
'blocked_keys' => [
439-
'password', 'token', 'api_key', 'authorization', 'secret',
440-
'ssn', 'ein', 'credit_card', 'private_key', 'email'
441-
],
442-
443-
// Priority 3: Regex patterns for value-based detection
444-
'patterns' => [
445-
'email' => '/[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+/',
446-
'credit_card' => '/\b(?:\d[ -]*?){13,16}\b/',
447-
'ssn' => '/\b\d{3}-?\d{2}-?\d{4}\b/',
448-
'phone' => '/\b\d{3}[.-]?\d{3}[.-]?\d{4}\b/',
449-
],
450-
451-
// Priority 4: Shannon entropy detection for unknown secrets
452-
'shannon_entropy' => [
453-
'enabled' => true,
454-
'threshold' => 4.5, // Entropy threshold (0-8 scale)
455-
'min_length' => 20, // Minimum string length to analyze
456-
],
457-
458-
'replacement' => '[REDACTED]',
459-
'mark_redacted' => true, // Add "_redacted": true marker
460-
'max_value_length' => 10000, // Truncate large values
461-
'redact_large_objects' => true, // Limit large arrays/objects
462-
'max_object_size' => 50,
424+
'redactor_profile' => 'default', // Uses Kirschbaum Redactor profiles
463425
],
464426
```
465427

466-
**How it works:**
428+
**Usage:** Redaction is automatically applied to all Monitor log context:
429+
467430
```php
468431
Monitor::from($this)->info('User data', [
469-
// Safe keys - never redacted (Priority 1)
470-
'id' => 123, // → 123 (safe key)
471-
'user_id' => 456, // → 456 (safe key)
472-
'created_at' => '2024-01-15', // → '2024-01-15' (safe key)
473-
474-
// Blocked keys - always redacted (Priority 2)
475-
'password' => 'secret123', // → '[REDACTED]' (blocked key)
476-
'email' => 'user@example.com', // → '[REDACTED]' (blocked key wins over pattern)
477-
478-
// Pattern matching - value-based (Priority 3)
479-
'contact' => 'user@example.com', // → '[REDACTED]' (email pattern)
480-
'card' => '4111-1111-1111-1111', // → '[REDACTED]' (credit card pattern)
481-
482-
// Shannon entropy - high entropy secrets (Priority 4)
483-
'api_token' => 'sk-1234567890abcdef...', // → '[REDACTED]' (high entropy)
484-
'jwt' => 'eyJ0eXAiOiJKV1QiLCJhbGc...', // → '[REDACTED]' (high entropy)
485-
486-
// Normal data - unchanged
487-
'name' => 'John Doe', // → 'John Doe' (low entropy, not blocked)
488-
'description' => 'A simple task', // → 'A simple task' (normal text)
432+
'id' => 123,
433+
'email' => 'user@example.com', // → '[REDACTED]' based on profile rules
434+
'password' => 'secret123', // → '[REDACTED]' based on profile rules
435+
'api_token' => 'sk-1234567890abcdef...', // → '[REDACTED]' based on profile rules
436+
'name' => 'John Doe', // → 'John Doe' (if allowed by profile)
489437
]);
490-
491-
// Result includes redaction marker when data was modified
492-
// { ..., "_redacted": true }
493438
```
494439

495-
**Shannon Entropy Detection:**
496-
- Automatically detects API keys, JWT tokens, and other high-entropy secrets
497-
- Ignores common patterns like URLs, UUIDs, dates, and file paths
498-
- Configurable threshold and minimum length requirements
499-
- Prevents false positives on normal text and structured data
440+
For detailed redaction configuration, rules, patterns, and profiles, see the [Kirschbaum Redactor documentation](https://github.com/kirschbaum-development/redactor).
500441

501442
## Configuration
502443

@@ -517,17 +458,8 @@ MONITOR_CONSOLE_AUTO_TRACE_ENABLED=true
517458
MONITOR_TRACE_HEADER=X-Trace-Id
518459

519460
# Log redaction
520-
MONITOR_LOG_REDACTOR_ENABLED=true
521-
MONITOR_LOG_REDACTOR_REPLACEMENT='[REDACTED]'
522-
MONITOR_LOG_REDACTOR_MARK_REDACTED=true
523-
MONITOR_LOG_REDACTOR_MAX_VALUE_LENGTH=10000
524-
MONITOR_LOG_REDACTOR_LARGE_OBJECTS=true
525-
MONITOR_LOG_REDACTOR_MAX_OBJECT_SIZE=50
526-
527-
# Shannon entropy detection
528-
MONITOR_LOG_REDACTOR_SHANNON_ENABLED=true
529-
MONITOR_LOG_REDACTOR_SHANNON_THRESHOLD=4.5
530-
MONITOR_LOG_REDACTOR_SHANNON_MIN_LENGTH=20
461+
MONITOR_REDACTOR_ENABLED=true
462+
MONITOR_REDACTOR_PROFILE=default
531463
```
532464

533465
**Logging Channel:** Configure a dedicated Monitor logging channel:

composer.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "kirschbaum/monitor",
2+
"name": "kirschbaum-development/monitor",
33
"description": "Laravel observability toolkit with critical control points, structured logging, performance timing, and trace context.",
44
"type": "library",
55
"license": "MIT",
@@ -24,6 +24,12 @@
2424
"email": "belisar.hoxholli@gmail.com"
2525
}
2626
],
27+
"repositories": [
28+
{
29+
"type": "vcs",
30+
"url": "https://github.com/kirschbaum-development/redactor"
31+
}
32+
],
2733
"require-dev": {
2834
"pestphp/pest": "^3.8",
2935
"laravel/pint": "^1.22",
@@ -40,7 +46,8 @@
4046
"require": {
4147
"illuminate/support": "^11.9|^12.0",
4248
"spatie/laravel-package-tools": "^1.16",
43-
"php": "^8.3|^8.4"
49+
"php": "^8.3|^8.4",
50+
"kirschbaum-development/redactor": "dev-main"
4451
},
4552
"extra": {
4653
"laravel": {

0 commit comments

Comments
 (0)