Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
AttrStatements is a simple strong typed attributes generator on classes. It also add the ability to validate these attributes. These validations are extended with ActiveModel::Errors, so you can have a full integration with ActiveRecord. A typical usecase will be extending a serializer with AttrStatements in order to have automatic ActiveModel::Errors management.
Add this line to your application's Gemfile:
gem 'attr_statements', '~> 0.1.1'
And then execute:
$ bundle
Or install it yourself as:
$ gem install attr_statements
require 'attr_statements'
class Profile
extend AttrStatements
attr_statement :email, String, presence: true, length: { maximum: 15 }
attr_statement :city, String
end
Profile.attr_statements
# => [:email, :city]
profile = Profile.new
# => #<Profile:0x007fc83511e8b0>
profile.valid?
# => false
profile.errors.any?
# => true
profile.errors
# => #<ActiveModel::Errors:0x007fc82bec5d88 @base=#<Profile:0x007fc83511e8b0 @errors=#<ActiveModel::Errors:0x007fc82bec5d88 ...>>, @messages={:email=>["can't be blank"]}>
profile.errors.full_messages
# => ["Email can't be blank"]
profile.email = 'mylongtest@email.com'
# => "mylongtest@email.com"
profile.valid?
# => false
profile.errors.full_messages
# => ["Email is too long (maximum is 15 characters)"]
profile.email = 'test@email.com'
# => 'test@email.com'
profile.valid?
# => true
profile.email = 42
# => 42
profile.valid?
# => false
profile.errors.full_messages
# => ["Email must be a String"]
The type
validation for example would need a translation (at least a default :en
). Translation is compatible with I18n. So all we need, is a yml with:
en:
errors:
messages:
type: 'must be a %{class}'
AttrStatements errors can be easily injected within an ActiveRecord validation processus. Here is an example:
Class User < ActiveRecord::Base
serialize :profile_attributes, Profile
after_validation :validate_profile_attributes
private
def validate_profile_attributes
if profile_attributes && !profile_attributes.valid?
# merge child errors with parent errors
profile_attributes.errors.each do |k, v|
errors.add("profile_attribute_#{k}", v)
end
end
end
end
User will now have the :profile_attributes
errors generated by AttrStatements on create
, update
. (see ActiveRecord::Validations#valid?)
To run tests:
$ bundle exec rake spec
To run rubocop:
$ rubocop
To run reek:
$ reek
Bug reports and pull requests are welcome on GitHub at https://github.com/SparkHub/attr_statements. 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.
FAQs
Unknown package
We found that attr_statements 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.