philiprehberger-log_filter 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +18 -0
- data/lib/philiprehberger/log_filter/presets.rb +26 -0
- data/lib/philiprehberger/log_filter/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1ded3c219f5f5509ea3cf4813493cd6450dc9cdf7a2ecda8e670e85aff637143
|
|
4
|
+
data.tar.gz: 94e643e2a2127d90ab99c910dd5e0c6052599e2bd15004f387d64e8b60ca0cc0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9de7b0858d9b8af17a4723625f6cc60a71d049c4f927759f243f24e61d8598c2f3d08eec20a8d3126a3de4feb4227251037eff4db28587f2e90e94f9d8b7f2b5
|
|
7
|
+
data.tar.gz: 2d8436630ec16af0cd964e01aca8c075b9609aced3236eceb15713779d43a930f5c2502b28836fd0bffc0ed76a88d8f77d48232d66a383464950ede2051f4675
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.4.0] - 2026-04-30
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `Presets.pii` — redacts emails, US Social Security Numbers, and 13–19 digit credit-card-shaped numbers with `[REDACTED]`
|
|
14
|
+
- `Presets.secrets` — redacts `Bearer` tokens, `api_key=`/`access_token=` parameters, and AWS-style access key IDs (`AKIA…`) with `[REDACTED]`
|
|
15
|
+
|
|
10
16
|
## [0.3.0] - 2026-04-17
|
|
11
17
|
|
|
12
18
|
### Added
|
data/README.md
CHANGED
|
@@ -138,6 +138,22 @@ pipeline.apply("login password=abc123") # => "login password=[REDACTED
|
|
|
138
138
|
|
|
139
139
|
The chained filter tracks its own `stats` independently of the source filters.
|
|
140
140
|
|
|
141
|
+
### PII and Secret Redaction Presets
|
|
142
|
+
|
|
143
|
+
```ruby
|
|
144
|
+
require "philiprehberger/log_filter"
|
|
145
|
+
|
|
146
|
+
pii = Philiprehberger::LogFilter::Presets.pii
|
|
147
|
+
pii.apply("login user=alice@example.com") # => "login user=[REDACTED]"
|
|
148
|
+
pii.apply("SSN 123-45-6789 lookup") # => "SSN [REDACTED] lookup"
|
|
149
|
+
pii.apply("card 4242424242424242 charged") # => "card [REDACTED] charged"
|
|
150
|
+
|
|
151
|
+
secrets = Philiprehberger::LogFilter::Presets.secrets
|
|
152
|
+
secrets.apply("Authorization: Bearer abc.def-_xyz") # => "Authorization: Bearer [REDACTED]"
|
|
153
|
+
secrets.apply("GET /v1?api_key=sk_live_xyz123 200") # => "GET /v1?api_key=[REDACTED] 200"
|
|
154
|
+
secrets.apply("AKIAIOSFODNN7EXAMPLE in env") # => "[REDACTED] in env"
|
|
155
|
+
```
|
|
156
|
+
|
|
141
157
|
### Filter Statistics
|
|
142
158
|
|
|
143
159
|
```ruby
|
|
@@ -175,6 +191,8 @@ filter.stats # => { dropped: 0, passed: 0, replaced: 0, sampled: 0 }
|
|
|
175
191
|
| `Presets.health_check` | Filter dropping health-check paths |
|
|
176
192
|
| `Presets.assets` | Filter dropping static-asset requests |
|
|
177
193
|
| `Presets.bots` | Filter dropping bot/crawler traffic |
|
|
194
|
+
| `Presets.pii` | Filter redacting emails, SSNs, and credit-card-shaped numbers with `[REDACTED]` |
|
|
195
|
+
| `Presets.secrets` | Filter redacting Bearer tokens, `api_key=`/`access_token=` values, and AWS access keys |
|
|
178
196
|
| `LogFilter.wrap(logger, filter)` | Convenience wrapper constructor |
|
|
179
197
|
| `LogFilter.health_check_filter` | Shortcut for `Presets.health_check` |
|
|
180
198
|
| `LogFilter.asset_filter` | Shortcut for `Presets.assets` |
|
|
@@ -25,6 +25,32 @@ module Philiprehberger
|
|
|
25
25
|
def self.bots
|
|
26
26
|
Filter.new.drop(/bot|crawler|spider|slurp|googlebot|bingbot/i)
|
|
27
27
|
end
|
|
28
|
+
|
|
29
|
+
# Filter that redacts common PII patterns from log lines.
|
|
30
|
+
#
|
|
31
|
+
# Replaces email addresses, US Social Security Numbers, and 13–19 digit
|
|
32
|
+
# credit-card-shaped numbers with `[REDACTED]`.
|
|
33
|
+
#
|
|
34
|
+
# @return [Filter] a filter replacing PII with `[REDACTED]`
|
|
35
|
+
def self.pii
|
|
36
|
+
Filter.new
|
|
37
|
+
.replace(/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/i, '[REDACTED]')
|
|
38
|
+
.replace(/\b\d{3}-\d{2}-\d{4}\b/, '[REDACTED]')
|
|
39
|
+
.replace(/\b\d(?:[ -]?\d){12,18}\b/, '[REDACTED]')
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Filter that redacts common secret patterns from log lines.
|
|
43
|
+
#
|
|
44
|
+
# Replaces Bearer tokens, `api_key=...`/`api-key=...` values, and
|
|
45
|
+
# AWS-style access key IDs with `[REDACTED]`.
|
|
46
|
+
#
|
|
47
|
+
# @return [Filter] a filter replacing secrets with `[REDACTED]`
|
|
48
|
+
def self.secrets
|
|
49
|
+
Filter.new
|
|
50
|
+
.replace(/Bearer\s+[A-Za-z0-9._-]+/, 'Bearer [REDACTED]')
|
|
51
|
+
.replace(/\b(api[_-]?key|access[_-]?token)=([A-Za-z0-9._-]+)/i, '\1=[REDACTED]')
|
|
52
|
+
.replace(/\bAKIA[0-9A-Z]{16}\b/, '[REDACTED]')
|
|
53
|
+
end
|
|
28
54
|
end
|
|
29
55
|
end
|
|
30
56
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-log_filter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-05-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Pattern-based log filtering — drop or transform log lines matching rules.
|
|
14
14
|
Includes preset filters for health checks, static assets, and bot traffic.
|