@lenne.tech/nest-server 12.6.12 → 12.6.13
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/.claude/rules/package-management.md +7 -7
- package/.claude/rules/role-system.md +10 -0
- package/.claude/rules/testing.md +4 -4
- package/FRAMEWORK-API.md +1 -1
- package/dist/core/common/decorators/rest-user.decorator.js +4 -0
- package/dist/core/common/decorators/rest-user.decorator.js.map +1 -1
- package/dist/core/common/filters/http-exception-log.filter.js +4 -0
- package/dist/core/common/filters/http-exception-log.filter.js.map +1 -1
- package/dist/core/common/helpers/context.helper.js +9 -0
- package/dist/core/common/helpers/context.helper.js.map +1 -1
- package/dist/core/common/helpers/decorator.helper.js +4 -0
- package/dist/core/common/helpers/decorator.helper.js.map +1 -1
- package/dist/core/common/helpers/execution-context-request.helper.d.ts +9 -1
- package/dist/core/common/helpers/execution-context-request.helper.js +29 -0
- package/dist/core/common/helpers/execution-context-request.helper.js.map +1 -1
- package/dist/core/common/helpers/graphql-upload.helper.d.ts +10 -0
- package/dist/core/common/helpers/graphql-upload.helper.js +220 -0
- package/dist/core/common/helpers/graphql-upload.helper.js.map +1 -0
- package/dist/core/common/interceptors/translate-response.interceptor.js +4 -0
- package/dist/core/common/interceptors/translate-response.interceptor.js.map +1 -1
- package/dist/core/modules/auth/guards/auth.guard.js +10 -2
- package/dist/core/modules/auth/guards/auth.guard.js.map +1 -1
- package/dist/core/modules/auth/guards/legacy-auth-rate-limit.guard.js +4 -1
- package/dist/core/modules/auth/guards/legacy-auth-rate-limit.guard.js.map +1 -1
- package/dist/core/modules/auth/guards/roles.guard.js +11 -1
- package/dist/core/modules/auth/guards/roles.guard.js.map +1 -1
- package/dist/core/modules/better-auth/better-auth-roles.guard.js +15 -1
- package/dist/core/modules/better-auth/better-auth-roles.guard.js.map +1 -1
- package/dist/core/modules/tenant/core-tenant.guard.js +9 -1
- package/dist/core/modules/tenant/core-tenant.guard.js.map +1 -1
- package/dist/core.module.js +2 -1
- package/dist/core.module.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/types/graphql-upload.d.ts +34 -2
- package/docs/REQUEST-LIFECYCLE.md +30 -8
- package/docs/security-overrides.md +3 -2
- package/migration-guides/12.6.12-to-12.6.13.md +162 -0
- package/package.json +10 -3
- package/src/core/common/decorators/rest-user.decorator.ts +6 -0
- package/src/core/common/filters/http-exception-log.filter.ts +9 -0
- package/src/core/common/helpers/context.helper.ts +14 -0
- package/src/core/common/helpers/decorator.helper.ts +5 -0
- package/src/core/common/helpers/execution-context-request.helper.ts +78 -1
- package/src/core/common/helpers/graphql-upload.helper.ts +482 -0
- package/src/core/common/interceptors/translate-response.interceptor.ts +8 -0
- package/src/core/modules/auth/guards/auth.guard.ts +19 -2
- package/src/core/modules/auth/guards/legacy-auth-rate-limit.guard.ts +9 -2
- package/src/core/modules/auth/guards/roles.guard.ts +23 -1
- package/src/core/modules/better-auth/better-auth-roles.guard.ts +29 -1
- package/src/core/modules/tenant/core-tenant.guard.ts +13 -1
- package/src/core.module.ts +5 -1
- package/src/index.ts +1 -0
- package/src/types/graphql-upload.d.ts +34 -2
|
@@ -17,7 +17,7 @@ import { firstValueFrom, isObservable } from 'rxjs';
|
|
|
17
17
|
|
|
18
18
|
import { RoleEnum } from '../../common/enums/role.enum.js';
|
|
19
19
|
import { ROLE_GUARD } from '../auth/guards/role-guard.token.js';
|
|
20
|
-
import { resolveGuardRequest } from '../../common/helpers/execution-context-request.helper.js';
|
|
20
|
+
import { isAgentCallContext, resolveGuardRequest } from '../../common/helpers/execution-context-request.helper.js';
|
|
21
21
|
import {
|
|
22
22
|
revalidateAllWsConnections,
|
|
23
23
|
revalidateWsConnectionsForTenant,
|
|
@@ -431,6 +431,18 @@ export class CoreTenantGuard implements CanActivate, OnApplicationBootstrap, OnM
|
|
|
431
431
|
|
|
432
432
|
const request = this.getRequest(context);
|
|
433
433
|
if (!request) {
|
|
434
|
+
// An agent function / MCP call without a request is anonymous (nestjs-ai plan §1). "No request" is never
|
|
435
|
+
// permission there: only a public method runs, every other one is refused like an unauthenticated request.
|
|
436
|
+
if (isAgentCallContext(context)) {
|
|
437
|
+
const rolesMetadata = this.reflector.getAll<string[][]>('roles', [context.getHandler(), context.getClass()]);
|
|
438
|
+
const roles = mergeRolesMetadata(rolesMetadata);
|
|
439
|
+
// The method's own roles win over the class's (as `systemCheckRoles` below): a class-level S_EVERYONE does
|
|
440
|
+
// not open a method that asks for S_USER or a tenant role
|
|
441
|
+
const effective = rolesMetadata?.[0]?.some((role) => !!role) ? rolesMetadata[0] : roles;
|
|
442
|
+
if (effective?.some((role) => !!role) && !effective.includes(RoleEnum.S_EVERYONE)) {
|
|
443
|
+
throw new UnauthorizedException(ErrorCode.UNAUTHORIZED);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
434
446
|
return true;
|
|
435
447
|
}
|
|
436
448
|
|
package/src/core.module.ts
CHANGED
|
@@ -15,6 +15,7 @@ import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.mjs';
|
|
|
15
15
|
|
|
16
16
|
import { MongooseCastErrorFilter } from './core/common/filters/mongoose-cast-error.filter.js';
|
|
17
17
|
import { merge } from './core/common/helpers/config.helper.js';
|
|
18
|
+
import { processGraphQlUploadRequest } from './core/common/helpers/graphql-upload.helper.js';
|
|
18
19
|
import { refuseWsHandshake, registerWsConnection } from './core/common/helpers/graphql-ws-connection.helper.js';
|
|
19
20
|
import {
|
|
20
21
|
buildRequestContextAwareExecute,
|
|
@@ -122,7 +123,10 @@ export class CoreModule implements NestModule {
|
|
|
122
123
|
// config read here and the values there.
|
|
123
124
|
consumer.apply(SecurityHeadersMiddleware).forRoutes('*');
|
|
124
125
|
if (CoreModule.graphQlEnabled) {
|
|
125
|
-
|
|
126
|
+
// The framework's processRequest, never graphql-upload's default: the default (graphql-upload < 18.0.2) lets
|
|
127
|
+
// one anonymous multipart request crash the process (GHSA-5vm7-vc2x-p3w2) and leaks temporary files on
|
|
128
|
+
// duplicate file fields (GHSA-qwwm-252j-9whw). This middleware runs before any authentication.
|
|
129
|
+
consumer.apply(graphqlUploadExpress({ processRequest: processGraphQlUploadRequest })).forRoutes('graphql');
|
|
126
130
|
}
|
|
127
131
|
}
|
|
128
132
|
|
package/src/index.ts
CHANGED
|
@@ -44,6 +44,7 @@ export * from './core/common/helpers/execution-context-request.helper.js';
|
|
|
44
44
|
export * from './core/common/helpers/file.helper.js';
|
|
45
45
|
export * from './core/common/helpers/filter.helper.js';
|
|
46
46
|
export * from './core/common/helpers/graphql.helper.js';
|
|
47
|
+
export * from './core/common/helpers/graphql-upload.helper.js';
|
|
47
48
|
export * from './core/common/helpers/graphql-ws-connection.helper.js';
|
|
48
49
|
export * from './core/common/helpers/graphql-ws-context.helper.js';
|
|
49
50
|
export * from './core/common/helpers/idle-stream.helper.js';
|
|
@@ -4,21 +4,53 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Since graphql-upload 16 the package is ESM: its `exports` map lists only the `.mjs` deep paths, each
|
|
6
6
|
* with a default export, and it ships no declaration files (its types are JSDoc inside the `.mjs`
|
|
7
|
-
* sources, which TypeScript does not read from `node_modules`).
|
|
7
|
+
* sources, which TypeScript does not read from `node_modules`). The names below are the ones the
|
|
8
8
|
* framework imports.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
declare module 'graphql-upload/graphqlUploadExpress.mjs' {
|
|
12
12
|
import { RequestHandler } from 'express';
|
|
13
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
13
14
|
|
|
14
|
-
interface
|
|
15
|
+
interface GraphQLUploadProcessRequestOptions {
|
|
16
|
+
maxFieldSize?: number;
|
|
15
17
|
maxFiles?: number;
|
|
16
18
|
maxFileSize?: number;
|
|
17
19
|
}
|
|
18
20
|
|
|
21
|
+
interface GraphQLUploadOptions extends GraphQLUploadProcessRequestOptions {
|
|
22
|
+
/**
|
|
23
|
+
* The function that parses the multipart request. graphql-upload's default is its own `processRequest`, which is
|
|
24
|
+
* vulnerable to GHSA-5vm7-vc2x-p3w2 and GHSA-qwwm-252j-9whw below 18.0.2 — pass the framework's
|
|
25
|
+
* `processGraphQlUploadRequest`.
|
|
26
|
+
*/
|
|
27
|
+
processRequest?: (
|
|
28
|
+
request: IncomingMessage,
|
|
29
|
+
response: ServerResponse,
|
|
30
|
+
options?: GraphQLUploadProcessRequestOptions,
|
|
31
|
+
) => Promise<unknown>;
|
|
32
|
+
}
|
|
33
|
+
|
|
19
34
|
export default function graphqlUploadExpress(options?: GraphQLUploadOptions): RequestHandler;
|
|
20
35
|
}
|
|
21
36
|
|
|
37
|
+
declare module 'graphql-upload/Upload.mjs' {
|
|
38
|
+
/**
|
|
39
|
+
* A file expected in a GraphQL multipart request, placed in the operations wherever the `map` names it. The
|
|
40
|
+
* `GraphQLUpload` scalar accepts a value only if it is `instanceof` this class, of the same graphql-upload copy.
|
|
41
|
+
*/
|
|
42
|
+
export default class Upload {
|
|
43
|
+
/** The file's details once it streamed in (set by `resolve`). */
|
|
44
|
+
file?: unknown;
|
|
45
|
+
/** Resolves with the file's details; the scalar hands it to the resolver. */
|
|
46
|
+
promise: Promise<unknown>;
|
|
47
|
+
/** Rejects the upload (missing file, aborted request). */
|
|
48
|
+
reject: (error: Error) => void;
|
|
49
|
+
/** Resolves the upload with the file's details. */
|
|
50
|
+
resolve: (file: unknown) => void;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
22
54
|
declare module 'graphql-upload/GraphQLUpload.mjs' {
|
|
23
55
|
import { GraphQLScalarType } from 'graphql';
|
|
24
56
|
|