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.
This is the package responsible for data validations in ORM.
You can create a list of validations for several properties of an Object
and then run the checks to
see if everything is OK.
var enforce = require("enforce");
var checks = new enforce.Enforce();
checks
.add("name", enforce.notEmptyString())
.add("age", enforce.ranges.number(18, undefined, "under-age"));
checks.check({
name : "John Doe",
age : 16
}, function (err) {
// err should have an error with "msg" = "under-age"
});
You can pass some options in the constructor. One of them is returnAllErrors
which makes the validations
be all checked before returning errors. With this option, if any error is found, even if it's only one, it will be
returned in an Array
.
var enforce = require("enforce");
var checks = new enforce.Enforce({
returnAllErrors : true
});
checks
.add("name", enforce.notEmptyString())
.add("name", enforce.ranges.length(2)) // yes, you can have multiple validators per property
.add("age", enforce.ranges.number(18, undefined, "under-age"));
checks.check({
name : "J",
age : 16
}, function (err) {
console.log(err);
// [ { [Error: "out-of-range-length"], property: "name", value: "J" },
// { [Error: "under-age"], property: "age", value: 16 }]
});
All validators accept a msg
argument at the end. These argument is the error message returned if the
validation fails. All validators return a function
that is called by Enforce
with the value of the property
in question and a next
callback.
enforce.required([ msg = "required" ])
Checks if a property is not null
and not undefined
. If can be false
, 0
or ""
.
enforce.notEmptyString([ msg = "empty-string" ])
Checks if a property length is not zero. It can actually work with Array
s.
enforce.lists.inside(Array[, msg = "outside-list" ])
Checks if the property is inside a list of items (the Array
).
enforce.lists.outside(Array[, msg = "inside-list" ])
Checks if the property is not inside a list of items (the Array
).
enforce.ranges.number(min[, max[, msg = "out-of-range-number" ]])
Checks if a value is inside a specific range of numbers. Either min
or max
can be set to undefined
meaning
that range side is Infinity
.
enforce.ranges.length(min[, max[, msg = "out-of-range-length" ]])
Does the same as the above but for the length
property.
enforce.security.password([ checks = "luns6", ]msg = "weak-password")
Checks if a value has some types of characters and a minimal length. checks
has a default string which means:
l
: lowercase lettersu
: uppercase lettersn
: numberss
: special characters6
: minimal length of 6You can of course change this to "lu4" (lowercase, uppercase, minimal length of 4). Please note that if you pass only one argument
to this validator, it will assume it's the msg
argument. If you want to change the default checks, you have to pass both arguments.
Checks if property passes a specific regular expression. You can pass the pattern
as a RegExp
object (setting modifiers
as null
)
or just pass a regular expression and it will be converted.
Checks if a property matches a predefined RegExp
object accepting insensitive hexadecimal characters.
Checks if a property matches a predefined RegExp
object accepting valid e-mail addresses.
Checks if a property matches a predefined RegExp
object accepting valid IPv4 address.
FAQs
NodeJS data validations
The npm package enforce receives a total of 654 weekly downloads. As such, enforce popularity was classified as not popular.
We found that enforce demonstrated a healthy version release cadence and project activity because the last version was released less than 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.