feat(maps): one shared list of the shipped tile hosts for the CSP and the client

A GL map fetches its style and its tiles, so it can only draw from a host
the server's connect-src names. The raster presets and OpenFreeMap were
written out in the middleware while the client kept its own idea of them,
and nothing held the two together.

The hosts, their reasons and the default OpenFreeMap style now live in
shared/src/maps/map-defaults.ts. The middleware builds those sources from
the list, and the client takes the default style from it, so the renderer
choice the next steps add reads the same hosts the policy allows.

The policy an install sends stays byte for byte the same: a test pins the
whole connect-src in its order.
This commit is contained in:
Maurice
2026-11-30 14:33:05 +01:00
parent b27b3f6563
commit d8a93af2f5
6 changed files with 150 additions and 51 deletions
+6 -50
View File
@@ -11,6 +11,7 @@ import {
} from '../nest/common/request-correlation';
import { isSameHostOrigin } from '../nest/common/same-origin';
import type { ConfigType } from '@nestjs/config';
import { OPENFREEMAP_HOST, RASTER_TILE_HOSTS } from '@trek/shared';
import compression from 'compression';
import cookieParser from 'cookie-parser';
@@ -298,55 +299,10 @@ export function applyGlobalMiddleware(
'https://api.openweathermap.org',
'https://en.wikipedia.org',
'https://commons.wikimedia.org',
// Both forms here too: CARTO documents the apex host on its key page,
// so that is the template users paste in, and the {s} sharded form is
// what TREK ships (#2054).
'https://basemaps.cartocdn.com',
'https://*.basemaps.cartocdn.com',
// Both forms: a CSP wildcard host never matches the apex, and OSM
// serves everything from the bare tile.openstreetmap.org since it
// retired the a/b/c/d shards (#1733). The sharded hosts stay listed
// for tile templates users saved before that.
'https://tile.openstreetmap.org',
'https://*.tile.openstreetmap.org',
// The other two raster presets TREK ships. `mode: 'no-cors'` relaxes
// CORS, not CSP, so without these the tile prefetch is refused in the
// document and never reaches the Service Worker that would cache it
// (#2180). routing.openstreetmap.de below is a different host.
'https://tile.openstreetmap.de',
'https://tiles.stadiamaps.com',
// OpenTopoMap is the key-free raster layer offered only by the Tours
// planner. Leaflet uses its a/b/c shards; the apex is named too so a
// future unsharded template does not repeat the OSM CSP gap above.
'https://tile.opentopomap.org',
'https://*.tile.opentopomap.org',
// The imagery host, for the same reason and one more. Leaflet fetches a tile
// as an <img>, which img-src's blanket `https:` waves through, so the satellite
// view worked on Leaflet with this host missing. A GL map reads the raster
// through fetch to hand it to WebGL, and the prefetch does too, so both were
// refused here while nothing in the app could see it: the switch flipped, the
// layer went on, and no tile ever arrived (#2307).
'https://server.arcgisonline.com',
// OpenSeaMap's transparent seamark layer, offered only to a paddle tour in the
// Tours planner (PAD-10). Leaflet loads it as an <img>; the GL map reads it
// through fetch and needs it here.
'https://tiles.openseamap.org',
// OpenSnowMap's transparent piste layer (SKI-01), offered in the Tours planner with
// no tour open and for a ski tour; the GL map reads it through fetch.
'https://tiles.opensnowmap.org',
// OpenHikingMap, the hiking base map of the Tours planner (MAP-01), loaded only
// while a user shows it and the admin allows it; GL reads it through fetch.
'https://tile.openmaps.fr',
// CyclOSM, the cycling base map of a bike tour in the Tours planner (BIK-06), on the
// same terms; its three shards are named, so no wildcard opens the whole domain.
'https://a.tile-cyclosm.openstreetmap.fr',
'https://b.tile-cyclosm.openstreetmap.fr',
'https://c.tile-cyclosm.openstreetmap.fr',
// Amap's raster tiles, for an install whose users are in China, for the
// same reason as the hosts above (#2180). Road (webrd01..04) and
// satellite (webst01..04) are numbered shards of one domain, so the
// wildcard is the whole list.
'https://*.is.autonavi.com',
// The raster tile hosts TREK ships, from the list the client reads too, so the
// policy and the renderer choice agree (shared/src/maps/map-defaults.ts says
// why each one is there).
...RASTER_TILE_HOSTS.map((host) => `https://${host}`),
'https://unpkg.com',
'https://open-meteo.com',
'https://api.open-meteo.com',
@@ -363,7 +319,7 @@ export function applyGlobalMiddleware(
'https://api.mapbox.com',
'https://*.tiles.mapbox.com',
'https://events.mapbox.com',
'https://tiles.openfreemap.org',
`https://${OPENFREEMAP_HOST}`,
// A self-hosted routing engine, when the instance has one configured. Without
// this the browser blocks it silently: no error the app can catch, just legs
// that never route (#1797).