mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 17:41:51 +00:00
Pin the request body ceiling instead of inheriting it
The Express shell set a 100kb limit and stopped applying it the moment the
Nest instance took over parsing: bootstrap passed bodyParser:false and
nothing replaced it. The number happened to stay the same, because it is also
the framework default - but it lived nowhere anybody would look for it, and
one NestFactory default away from silently becoming something else.
It goes through Nest's own parser rather than a second express.json(),
because that parser carries the verify hook that keeps req.rawBody, and the
plugin webhook routes need the exact payload bytes to check a provider's
HMAC. Adding a parser in front of it would have taken rawBody away without
failing anything.
MISC-009 and MISC-010 pin it from both sides.
The bodyParser flag on applyGlobalMiddleware goes with it: one caller, which
passed false.
Not moved: cookieParser stays on the raw Express layer rather than becoming a
configure(consumer) middleware. The platform routes - the OAuth consent flow
among them - are registered on that instance before Nest routing exists, so a
Nest-slot cookie parser would simply not run for them. helmet, CORS,
compression, the forced-HTTPS 301 and the res.on('finish') logging stay for
the same reason: they have to see requests Nest never routes.
This commit is contained in:
@@ -15,18 +15,19 @@ import { logDebug, logWarn, logError } from '../nest/audit/audit-log.logger';
|
||||
* behaviourally transparent — and is the prerequisite for retiring Express,
|
||||
* since the Nest instance must carry the whole shell on its own.
|
||||
*
|
||||
* `bodyParser` is opt-out: the Nest instance does its own body parsing, so it
|
||||
* passes `false` to avoid parsing the request twice.
|
||||
* Body parsing is NOT here: the Nest instance does it, with the limit pinned in
|
||||
* bootstrap.ts. The flag that used to switch a second parser on had exactly one
|
||||
* caller, which passed false.
|
||||
*/
|
||||
export function applyGlobalMiddleware(
|
||||
app: express.Application,
|
||||
opts: { bodyParser?: boolean; http?: AppEnv['http'] } = {},
|
||||
opts: { http?: AppEnv['http'] } = {},
|
||||
): void {
|
||||
// The whole pipeline is configured at APPLY time (the per-request closures
|
||||
// capture these values), so a snapshot is the correct semantic. bootstrap
|
||||
// threads in the DI-loaded httpConfig; direct callers fall back to an
|
||||
// apply-time readEnv() — same values, same freeze point.
|
||||
const { bodyParser = true, http = readEnv().http } = opts;
|
||||
const { http = readEnv().http } = opts;
|
||||
const { nodeEnv, isProduction } = readEnv().app;
|
||||
|
||||
// Trust first proxy (nginx/Docker) for correct req.ip
|
||||
@@ -169,10 +170,6 @@ export function applyGlobalMiddleware(
|
||||
});
|
||||
}
|
||||
|
||||
if (bodyParser) {
|
||||
app.use(express.json({ limit: '100kb' }));
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
}
|
||||
app.use(cookieParser());
|
||||
|
||||
// Request logging with sensitive field redaction
|
||||
|
||||
Reference in New Issue
Block a user