
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
expressjs-check
Advanced tools
A simple library for data validation.
expressjs-check allows pattern-based data validation. This build is specifically implemented to support expressJS functionalities, such as auto-respond with error messages.
You can install expressjs-check by simply entering the command npm i expressjs-check. Once it has installed you can use it in your Express app however you'd like. Below is a little example:
const express = require('express');
const app = express();
const port = 3000;
const checker = require('expressjs-check');
app.get('/', (req, res) => {
// Check GET Parameters
if(checker.check(req.query, res, {
someString: {type:"string", required:true}
})) return;
// If parameter "someString" is passed
res.status(200);
res.send({ok:true});
});
app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`));
Patterns are JSON Objects defining a certain format of values that should be checked. Every key in the pattern object represents a key of the same name in the check-object. The check() function returns false if all given parameters are valid, true otherwise.
Values can be set as required using required:true.
If null should be allowed, allowNull:true must be set.
Values can be set as required conditionally by using the requiredIf attribute. This allows for a JS-string to be passed that evaluates to either true or false, deciding whether or not the value is required. Other values in the object can be accessed using #keyname, for example:
'#somenumber === 1' will make the value required if the value somenumber is equal to 1.
Not-required values can be set to a specified default value by using the default attribute:
{ a: { type:"number", default: 5 } }
The example above would insert the value 5 in the a key of the input object if it was initially undefined. If a value is provided in the input all checks are still run as normal and the original value is not overwritten.
null is, by default, not treated as an undefined value. In order to replace null values with the default values as well, the replaceNull attribute must be set to true.
A pattern can contain a list of valid parameters in form of an array. The following is a pattern which would allow the property a of the input object to be one of the numbers 1, 1.5 or 2:
{ a: { type:"number", possibleValues:[1, 1.5, 2] } }
All data types except for Objects are compared using the === operand. If the value is within the range of possible values, all other pattern attributes (such as for example min or max) still apply.
Objects are recursively compared, as the === operator does not guarantee equality if both values are objects.
Data Types can be checked using the type key in the pattern. Supported Types are as follows:
object
pattern : Allows for a recursive object check using a seperate pattern. requiredIf variables will still only reference the global object, howeverarray
pattern : Pattern that must apply to every item within the arrayminLength : Minimum amount of items in the arraymaxLength : Maximum amount of items in the arrayfixedLength : Fixed amount of items in the array (overwrites minLength and maxLength)noDuplicates : If set to true, only arrays containing no duplicate values are allowed.removeDuplicates : If set to true, the check acts similarly to noDuplicates explained above. However, instead of returning an error, the checker removes all duplicate values from the passed object.string
minLength : Minimum length of the stringmaxLength : Maximum length of the stringfixedLength : Fixed length of the string (overwrites minLength and maxLength)regex : Regular Expression the string needs to match (passed as a string)regexFlags : Flags to be used with the given regex, as single characters (Example: "gm" for global + multiline)booleandate
min : Earliest possible datemax : Latest possible dateallowTimestamp : Allows Numbers to be passed as timestampsnumber
min : Minimum valuemax : Maximum valueprecision : Maximum amount of allowed decimal placesinteger: Same attributes as number, but does not allow decimal places.// Check for a valid number larger than or equal to 10:
{
testNumber: {
required: true,
type: 'number',
min: 10
}
}
// Check for a simple Email address string:
{
email: {
required: true,
type: 'string',
regex: '.+@.+\..+'
}
}
// Use of multiple features of expressjs-check
{
mail: {
type: "object",
required: true,
pattern: {
enabled: { type: "boolean", required: true },
delay: {
type: "object",
requiredIf: "#mail.enabled",
pattern: {
days: { type: "number", required: true, min: 0 },
months: { type: "number", required: true, min: 0 }
},
},
time: { type: "string", regex: "([0-1][0-9]|2[0-3]):[0-5][0-9]" },
weekday: { type: "integer", min: 0, max: 7 }
}
}
}
FAQs
A simple data validation library.
We found that expressjs-check 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
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.