
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
@betsys-nestjs/headers
Advanced tools
This library is responsible for enforcing mandatory headers in the request.
@betsys-nestjs/headers
This is a simple library helps you to enforce mandatory headers in requests. Also you can provide custom validators and
conditional headers.
Works for Express
adapter.
Package | Version |
---|---|
@nestjs/common | ^10.0.0 |
@nestjs/core | ^10.0.0 |
class-validator | ^0.13.2 |
When building the module of the application you need to
initialize the library using forRoot
method that accepts PlatformType
as an argument.
PlatformType
can be 'express'
.
import {HeadersModule} from "@betsys-nestjs/headers";
@Module({
imports: [
HeadersModule.forRoot('express'),
],
controllers: [
Test1Controller,
Test2Controller,
],
})
export class AppModule {
}
As soon as you initialize module using forRoot
method, you can use forFeature
method to
create a ruleset for headers. This config under the hood dynamically configures NestJS middleware
. Method accepts 4
parameters:
This config is defined this way:
interface HeadersConfig {
requiredHeaders: Array<HeaderWithValidation>;
forRoutes: Array<string | Type | RouteInfo>;
exclude?: Array<string | RouteInfo>;
conditionalHeaders?: ConditionalHeadersConfig[];
}
requiredHeaders
- You can define headers, that are required, it is an array with this interface:interface HeaderWithValidation {
headerName: string;
validator: Type<unknown>;
}
where:
headerName
is name of a header (key) and validator
is Dto class that uses decorators from class-validator
to
validate given header
forRoutes
(optional) - You can define array of routes using explicit string, regular expressions, Controller
references
or RouteInfo
object that is defined this way:If forRoutes
is not added, middleware is set globally.
interface RouteInfo {
path: string;
method: RequestMethod;
version?: VersionValue;
}
exclude
(optional) - You can define array with routes that should be excluded using either string or RouteInfo
conditionalHeaders
(optional) - This way you can require array of any headers dependent on other headers based on
custom
condition. This interface is defined like this:interface ConditionalHeadersConfig {
ifHeader: string;
matchesCondition: (headerValue: string) => boolean;
thenRequireHeaders: Array<HeaderWithValidation>;
}
where:
ifHeader
- define header name that needs to fulfil condition in matchesCondition
.matchesCondition
- condition for the header value defined in ifHeader
.thenRequireHeaders
- here you define headers that are further required when matchesCondition
returns true
.import {HeadersModule} from "@betsys-nestjs/headers";
@Module({
imports: [
HeadersModule.forFeature(
{
requiredHeaders: [
{headerName: 'A', validator: AHeaderDto},
{
headerName: 'B',
validator: BHeaderDto,
},
],
forRoutes: ['*'],
exclude: [TEST_2_PREFIX],
conditionalHeaders: [
{
ifHeader: 'C',
matchesCondition: (headerValue: string) => headerValue === 'MNAU',
thenRequireHeaders: [{headerName: 'D', validator: DHeaderDto}],
},
],
}
),
],
controllers: [
Test1Controller,
Test2Controller,
],
})
export class FeatureModule {
}
You can set the headers globally (i.e. you do not add forRoutes
) or
for particular controllers as shown in the example above.
FAQs
This library is responsible for enforcing mandatory headers in the request.
The npm package @betsys-nestjs/headers receives a total of 2 weekly downloads. As such, @betsys-nestjs/headers popularity was classified as not popular.
We found that @betsys-nestjs/headers demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 9 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.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.