Files
TREK/server/tests/unit/middleware/globalMiddleware.csp.test.ts
T
Maurice e5c99903ea 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.
2026-08-10 13:38:26 +02:00

33 lines
1.2 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import express from 'express';
import request from 'supertest';
import { applyGlobalMiddleware } from '../../../src/middleware/globalMiddleware';
async function connectSrcSources(): Promise<string[]> {
const app = express();
applyGlobalMiddleware(app);
app.get('/probe', (_req, res) => res.json({ ok: true }));
const res = await request(app).get('/probe');
const csp = String(res.headers['content-security-policy'] || '');
const directive = csp
.split(';')
.map(d => d.trim())
.find(d => d.startsWith('connect-src'));
return directive ? directive.split(/\s+/).slice(1) : [];
}
describe('global CSP: OpenStreetMap tile hosts (#1733)', () => {
it('allows the bare tile.openstreetmap.org host', async () => {
// A CSP wildcard host never matches the apex, so `*.tile.openstreetmap.org`
// alone would block the tile prefetcher's fetch() against the single host
// OSM has served from since it retired a/b/c/d sharding.
expect(await connectSrcSources()).toContain('https://tile.openstreetmap.org');
});
it('still allows the sharded hosts for templates saved earlier', async () => {
expect(await connectSrcSources()).toContain('https://*.tile.openstreetmap.org');
});
});