
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
body-checker
Advanced tools
A simple tool to protect your API against bad request parameters
npm install body-checker
var check = require('body-checker');
check([body to validate], [configuration options], [callback]);
This is the request object (req.body
in express) that you want to validate.
Currently we only support shallow objects, but if there is an overwhelming need for deep objects, let us know in the issues and we will implement deep validation.
This is an object that outlines your allowed request parameters. It takes the following form:
{
paramKey: {
type: 'string', // String: Required
required: false, // Boolean: Optional, defaults to false
default: 'default value' // String: Optional
},
nextParamKey: { ... }
}
Type is a required parameter. If you don't care what type it is, you can set type to any
.
Callback is a traditional callback(err, data) function. It will pass back detailed errors for debugging or the final req.body
object. This allows you to send your own generic error to the client to prevent phishing attacks. See example below.
var check = require('body-checker');
module.exports = function(req, res, next) {
check(req.body, {
name: {
type: 'string',
default: 'public',
required: true
},
id: {
type: 'integer',
required: true
}
}, function(err, body) {
if(err) {
// Log detailed error message on server
console.log(err.message);
// Send generic error to client
res.status(400).send({
message: 'Bad Request'
});
} else {
// do stuff with safe parameters
// and eventually...
res.status(200).send(body);
}
});
}
npm test
FAQs
A simple tool to protect your API against bad request parameters
We found that body-checker 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.