Files
TREK/server/tests/unit/middleware/globalMiddleware.csp.test.ts
T
Maurice 9ecca404c5 fix(map): drop the retired OpenStreetMap tile subdomains (#1733)
The a/b/c shards stopped being necessary in 2022 and d has since lost its
DNS record. The map never asked for d — Leaflet defaults to abc — but the
offline prefetcher rotated over a to d, which is where the failing requests
came from, and it cached most tiles under a host the map never requests.

Presets and the prefetcher use the apex host now. A URL already saved in
user_settings is rewritten where it is read and written back, so existing
instances heal without a migration touching what someone typed themselves.

The CSP only allowed https://*.tile.openstreetmap.org, and a wildcard host
never matches the apex domain, so the prefetch fetch would have been blocked.
The service worker rule had the same gap and would have stopped filling the
tile cache.
2026-07-29 15:14:21 +02:00

33 lines
1.3 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, { bodyParser: false });
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');
});
});