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