Skip to content

Rack middleware for automatic address munging

License

Notifications You must be signed in to change notification settings

notus-sh/rack-address_munging

Repository files navigation

Rack::AddressMunging

Unit tests Gem Version

Rack::AddressMunging is a Rack middleware for automatic e-mail addresses 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 so you can add it to your Gemfile or install it manually with:

gem install rack-address_munging

Usage

To use the middleware with it's default configuration, just drop it in your middleware stack:

# 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:

# 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 <script> tag that will print it back into the page, based on a 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);});))</script>

For more informations about the exact behavior of each strategy, please refer to the strategies specs data.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/notus-sh/rack-address_munging.

About

Rack middleware for automatic address munging

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages