@nestjs/common 11.2.5 → 11.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/interfaces/http/cookie-options.interface.d.ts +79 -0
- package/interfaces/http/cookie-options.interface.js +1 -0
- package/interfaces/http/csrf-protection-options.interface.d.ts +47 -0
- package/interfaces/http/csrf-protection-options.interface.js +1 -0
- package/interfaces/http/security-headers-options.interface.d.ts +142 -0
- package/interfaces/http/security-headers-options.interface.js +1 -0
- package/internal.d.ts +1 -1
- package/package.json +2 -2
- package/pipes/standard-schema-validation.pipe.js +1 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attributes of a `Set-Cookie` header written by `HttpServer.setCookie()` and
|
|
3
|
+
* `HttpServer.clearCookie()`.
|
|
4
|
+
*
|
|
5
|
+
* @see [RFC 6265, section 4.1](https://datatracker.ietf.org/doc/html/rfc6265#section-4.1)
|
|
6
|
+
*
|
|
7
|
+
* @publicApi
|
|
8
|
+
*/
|
|
9
|
+
export interface CookieSerializeOptions {
|
|
10
|
+
/**
|
|
11
|
+
* `Path` attribute.
|
|
12
|
+
*
|
|
13
|
+
* @default '/'
|
|
14
|
+
*/
|
|
15
|
+
path?: string;
|
|
16
|
+
/**
|
|
17
|
+
* `Domain` attribute. Omitted by default, which makes the cookie host-only.
|
|
18
|
+
*/
|
|
19
|
+
domain?: string;
|
|
20
|
+
/**
|
|
21
|
+
* `Max-Age` attribute, in **seconds**, as in RFC 6265 and `@fastify/cookie`.
|
|
22
|
+
* Must be an integer.
|
|
23
|
+
*
|
|
24
|
+
* **Not milliseconds**: Express' `res.cookie()` takes `maxAge` in
|
|
25
|
+
* milliseconds, so a value carried over from it would make the cookie live
|
|
26
|
+
* 1000 times longer. For one day, pass `60 * 60 * 24`.
|
|
27
|
+
*/
|
|
28
|
+
maxAge?: number;
|
|
29
|
+
/**
|
|
30
|
+
* `Expires` attribute. Browsers give precedence to `maxAge` when both are
|
|
31
|
+
* set.
|
|
32
|
+
*/
|
|
33
|
+
expires?: Date;
|
|
34
|
+
/**
|
|
35
|
+
* `HttpOnly` attribute.
|
|
36
|
+
*/
|
|
37
|
+
httpOnly?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* `Secure` attribute.
|
|
40
|
+
*/
|
|
41
|
+
secure?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* `SameSite` attribute. `'none'` requires `secure: true`, since browsers
|
|
44
|
+
* reject `SameSite=None` cookies that are not `Secure`.
|
|
45
|
+
*/
|
|
46
|
+
sameSite?: 'strict' | 'lax' | 'none';
|
|
47
|
+
/**
|
|
48
|
+
* `Partitioned` attribute (CHIPS). Requires `secure: true`, since browsers
|
|
49
|
+
* reject partitioned cookies that are not `Secure`.
|
|
50
|
+
*/
|
|
51
|
+
partitioned?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* `Priority` attribute (non-standard, honored by Chromium).
|
|
54
|
+
*/
|
|
55
|
+
priority?: 'low' | 'medium' | 'high';
|
|
56
|
+
/**
|
|
57
|
+
* Whether to sign the value with the first secret configured through the
|
|
58
|
+
* `cookies.secret` application option. Signed cookies are read with the
|
|
59
|
+
* `@SignedCookies()` decorator.
|
|
60
|
+
*
|
|
61
|
+
* @default false
|
|
62
|
+
*/
|
|
63
|
+
signed?: boolean;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The `cookies` option of `NestFactory.create()`.
|
|
67
|
+
*
|
|
68
|
+
* @publicApi
|
|
69
|
+
*/
|
|
70
|
+
export interface CookiesOptions {
|
|
71
|
+
/**
|
|
72
|
+
* Secret (or secrets) used to sign and verify cookies. When an array is
|
|
73
|
+
* given, cookies are signed with the first secret and verified against all
|
|
74
|
+
* of them, which allows rotating secrets without invalidating cookies
|
|
75
|
+
* signed with a previous one. An empty string, an empty array or an empty
|
|
76
|
+
* entry throws when the application is created.
|
|
77
|
+
*/
|
|
78
|
+
secret?: string | string[];
|
|
79
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { RouteInfo } from '../middleware/middleware-configuration.interface.js';
|
|
2
|
+
/**
|
|
3
|
+
* Options for `app.enableCsrfProtection()`.
|
|
4
|
+
*
|
|
5
|
+
* The protection is based on Fetch Metadata (`Sec-Fetch-Site`) with an
|
|
6
|
+
* `Origin`/`Host` fallback, following the algorithm of Go's
|
|
7
|
+
* `net/http.CrossOriginProtection`. It is not a token scheme: it relies on the
|
|
8
|
+
* browser telling the server where a request comes from, which every
|
|
9
|
+
* evergreen browser does since 2023.
|
|
10
|
+
*
|
|
11
|
+
* Browsers only send `Sec-Fetch-Site` to secure origins (HTTPS or
|
|
12
|
+
* `localhost`). Otherwise the `Origin` header is compared with the `Host`
|
|
13
|
+
* header the server receives (`X-Forwarded-Host` is ignored). Behind a proxy
|
|
14
|
+
* that rewrites `Host`, preserve it, or list the public origin in
|
|
15
|
+
* `trustedOrigins`.
|
|
16
|
+
*
|
|
17
|
+
* @publicApi
|
|
18
|
+
*/
|
|
19
|
+
export interface CsrfProtectionOptions<TRequest = any> {
|
|
20
|
+
/**
|
|
21
|
+
* Origins that may send cross-origin, state-changing requests, e.g.
|
|
22
|
+
* `https://admin.example.com`. Each entry must be a serialized origin:
|
|
23
|
+
* `scheme://host[:port]`, without a path, query string, fragment or
|
|
24
|
+
* wildcard. Entries are normalized the way browsers serialize `Origin`
|
|
25
|
+
* (lower-case, without the default port), and a request is exempt when its
|
|
26
|
+
* `Origin` header equals one of them.
|
|
27
|
+
*
|
|
28
|
+
* Origins allowed by CORS are not trusted implicitly: list them here too.
|
|
29
|
+
*/
|
|
30
|
+
trustedOrigins?: string[];
|
|
31
|
+
/**
|
|
32
|
+
* Requests that skip the protection altogether (for example webhook
|
|
33
|
+
* endpoints called by third-party servers that send a foreign `Origin`).
|
|
34
|
+
*
|
|
35
|
+
* Either a list of routes, or a predicate receiving the platform request
|
|
36
|
+
* object. Only consulted for requests that would otherwise be rejected.
|
|
37
|
+
*
|
|
38
|
+
* Routes are declared like `MiddlewareConsumer.exclude()`: a path, or
|
|
39
|
+
* `{ path, method, version? }` to narrow by method (and URI version),
|
|
40
|
+
* without the global prefix, which is added unless the route is excluded
|
|
41
|
+
* from it. Unlike `exclude()`, the match is exact: case-sensitive, without
|
|
42
|
+
* an optional trailing slash, and never for non-canonical request paths
|
|
43
|
+
* (`//`, dot segments, `;`, encoded `/` or `.`), which a router could
|
|
44
|
+
* resolve to a route that is not excluded.
|
|
45
|
+
*/
|
|
46
|
+
exclude?: (string | RouteInfo)[] | ((request: TRequest) => boolean);
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Value of a Content-Security-Policy directive:
|
|
3
|
+
*
|
|
4
|
+
* - a string or a list of strings: the directive's source expressions
|
|
5
|
+
* (keywords must be quoted, e.g. `"'self'"`);
|
|
6
|
+
* - `true` or an empty list: a directive without value (e.g.
|
|
7
|
+
* `upgrade-insecure-requests`);
|
|
8
|
+
* - `null` or `false`: removes the directive, including a default one.
|
|
9
|
+
*
|
|
10
|
+
* @publicApi
|
|
11
|
+
*/
|
|
12
|
+
export type ContentSecurityPolicyDirectiveValue = string | readonly string[] | boolean | null;
|
|
13
|
+
/**
|
|
14
|
+
* @publicApi
|
|
15
|
+
*/
|
|
16
|
+
export interface ContentSecurityPolicyOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Whether `directives` are merged into the default directives. When
|
|
19
|
+
* `false`, only `directives` are sent, and they must include `default-src`
|
|
20
|
+
* (or remove it explicitly with `defaultSrc: null`).
|
|
21
|
+
*
|
|
22
|
+
* @default true
|
|
23
|
+
*/
|
|
24
|
+
useDefaults?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Directives keyed by name, in camelCase (`scriptSrc`) or kebab-case
|
|
27
|
+
* (`'script-src'`). A directive given here replaces the default directive
|
|
28
|
+
* of the same name.
|
|
29
|
+
*/
|
|
30
|
+
directives?: Record<string, ContentSecurityPolicyDirectiveValue>;
|
|
31
|
+
/**
|
|
32
|
+
* Sends `Content-Security-Policy-Report-Only` instead, so violations are
|
|
33
|
+
* reported (see the `report-to` directive) but not blocked.
|
|
34
|
+
*
|
|
35
|
+
* @default false
|
|
36
|
+
*/
|
|
37
|
+
reportOnly?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Options for `app.useSecurityHeaders()`.
|
|
41
|
+
*
|
|
42
|
+
* Each key controls one header and accepts `false` to leave that header out,
|
|
43
|
+
* `true` for its default value (the same defaults as helmet 8), or an object
|
|
44
|
+
* to configure it. Option names match helmet's, so existing helmet
|
|
45
|
+
* configurations carry over, except for helmet's legacy aliases (`hsts`,
|
|
46
|
+
* `frameguard`, ...). Unknown options are rejected.
|
|
47
|
+
*
|
|
48
|
+
* @publicApi
|
|
49
|
+
*/
|
|
50
|
+
export interface SecurityHeadersOptions {
|
|
51
|
+
/**
|
|
52
|
+
* `Content-Security-Policy`. Default: `default-src 'self'; base-uri 'self';
|
|
53
|
+
* font-src 'self' https: data:; form-action 'self'; frame-ancestors 'self';
|
|
54
|
+
* img-src 'self' data:; object-src 'none'; script-src 'self';
|
|
55
|
+
* script-src-attr 'none'; style-src 'self' https: 'unsafe-inline';
|
|
56
|
+
* upgrade-insecure-requests` (serialized without spaces after `;`).
|
|
57
|
+
*/
|
|
58
|
+
contentSecurityPolicy?: boolean | ContentSecurityPolicyOptions;
|
|
59
|
+
/**
|
|
60
|
+
* `Cross-Origin-Embedder-Policy`. Not sent by default; `true` sends
|
|
61
|
+
* `require-corp`.
|
|
62
|
+
*/
|
|
63
|
+
crossOriginEmbedderPolicy?: boolean | {
|
|
64
|
+
policy?: 'require-corp' | 'credentialless' | 'unsafe-none';
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* `Cross-Origin-Opener-Policy`. Default: `same-origin`.
|
|
68
|
+
*/
|
|
69
|
+
crossOriginOpenerPolicy?: boolean | {
|
|
70
|
+
policy?: 'same-origin' | 'same-origin-allow-popups' | 'noopener-allow-popups' | 'unsafe-none';
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* `Cross-Origin-Resource-Policy`. Default: `same-origin`.
|
|
74
|
+
*/
|
|
75
|
+
crossOriginResourcePolicy?: boolean | {
|
|
76
|
+
policy?: 'same-origin' | 'same-site' | 'cross-origin';
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* `Origin-Agent-Cluster: ?1`.
|
|
80
|
+
*/
|
|
81
|
+
originAgentCluster?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* `Referrer-Policy`. Default: `no-referrer`. A list is sent as a fallback
|
|
84
|
+
* chain (the browser uses the last one it supports).
|
|
85
|
+
*/
|
|
86
|
+
referrerPolicy?: boolean | {
|
|
87
|
+
policy?: ReferrerPolicyToken | readonly ReferrerPolicyToken[];
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* `Strict-Transport-Security`. Default: `max-age=31536000;
|
|
91
|
+
* includeSubDomains`. Browsers ignore it over plain HTTP.
|
|
92
|
+
*/
|
|
93
|
+
strictTransportSecurity?: boolean | {
|
|
94
|
+
/** In seconds. @default 31536000 (365 days) */
|
|
95
|
+
maxAge?: number;
|
|
96
|
+
/** @default true */
|
|
97
|
+
includeSubDomains?: boolean;
|
|
98
|
+
/** @default false */
|
|
99
|
+
preload?: boolean;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* `X-Content-Type-Options: nosniff`.
|
|
103
|
+
*/
|
|
104
|
+
xContentTypeOptions?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* `X-DNS-Prefetch-Control`. Default: `off`; `{ allow: true }` sends `on`.
|
|
107
|
+
*/
|
|
108
|
+
xDnsPrefetchControl?: boolean | {
|
|
109
|
+
allow?: boolean;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* `X-Download-Options: noopen`.
|
|
113
|
+
*/
|
|
114
|
+
xDownloadOptions?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* `X-Frame-Options`. Default: `SAMEORIGIN`. Superseded by the CSP
|
|
117
|
+
* `frame-ancestors` directive, kept for older browsers.
|
|
118
|
+
*/
|
|
119
|
+
xFrameOptions?: boolean | {
|
|
120
|
+
action?: 'deny' | 'sameorigin';
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* `X-Permitted-Cross-Domain-Policies`. Default: `none`.
|
|
124
|
+
*/
|
|
125
|
+
xPermittedCrossDomainPolicies?: boolean | {
|
|
126
|
+
permittedPolicies?: 'none' | 'master-only' | 'by-content-type' | 'all';
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Removes the `X-Powered-By` header (on Express, also disables the
|
|
130
|
+
* `x-powered-by` setting). `false` leaves it untouched.
|
|
131
|
+
*/
|
|
132
|
+
xPoweredBy?: boolean;
|
|
133
|
+
/**
|
|
134
|
+
* `X-XSS-Protection: 0`, which disables the legacy XSS auditor of old
|
|
135
|
+
* browsers (a source of vulnerabilities itself).
|
|
136
|
+
*/
|
|
137
|
+
xXssProtection?: boolean;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* @publicApi
|
|
141
|
+
*/
|
|
142
|
+
export type ReferrerPolicyToken = '' | 'no-referrer' | 'no-referrer-when-downgrade' | 'same-origin' | 'origin' | 'strict-origin' | 'origin-when-cross-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/internal.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export type { MiddlewareConfiguration, RouteInfo, } from './interfaces/middlewar
|
|
|
25
25
|
export type { MiddlewareConfigProxy } from './interfaces/middleware/middleware-config-proxy.interface.js';
|
|
26
26
|
export type { ModuleMetadata } from './interfaces/modules/module-metadata.interface.js';
|
|
27
27
|
export type { HttpArgumentsHost, RpcArgumentsHost, WsArgumentsHost, } from './interfaces/features/arguments-host.interface.js';
|
|
28
|
-
export type { RequestHandler } from './interfaces/http/http-server.interface.js';
|
|
28
|
+
export type { RequestHandler, SecurityRequestHook, } from './interfaces/http/http-server.interface.js';
|
|
29
29
|
export type { GetOrResolveOptions, SelectOptions, } from './interfaces/nest-application-context.interface.js';
|
|
30
30
|
export type { ShutdownHooksOptions } from './interfaces/shutdown-hooks-options.interface.js';
|
|
31
31
|
export { assignMetadata } from './decorators/http/route-params.decorator.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/common",
|
|
3
|
-
"version": "11.2.
|
|
3
|
+
"version": "11.2.6",
|
|
4
4
|
"description": "Nest - modern, fast, powerful node.js web framework (@common)",
|
|
5
5
|
"author": "Kamil Mysliwiec",
|
|
6
6
|
"homepage": "https://nestjs.com",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"optional": true
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "c07cfb0be5e95ffa129da39ccc49a23cb64d49ff"
|
|
42
42
|
}
|
|
@@ -61,7 +61,7 @@ let StandardSchemaValidationPipe = class StandardSchemaValidationPipe {
|
|
|
61
61
|
if (!schema || !this.toValidate(metadata)) {
|
|
62
62
|
return value;
|
|
63
63
|
}
|
|
64
|
-
stripProtoKeys(value);
|
|
64
|
+
this.stripProtoKeys(value);
|
|
65
65
|
const result = await this.validate(value, schema, this.validateOptions);
|
|
66
66
|
if (result.issues) {
|
|
67
67
|
throw this.exceptionFactory(result.issues);
|