philiprehberger-mask
Data masking library — auto-detect and redact PII (emails, credit cards, SSNs, tokens) in strings and nested structures.
Requirements
- Ruby >= 3.1
Installation
Add to your Gemfile:
gem "philiprehberger-mask"Then run:
bundle installOr install directly:
gem install philiprehberger-maskUsage
require "philiprehberger/mask"
Philiprehberger::Mask.scrub("Contact us at user@example.com")
# => "Contact us at u***@e******.com"Hash Scrubbing
Philiprehberger::Mask.scrub_hash({
name: "Alice",
email: "alice@example.com",
password: "secret123",
nested: { ssn: "123-45-6789" }
})
# => { name: "Alice", email: "a***@e******.com", password: "[FILTERED]", nested: { ssn: "***-**-6789" } }Custom Patterns
Philiprehberger::Mask.configure do |c|
c.add_pattern(:order_id, /ORD-\d{10}/, replacement: "ORD-XXXXXXXXXX")
endBuilt-in Detectors
| Detector | Pattern | Masking |
|---|---|---|
user@example.com |
u***@e******.com |
|
| Credit Card | 4111-1111-1111-1111 |
****-****-****-1111 |
| SSN | 123-45-6789 |
***-**-6789 |
| Phone | 555-123-4567 |
***-***-4567 |
| IP Address | 192.168.1.1 |
***.***.***.*** |
| JWT | eyJ... |
[REDACTED_JWT] |
API
| Method | Description |
|---|---|
Mask.scrub(string) |
Detect and redact PII in a string |
Mask.scrub_hash(hash, keys: nil) |
Deep-walk and redact hash values |
Mask.configure { |c| ... } |
Register custom patterns |
Mask.reset_configuration! |
Reset to default patterns |
Development
bundle install
bundle exec rspec # Run tests
bundle exec rubocop # Check code styleLicense
MIT