
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
active_record_encryption
Advanced tools
Provides transparent encryption attribute for ActiveRecord. You can easily encrypt and decrypt sensitive data.
This implementation is based on ActiveRecord's Attribute-API, and it is very simple and powerful.
Add definition of the encrypted attribute in your application.
# app/models/post.rb
class Post < ActiveRecord::Base
encrypted_attribute(:name, :string)
end
That's all. This column is already enabled for transparent encryption.
post = Post.create!(name: 'Baker')
post.name #=> "Baker"
post.name_before_type_cast #=> "ZS~\xAB\x8C\xD1\xCA\u0016\xA8\x80f@\xE8s\xB7J/\xA9\xEC/\xBDj\xDE6(Y\u007F\u0016<W\u0011\x96"
You can set encryption as default.
# config/initializers/active_record_encryption.rb
ActiveRecordEncryption.default_encryption = {
encryptor: :active_support,
key: ENV['ENCRYPTION_KEY'],
salt: ENV['ENCRYPTION_SALT']
}
.encrypted_attribute()
wrapped on .attribute
method. and you can pass the same arguments as ActiveRecord::Attributes.attribute
class PointLog < ActiveRecord::Base
encrypted_attribute(:date, :date)
encrypted_attribute(:point, :integer, default: -> { Current.user.current_point })
encrypted_attribute(:price, Money.new)
encrypted_attribute(:serialized_address, :string)
# Change encryptor
encrypted_attribute(:name, :field, encryption: { encryptor: :active_support, key: ENV['ENCRYPTION_KEY'], salt: ENV['ENCRYPTION_SALT'] })
end
There are four supported encryptors: :active_support
, :aes_256_cbc
.
:active_support
ActiveSupport::MessageEncryptor
encrypted_attribute(:field, :type, encryption: { encryptor: :active_support, key: SecureRandom.hex(64), salt: SecureRandom.hex(64) })
:aes_256_cbc
OpenSSL::Cipher.new('AES-256-CBC')
encrypted_attribute(:field, :type, encryption: { encryptor: :aes_256_cbc, key: SecureRandom.hex(64) })
You can easilly add your encryptor.
class YourEncryptor < ActiveRecordEncryption::Encryptor::Base
def initialize(key:)
@key = key
end
def encrypt(value)
# An encrypt method that returns the encrypted string
end
def decrypt(value)
# A decrypt method that returns the plaintext
end
end
ActiveRecordEncryption.default_encryption = {
encryptor: YourEncryptor,
key: ENV['ENCRYPTION_KEY']
}
For encryptors requiring secret keys, you can generate them. These values should be stored outside of your application repository for added security.
ruby -e "require 'securerandom'; puts SecureRandom.hex(64)"`
Create or modify the table that your model like the following:
NOTE: Default limit of ActiveRecord's binary column is too long. Please set limit(< 0xfff) for encrypted columns.
ActiveRecord::Schema.define do
create_table(:posts) do |t|
t.binary :name, limit: 1000
end
end
bundle exec appraisal install
bundle exec appraisal 6.1-stable rspec
bundle exec appraisal 7.0-stable rspec
Bug reports and pull requests are welcome on GitHub at https://github.com/alpaca-tc/active_record_encryption. 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.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the ActiveRecord::Encryption
project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
FAQs
Unknown package
We found that active_record_encryption demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.