PIIGuard

Protect your logs from leaking sensitive data.

PIIGuard automatically masks personally identifiable information (PII) such as emails and phone numbers in logs and application data.


๐Ÿšจ Problem

Sensitive data often leaks into logs:

Rails.logger.info("User email is test@gmail.com")

Logs may contain:

  • Emails
  • Phone numbers
  • Tokens
  • API keys

This creates security and compliance risks (GDPR, etc.).


โœ… Solution

PIIGuard masks sensitive data automatically:

Rails.logger.info("User email is test@gmail.com")

Becomes:

User email is [EMAIL]

โœจ Features

  • ๐Ÿ”’ Masks emails and phone numbers
  • ๐Ÿง  Works with strings, hashes, and arrays
  • โšก Automatically integrates with Rails logging
  • ๐Ÿ›  Extensible for custom patterns
  • ๐Ÿงฉ Lightweight and easy to use

๐Ÿ“ฆ Installation

Add this line to your application's Gemfile:

gem 'piiguard'

Then execute:

bundle install

๐Ÿš€ Usage

Basic masking

Piiguard.mask("Contact me at test@gmail.com")
# => "Contact me at [EMAIL]"

Mask structured data

data = {
  email: "test@gmail.com",
  phone: "9876543210"
}

Piiguard.mask(data)
# => { email: "[EMAIL]", phone: "[PHONE]" }

๐Ÿ”ง Rails Integration (Automatic)

PIIGuard integrates with Rails automatically:

  • Adds sensitive keys to filter_parameters
  • Masks log messages before they are written

No additional setup required.


โš™๏ธ Configuration

Piiguard.configure do |config|
  config.mask_email = true
  config.mask_phone = true
end

Disable masking:

Piiguard.enabled = false

๐Ÿงช Example

Before:

Started POST "/users" with params:
{ "email": "test@gmail.com" }

After:

Started POST "/users" with params:
{ "email": "[EMAIL]" }

โš ๏ธ Limitations

  • Uses regex-based masking (may not cover all edge cases)
  • Designed for application-level protection, not full compliance guarantees

๐Ÿ›ฃ Roadmap

  • Custom pattern configuration
  • JSON log masking improvements
  • API integration for centralized control
  • Analytics and tracking

๐Ÿค Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.


๐Ÿ“„ License

MIT License