Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Gavel tells you whether an actual HTTP message is valid against an expected HTTP message.
npm install gavel
# (Optional) Record HTTP messages
curl -s --trace - http://httpbin.org/ip | curl-trace-parser > expected
curl -s --trace - http://httpbin.org/ip | curl-trace-parser > actual
# Perform the validation
cat actual | gavel expected
Gavel CLI is not supported on Windows. Example above uses
curl-trace-parser
.
const gavel = require('gavel');
// Define HTTP messages
const expected = {
statusCode: 200,
headers: {
'Content-Type': 'application/json'
}
};
const actual = {
statusCode: 404,
headers: {
'Content-Type': 'application/json'
}
};
// Perform the validation
const result = gavel.validate(expected, actual);
The code above would return the following validation result
:
{
valid: false,
fields: {
statusCode: {
valid: false,
kind: 'text',
values: {
expected: '200',
actual: '404'
},
errors: [
{
message: `Expected status code '200', but got '404'.`
}
]
},
headers: {
valid: true,
kind: 'json',
values: {
expected: {
'Content-Type': 'application/json'
},
actual: {
'Content-Type': 'application/json'
}
},
errors: []
}
}
}
When a parsable JSON body is expected without an explicit schema the default schema is inferred.
You can describe the body expectations using JSON Schema by providing a valid schema to the bodySchema
property of the expected HTTP message:
const gavel = require('gavel');
const expected = {
bodySchema: {
type: 'object',
properties: {
fruits: {
type: 'array',
items: {
type: 'string'
}
}
}
}
};
const actual = {
body: JSON.stringify({
fruits: ['apple', 'banana', 2]
})
};
const result = gavel.validate(expected, actual);
The validation result
against the given JSON Schema will look as follows:
{
valid: false,
fields: {
body: {
valid: false,
kind: 'json',
values: {
actual: "{\"fruits\":[\"apple\",\"banana\",2]}"
},
errors: [
{
message: `At '/fruits/2' Invalid type: number (expected string)`,
location: {
pointer: '/fruits/2'
}
}
]
}
}
}
Take a look at the Gherkin specification, which describes on examples how validation of each field behaves:
Gavel ships with TypeScript type definitions. Please refer to the definitions file for more details.
validate(expected: HttpMessage, actual: HttpMessage): ValidationResult
FAQs
Validator of HTTP transactions (JavaScript implementation)
The npm package gavel receives a total of 0 weekly downloads. As such, gavel popularity was classified as not popular.
We found that gavel 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
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.