
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
effective_obfuscation
Advanced tools
Display unique 10-digit numbers instead of ActiveRecord IDs. Hides the ID param so curious website visitors are unable to determine your user or order count.
Turn a URL like:
http://example.com/users/3
into something like:
http://example.com/users/2356513904
Sequential ActiveRecord ids become non-sequential, random looking, numeric ids.
# user 7000
http://example.com/users/5270192353
# user 7001
http://example.com/users/7107163820
# user 7002
http://example.com/user/3296163828
This is a Rails 4 compatible version of obfuscate_id (https://github.com/namick/obfuscate_id) which also adds totally automatic integration with Rails finder methods.
Add to Gemfile:
gem 'effective_obfuscation'
Run the bundle command to install it:
bundle install
Add the mixin to an existing model:
class User
acts_as_obfuscated
end
Thats it. Now URLs for a User will be generated as
http://example.com/users/2356513904
As well, any find(), exists?(), find_by_id(), find_by(), where(:id => params[:id]) and all Arel table finder methods will be automatically translated to lookup the proper underlying ID.
You shouldn't require any changes to your view or controller code. Just Works with InherittedResources and ActiveAdmin.
Because of the underlying ScatterSwap algorithm, the obfuscated IDs must be exactly 10 digits in length.
However, if you'd like to add some formatting to make the 10-digit number more human readable and over-the-phone friendly
class User
acts_as_obfuscated :format => '###-####-###'
end
will generate URLs that look like
http://example.com/users/235-6513-904
Any String.parameterize-able characters will work as long as there are exactly 10 # (hash symbol) characters in the format string somewhere.
The Spin value is basically a salt used by the ScatterSwap algorithm to randomize integers.
In this gem, the default spin value is set on a per-model basis.
There is really no reason to change it; however, you can specify the spin value directly if you wish
class User
acts_as_obfuscated :spin => 123456789
end
So maybe you just want access to the underlying ScatterSwap obfuscation algorithm including the additional model-specific formatting.
To obfuscate, pass any number as a string, or an integer
User.obfuscate(43) # Using acts_as_obfuscated :format => '###-####-###'
=> "990-5826-174"
And to de-obfuscate, pass any number as a string or an integer
User.deobfuscate("990-5826-174")
=> 43
User.deobfuscate(9905826174)
=> 43
By default, all finder method except find()
will work with both obfuscated and database IDs.
This means,
User.where(:id => "990-5826-174")
=> User<id: 43>
returns the same User as
User.where(:id => 43)
=> User<id: 43>
This behaviour is not applied to find()
because it would allow a user to visit:
http://example.com/users/1 http://example.com/users/2 ...etc...
and enumerate all users.
Please continue to use @user = User.find(params[:id]) in your controller to prevent route enumeration.
Any other internally used finder methods, where
and find_by_id
should respond to both obfuscated and database IDs for maximum compatibility.
MIT License. Copyright Code and Effect Inc.
This project was inspired by
ObfuscateID (https://github.com/namick/obfuscate_id)
and uses the same (simply genius!) underlying algorithm
ScatterSwap (https://github.com/namick/scatter_swap)
The test suite for this gem is unfortunately not yet complete.
Run tests by:
rake spec
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that effective_obfuscation demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.