
Security News
Nx npm Packages Compromised in Supply Chain Attack Leveraging AI CLI Tools
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Validates params
in your controller.
gem "weak_parameters"
class ApplicationController < ActionController::Base
protect_from_forgery
respond_to :json
rescue_from WeakParameters::ValidationError do
head 400
end
end
# WeakParameters provides `validates` class method to define validations.
class RecipesController < ApplicationController
validates :create do
string :name, required: true, except: ["charlie", "dave"], strong: true
integer :type, only: 1..3, strong: true
string :quantity do |value|
value =~ /\A\d+(?:\.\d+)g\z/
end
date :date, format: ["%Y/%m/%d", "%Y.%m.%d"]
time :time, format: "%Y/%m/%d %H:%M:%S"
end
def create
# pass the only parameters with strong option. like strong parameters.
respond_with Recipe.create(permitted_params)
end
end
irb(main):001:0> app.accept = "application/json"
=> "application/json"
irb(main):002:0> app.post "/recipes", name: "alice", type: 1
=> 201
irb(main):003:0> app.post "/recipes", name: "alice"
=> 201
irb(main):004:0> app.post "/recipes", type: 1
=> 400
irb(main):005:0> app.post "/recipes", name: "alice", type: "bob"
=> 400
WeakParameters.stats returns its validation metadata, and this is useful for auto-generating API documents. With autodoc, you can auto-generate API documents with params information.
FAQs
Unknown package
We found that weak_parameters 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
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.