The project is in a healthy, maintained state
Automatically detect and redact sensitive data like emails, credit cards, SSNs, and tokens in strings and nested structures with configurable patterns.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

philiprehberger-mask

Tests Gem Version License

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 install

Or install directly:

gem install philiprehberger-mask

Usage

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")
end

Built-in Detectors

Detector Pattern Masking
Email 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 style

License

MIT