Cloaked
Cloaked provides a simple mechanism to help obfuscate ActiveRecord ids and/or other database attributes by generating public keys that can be used and made publicly visible.
Installation
Add this line to your application's Gemfile:
gem 'cloaked'
And then execute:
$ bundle
Or install it yourself as:
$ gem install cloaked
Usage
Cloaked needs to be included in your model:
class Post < ApplicationRecord
include Cloaked
end
After including it in the model, you can specify the list of public keys for which you want to generate public keys:
class Post < ApplicationRecord
include Cloaked
with_cloaked_keys :public_id
end
By default, cloak will generate a random URL-safe base64 of 8 bytes. You can specify a different method for generating the public keys:
class Post < ApplicationRecord
include Cloaked
with_cloaked_keys :public_id, method: :hex
end
Will generate a random hexadecimal string with 16 characters.
class Post < ApplicationRecord
include Cloaked
with_cloaked_keys :public_id, method: :uuid
end
Will generate a v4 random UUID (Universally Unique IDentifier).
You can specify a custom length:
class Post < ApplicationRecord
include Cloaked
with_cloaked_keys :public_id, size: 16
end
Only applies to :base64
and hex
. Note that in the latter case, the length of the hexadecimal string will be twice the size amount.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/lightthefuserun/cloaked. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the Cloaked project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
TODO
- Load Cloaked automatically with railtie.