Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
backend-validation-express
Advanced tools
Request data validation middleware using Joi for express in backend
npm install backend-validation-express
const { validator, Joi } = require("backend-validation-express");
const bodySchema = Joi.object({
name: Joi.string().required(),
email: Joi.string().email().required(),
password: Joi.string().min(8).required()
});
const querySchema = Joi.object({
_id: Joi.string().required(),
name: Joi.string().required(),
});
const paramsSchema = Joi.string().required();
const bodyValidator = validator({ body: bodySchema });
const queryValidator = validator({ query: querySchema });
const paramsValidator = validator({ params: paramsSchema });
module.exports = {
bodyValidator,
queryValidator,
paramsValidator
};
const express = require("express");
const { paramsValidator, queryValidator, bodyValidator } = require("./validation");
const app = express();
app.use(express.json());
app.post("/user", bodyValidator, (req, res, next) => {
// Here, req.body has been validated.
return res.status(200).json(req.body);
});
app.get("/user", queryValidator, (req, res, next) => {
// Here, req.query has been validated.
return res.status(200).json(req.query);
});
app.listen(3000, () => {
console.log("Server listening on the port 3000");
});
const { validator, Joi } = require("backend-validation-express");
const bodySchema = Joi.object({
name: Joi.string().required(),
email: Joi.string().email().required(),
password: Joi.string().min(8).required(),
role: Joi.string()
});
const querySchema = Joi.object({
_id: Joi.string().required(),
role: Joi.string().required(),
});
const commonValidator = validator({ body: bodySchema, query: querySchema });
module.exports = { commonValidator };
{
"success": false,
"errors": {
"body": {
"name": "name is required",
"email": "email is required",
"password": "password is required"
}
},
"message": "Validation Error!"
}
{
"success": false,
"errors": {
"body": {
"name": "name is required",
"email": "email is required",
"password": "password is required"
},
"query": {
"_id": "_id is required",
"role": "role is required"
}
},
"message": "Validation Error!"
}
FAQs
Request data validation middleware using Joi for express in backend
The npm package backend-validation-express receives a total of 1 weekly downloads. As such, backend-validation-express popularity was classified as not popular.
We found that backend-validation-express demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.