https://github.com/notus-sh/rack-address_munging
Rack middleware for automatic address munging
https://github.com/notus-sh/rack-address_munging
middleware rack ruby
Last synced: about 1 year ago
JSON representation
Rack middleware for automatic address munging
- Host: GitHub
- URL: https://github.com/notus-sh/rack-address_munging
- Owner: notus-sh
- License: other
- Created: 2018-03-12T14:13:32.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2025-03-10T22:27:12.000Z (over 1 year ago)
- Last Synced: 2025-04-16T02:04:23.308Z (about 1 year ago)
- Topics: middleware, rack, ruby
- Language: Ruby
- Size: 61.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Rack::AddressMunging
[](https://github.com/notus-sh/rack-address_munging/actions/workflows/unit-tests.yml)
[](https://badge.fury.io/rb/rack-address_munging)
`Rack::AddressMunging` is a Rack middleware for automatic [e-mail addresses munging](https://en.wikipedia.org/wiki/Address_munging).
Once added to your middleware stack, `Rack::AddressMunging` will parse the body of any HTML response and mung it to obfuscate email addresses, in hope to prevent spambots to collect them too easily.
## Installation
`Rack::AddressMunging` is distributed as a gem and available on [rubygems.org](https://rubygems.org/gems/rack-address_munging) so you can add it to your `Gemfile` or install it manually with:
```ruby
gem install rack-address_munging
```
## Usage
To use the middleware with it's default configuration, just drop it in your middleware stack:
```ruby
# In config.ru or wherever your stack is defined
require 'rack/address_munging'
use Rack::AddressMunging
```
If you want to use another munging strategy, precise it as an argument:
```ruby
# In a Rails initializer
require 'rack/address_munging'
module YourRailsAppName
class Application
config.middleware.use Rack::AddressMunging, strategy: :hex
end
end
```
## Supported Strategies
### `:Hex`
Replace email addresses and mailto href attributes values with an hexadecimal entities alternative.
Input: email@example.com
Output: email@example.com
`:Hex` is the default strategy.
### `:Rot13JS`
Replace email addresses and full mailto links with a `` tag that will print it back into the page, based on a [ROT13](https://en.wikipedia.org/wiki/ROT13) version.
Input: email@example.com
Output: <script type="text/javascript">document.write("rznvy(at)rknzcyr.pbz".replace(/(at)/, '@').replace(/[a-z]/gi,function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);});))
For more informations about the exact behavior of each strategy, please refer to the [strategies specs data](https://github.com/notus-sh/rack-address_munging/blob/master/spec/data/strategy.yml).
## Contributing
Bug reports and pull requests are welcome on GitHub at .