Skip to content

armgit / TREK

Public Imported from GitHub
0

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.

fix(maps): let the imagery through the CSP, so the GL switch does something

Maurice2f71549413f9
diff --git a/server/src/middleware/globalMiddleware.ts b/server/src/middleware/globalMiddleware.ts
index 06665600f..eeb805f59 100644
--- a/server/src/middleware/globalMiddleware.ts
+++ b/server/src/middleware/globalMiddleware.ts
@@ -235,6 +235,13 @@ export function applyGlobalMiddleware(
// 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",
+ // 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",
"https://unpkg.com", "https://open-meteo.com", "https://api.open-meteo.com",
"https://geocoding-api.open-meteo.com", "https://api.frankfurter.dev",
"https://router.project-osrm.org/route/v1/", "https://routing.openstreetmap.de/",
diff --git a/server/tests/unit/middleware/globalMiddleware.csp.test.ts b/server/tests/unit/middleware/globalMiddleware.csp.test.ts
index 8b768d0bf..ea1e14dea 100644
--- a/server/tests/unit/middleware/globalMiddleware.csp.test.ts
+++ b/server/tests/unit/middleware/globalMiddleware.csp.test.ts
@@ -52,6 +52,25 @@ describe('global CSP: the other shipped raster presets (#2180)', () => {
});
});
+describe('global CSP: the imagery host (#2307)', () => {
+ it('allows server.arcgisonline.com, which a GL map reaches through fetch', async () => {
+ // The gap hid behind Leaflet for as long as Leaflet was the only renderer to
+ // show the imagery: it loads a tile as an <img>, and img-src allows `https:`
+ // outright. A GL map reads the raster through fetch to hand it to WebGL, so
+ // it lands on connect-src instead and was refused with nothing to see for it.
+ expect(await connectSrcSources()).toContain('https://server.arcgisonline.com');
+ });
+
+ it('names the apex host, because img-src is what used to carry it', async () => {
+ // img-src keeps its blanket `https:`, which is why Leaflet never noticed. The
+ // fix belongs on connect-src alone; widening img-src further would buy nothing
+ // and widening connect-src to a wildcard would not match the apex anyway.
+ const sources = await connectSrcSources();
+ expect(sources).not.toContain('https://*.arcgisonline.com');
+ expect(await directiveSources('img-src')).toContain('https:');
+ });
+});
+
describe('global CSP: script-src', () => {
it("allows 'wasm-unsafe-eval' so the WASM decoders keep running", async () => {
expect(await directiveSources('script-src')).toContain("'wasm-unsafe-eval'");