The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.
TypeScript budget-trackercollaborativedockeritinerarymcp-serveroffline-firstopen-sourceopenstreetmappacking-listpwareal-timeself-hostedselfhostedtraveltravel-apptravel-journaltravel-plannertripitwanderlog
Pin the request body ceiling instead of inheriting it
Mauricee5c99903ea17
diff --git a/server/src/bootstrap.ts b/server/src/bootstrap.tsindex de81836c1..ebe7dd49e 100644--- a/server/src/bootstrap.ts+++ b/server/src/bootstrap.ts@@ -1,5 +1,5 @@import { NestFactory } from '@nestjs/core';-import { ExpressAdapter } from '@nestjs/platform-express';+import { ExpressAdapter, type NestExpressApplication } from '@nestjs/platform-express';import type { INestApplication } from '@nestjs/common';import type { ConfigType } from '@nestjs/config';import { AppModule } from './nest/app.module';@@ -54,10 +54,20 @@ export async function buildApp(): Promise<INestApplication> {// the one bridge that lets the pre-init Express layer consume the validated// config instead of reading process.env itself.const http = app.get<ConfigType<typeof httpConfig>>(httpConfig.KEY);- applyGlobalMiddleware(instance, { bodyParser: false, http });+ applyGlobalMiddleware(instance, { http });applyPlatformUploads(instance);applyPlatformTransport(instance);applyPlatformStatic(instance);+ // Pin the request-body ceiling explicitly. The Express shell used to set+ // '100kb' and stopped doing it when the Nest instance took over parsing, which+ // left the limit implicit — the same number, but nowhere anybody would find+ // it, and one NestFactory default away from silently becoming something else.+ // Configured through Nest rather than a second express.json(): its parser+ // carries the verify hook that keeps req.rawBody, which the plugin webhook+ // routes need to check a provider's HMAC over the exact payload.+ const express = app as unknown as NestExpressApplication;+ express.useBodyParser('json', { limit: '100kb' });+ express.useBodyParser('urlencoded', { limit: '100kb', extended: true });if (apiDocsEnabled()) setupApiDocs(app);await app.init();// The /mcp handler is mounted pre-init (step 3) and has no DI access — handdiff --git a/server/src/middleware/globalMiddleware.ts b/server/src/middleware/globalMiddleware.tsindex 0555dec3e..e5ee7611e 100644--- a/server/src/middleware/globalMiddleware.ts+++ b/server/src/middleware/globalMiddleware.ts@@ -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 redactiondiff --git a/server/tests/integration/misc.test.ts b/server/tests/integration/misc.test.tsindex 7966c2d8c..65898bc1f 100644--- a/server/tests/integration/misc.test.ts+++ b/server/tests/integration/misc.test.ts@@ -145,3 +145,24 @@ describe('Force HTTPS redirect', () => {});});++describe('Request body ceiling', () => {+ // The Express shell set '100kb' and stopped when the Nest instance took over+ // parsing, which left the limit implicit. This pins it, so it cannot drift+ // back to a framework default without somebody noticing.+ it('MISC-009 — a body over 100kb is refused with 413', async () => {+ const res = await request(app)+ .post('/api/auth/login')+ .set('Content-Type', 'application/json')+ .send({ email: '[email protected]', password: 'x'.repeat(200 * 1024) });+ expect(res.status).toBe(413);+ });++ it('MISC-010 — a body under it still reaches the handler', async () => {+ const res = await request(app)+ .post('/api/auth/login')+ .set('Content-Type', 'application/json')+ .send({ email: '[email protected]', password: 'x'.repeat(1024) });+ expect(res.status).not.toBe(413);+ });+});diff --git a/server/tests/unit/middleware/globalMiddleware.csp.test.ts b/server/tests/unit/middleware/globalMiddleware.csp.test.tsindex effaa754c..07b179b59 100644--- a/server/tests/unit/middleware/globalMiddleware.csp.test.ts+++ b/server/tests/unit/middleware/globalMiddleware.csp.test.ts@@ -5,7 +5,7 @@ import { applyGlobalMiddleware } from '../../../src/middleware/globalMiddleware'async function connectSrcSources(): Promise<string[]> {const app = express();- applyGlobalMiddleware(app, { bodyParser: false });+ applyGlobalMiddleware(app);app.get('/probe', (_req, res) => res.json({ ok: true }));const res = await request(app).get('/probe');