Merge pull request #592 from BigBodyCobain/fix/583-keyless-default-basemap

fix(basemap): restore a keyless default map
This commit is contained in:
Shadowbroker authored and GitHub committed 2026-10-06 17:16:09 -06:00
commit 3bc7886e5c
8 files changed
+99 -76

No files matched your search

+2 -2
View File
@@ -27,8 +27,8 @@ AIS_API_KEY=
# Windy Webcams global CCTV layer — free key from https://api.windy.com/webcams/docs
# WINDY_API_KEY=
# CARTO basemap tiles (DEFAULT map) — free key from https://carto.com/basemaps/apikey
# Without it tiles render with an "API KEY REQUIRED" watermark.
# Optional CARTO raster-basemap override — free key from https://carto.com/basemaps/apikey
# Leave unset for the zero-config OpenFreeMap dark/light basemap.
# CARTO_API_KEY=
# Telegram OSINT map layer — scrapes public t.me/s channel previews (no bot token).
+2 -2
View File
@@ -19,7 +19,7 @@ derivative must also be offered under ODbL and must preserve attribution.
| Source | URL | What we use it for |
|---|---|---|
| adsb.lol | https://adsb.lol | Military aircraft positions, regional commercial gap-fill, route enrichment |
| OpenStreetMap contributors | https://www.openstreetmap.org/copyright | Nominatim geocoding (LOCATE bar), CARTO basemap tiles (OSM-derived) |
| OpenStreetMap contributors | https://www.openstreetmap.org/copyright | Nominatim geocoding (LOCATE bar), OpenFreeMap/CARTO basemap data (OSM-derived) |
**Attribution requirement:** the ShadowBroker map UI displays
"© OpenStreetMap contributors" and "adsb.lol (ODbL)" in the map attribution
@@ -59,7 +59,7 @@ These sources have their own terms; consult each link before redistributing.
| Meshtastic | https://meshtastic.org | Open Source | Mesh radio nodes (protocol) |
| Meshtastic Map (Liam Cottle) | https://meshtastic.liamcottle.net | Community project (per-site terms) | Global Meshtastic node positions — polled once per day with on-disk cache trust to minimize load on this volunteer-run HTTP API |
| APRS-IS | https://www.aprs-is.net | Open / attribution-based | Amateur radio positions |
| CARTO basemaps | https://carto.com | CARTO attribution required | Dark map tiles (OSM-derived) |
| OpenFreeMap / OpenMapTiles | https://openfreemap.org | OSM/OpenMapTiles attribution | Default dark/light vector basemap |\n| CARTO basemaps | https://carto.com | CARTO attribution required | Optional keyed raster basemap override |
| Esri World Imagery | https://www.arcgis.com | Esri terms | High-res satellite basemap |
| IODA (Georgia Tech) | https://ioda.inetintel.cc.gatech.edu | Research/academic terms | Internet outage data |
+3 -3
View File
@@ -354,7 +354,7 @@ Adapted from the [OSIRIS](https://github.com/simplifaisoul/osiris) recon stack (
* **Sentinel Hub Process API** — Copernicus CDSE satellite imagery with OAuth2 token flow (NEW)
* **VIIRS Nightlights** — Night-time light change detection overlay (NEW)
* **5 Visual Modes** — Toggle the entire map aesthetic via the STYLE button:
* **DEFAULT** — Dark CARTO basemap
* **DEFAULT** — Dark OpenFreeMap vector basemap (no API key required; optional CARTO override)
* **SATELLITE** — Sub-meter Esri World Imagery
* **FLIR** — Thermal imaging aesthetic (inverted greyscale)
* **NVG** — Night vision green phosphor
@@ -666,7 +666,7 @@ ShadowBroker v0.9.7 is composed of three vertically-stacked planes — the **Ope
| [Wikidata SPARQL](https://query.wikidata.org) | Head of state data | On-demand (cached 24h) | No |
| [Wikipedia API](https://en.wikipedia.org/api) | Location summaries & aircraft images | On-demand (cached) | No |
| [OSM Nominatim](https://nominatim.openstreetmap.org) | Place name geocoding (LOCATE bar) | On-demand | No |
| [CARTO Basemaps](https://carto.com) | Dark/light map tiles | Continuous | **Yes** (free, `CARTO_API_KEY`) |
| [OpenFreeMap](https://openfreemap.org) | Default dark/light vector basemap | Continuous | No |\n| [CARTO Basemaps](https://carto.com) | Optional raster basemap override | Continuous | Optional (`CARTO_API_KEY`) |
**Outbound privacy & audit (#348–#366):** Each self-hosted install uses its own backend IP and per-install User-Agent handle. See [docs/OUTBOUND_DATA.md](docs/OUTBOUND_DATA.md) for what contacts third parties, opt-in/env controls, and accepted tradeoffs (CCTV Referer, basemap CDN, LiveUAMap, etc.).
@@ -1130,7 +1130,7 @@ OPENSKY_CLIENT_SECRET=your_opensky_secret # OAuth2 — paired with Client ID
# Optional (enhances data quality)
AIS_API_KEY=your_aisstream_key # Maritime vessel tracking (aisstream.io) — ships layer empty without it
LTA_ACCOUNT_KEY=your_lta_key # Singapore CCTV cameras
CARTO_API_KEY=your_carto_key # CARTO basemap tiles — DEFAULT map shows an "API KEY REQUIRED" watermark without it (free: carto.com/basemaps/apikey)
CARTO_API_KEY=your_carto_key # Optional CARTO raster-basemap override; DEFAULT uses keyless OpenFreeMap when unset
SHODAN_API_KEY=your_shodan_key # Shodan device search overlay
SH_CLIENT_ID=your_sentinel_hub_id # Copernicus CDSE Sentinel Hub imagery
SH_CLIENT_SECRET=your_sentinel_hub_secret # Paired with Sentinel Hub Client ID
+1 -1
View File
@@ -229,7 +229,7 @@ API_REGISTRY = [
"id": "carto_api_key",
"env_key": "CARTO_API_KEY",
"name": "CARTO Basemaps",
"description": "API key for the CARTO raster basemap behind the DEFAULT dark/light map. CARTO requires one; without it tiles still load but carry an \"API KEY REQUIRED\" watermark. Free at carto.com/basemaps/apikey (no CARTO account needed, 5M tiles/month). Unlike the other keys this one is sent to the browser (GET /api/basemap-config) because the browser passes it to CARTO on every tile request.",
"description": "Optional CARTO raster-basemap override. ShadowBroker defaults to the keyless OpenFreeMap dark/light styles when this is unset. When configured, the browser receives this key from GET /api/basemap-config and sends it to CARTO on tile requests.",
"category": "Imagery",
"url": "https://carto.com/basemaps/apikey",
"required": False,
+8 -6
View File
@@ -78,13 +78,15 @@ Shadowbroker is **self-hosted**: each install uses its own backend egress IP. Th
---
## Basemap CDN (#354)
## Basemap CDN (#354, #583)
- **Code:** `frontend/src/components/map/styles/mapStyles.ts`, `frontend/public/map-style.json`
- **Hosts:** `*.basemaps.cartocdn.com`, `demotiles.maplibre.org`
- **Exposure:** **Browser** loads tiles (client IP + pan/zoom), not the backend
- **API key:** CARTO requires a key for basemap tiles. `CARTO_API_KEY` lives with the other backend keys (env or the API Keys panel) and is served to the browser by the public backend route `GET /api/basemap-config` through the normal same-origin `/api/*` path (Next.js proxy in web mode, companion server in packaged desktop). The browser then sends it to `*.basemaps.cartocdn.com` as a `?key=` query parameter on every tile request, so it is not treated as a secret. Unset it to keep the previous unkeyed behavior (watermarked tiles).
- **Mitigation:** Self-host raster tiles and point MapLibre `sources` at your tile server (operator choice; not required for core features)
- **Code:** `frontend/src/components/map/styles/mapStyles.ts`
- **Default host:** `tiles.openfreemap.org`
- **Default behavior:** OpenFreeMap Dark/Positron vector styles load without registration or an API key. OpenFreeMap's public instance is the zero-config path.
- **Optional CARTO override:** If `CARTO_API_KEY` is configured (env or API Keys panel), ShadowBroker keeps the existing CARTO raster dark/light basemap. The key is served by `GET /api/basemap-config` and sent by the browser to `*.basemaps.cartocdn.com`.
- **Exposure:** Basemap requests are made by the **browser**, so the selected provider sees browser network metadata and requested map resources.
- **Attribution:** ShadowBroker explicitly displays OpenStreetMap plus the active basemap provider attribution.
- **Self-hosting:** OpenFreeMap is open-source and supports self-hosting; operators can replace the public basemap endpoint if they need full infrastructure control.
---
@@ -5,6 +5,8 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import {
CARTO_ATTRIBUTION_HTML,
OPENFREEMAP_ATTRIBUTION_HTML,
OPENFREEMAP_STYLE_URLS,
OSM_ATTRIBUTION_HTML,
buildBasemapStyle,
cartoTileUrls,
@@ -24,57 +26,64 @@ const VIEWER_SRC = fs.readFileSync(
);
describe('buildBasemapStyle', () => {
it('produces unkeyed CARTO tile URLs when no key is given', () => {
const style = buildBasemapStyle('dark');
const source = style.sources['carto-dark'];
it('uses keyless OpenFreeMap styles when CARTO is not configured', () => {
expect(buildBasemapStyle('dark')).toBe(OPENFREEMAP_STYLE_URLS.dark);
expect(buildBasemapStyle('light')).toBe(OPENFREEMAP_STYLE_URLS.light);
expect(buildBasemapStyle('dark', ' ')).toBe(OPENFREEMAP_STYLE_URLS.dark);
});
it('keeps CARTO as the compatibility path when an operator configured a key', () => {
const style = buildBasemapStyle('light', 'my key');
expect(typeof style).toBe('object');
if (typeof style === 'string') throw new Error('expected CARTO style object');
const source = style.sources['carto-light'];
expect(source.tiles).toHaveLength(4);
for (const url of source.tiles) {
expect(url).toMatch(/^https:\/\/[abcd]\.basemaps\.cartocdn\.com\/rastertiles\/dark_all\//);
expect(url).not.toContain('?');
}
expect(style.layers[0]).toMatchObject({ id: 'carto-dark-layer', source: 'carto-dark' });
});
it('appends ?key= to every tile URL when a key is given', () => {
const style = buildBasemapStyle('light', 'my key');
for (const url of style.sources['carto-light'].tiles) {
expect(url).toMatch(/\/rastertiles\/light_all\/\{z\}\/\{x\}\/\{y\}@2x\.png\?key=my%20key$/);
}
expect(style.layers[0]).toMatchObject({ id: 'carto-light-layer', source: 'carto-light' });
});
it('treats blank keys as unconfigured', () => {
expect(cartoTileUrls('dark', ' ')).toEqual(cartoTileUrls('dark'));
expect(cartoTileUrls('dark', null)).toEqual(cartoTileUrls('dark'));
it('requires a non-empty CARTO key before building CARTO tile URLs', () => {
expect(cartoTileUrls('dark', 'my key')).toHaveLength(4);
expect(cartoTileUrls('dark', 'my key')[0]).toContain('?key=my%20key');
});
it('keeps the key-less default exports in sync with the builder', () => {
expect(darkStyle).toEqual(buildBasemapStyle('dark'));
expect(lightStyle).toEqual(buildBasemapStyle('light'));
it('keeps the keyless default exports in sync with the builder', () => {
expect(darkStyle).toBe(OPENFREEMAP_STYLE_URLS.dark);
expect(lightStyle).toBe(OPENFREEMAP_STYLE_URLS.light);
});
it('declares OpenStreetMap and CARTO attribution on the raster source, keyed or not', () => {
for (const style of [buildBasemapStyle('dark'), buildBasemapStyle('light', 'k')]) {
const source = Object.values(style.sources)[0];
expect(source.attribution).toContain('openstreetmap.org/copyright');
expect(source.attribution).toContain('carto.com/attribution');
}
it('keeps OpenStreetMap/CARTO attribution on the optional CARTO raster path', () => {
const style = buildBasemapStyle('dark', 'k');
if (typeof style === 'string') throw new Error('expected CARTO style object');
const source = Object.values(style.sources)[0];
expect(source.attribution).toContain('openstreetmap.org/copyright');
expect(source.attribution).toContain('carto.com/attribution');
});
});
describe('MaplibreViewer attribution and basemap gating', () => {
it('still renders the explicit AttributionControl with the same OSM/CARTO markup', () => {
// attributionControl={false} only disables the default control; the
// explicit child below it is the visible attribution and must survive.
it('renders OSM plus provider-specific attribution', () => {
expect(VIEWER_SRC).toContain('<AttributionControl');
expect(VIEWER_SRC).toContain(OSM_ATTRIBUTION_HTML);
expect(VIEWER_SRC).toContain(CARTO_ATTRIBUTION_HTML);
expect(VIEWER_SRC).toContain('OSM_ATTRIBUTION_HTML');
expect(VIEWER_SRC).toContain('CARTO_ATTRIBUTION_HTML');
expect(VIEWER_SRC).toContain('OPENFREEMAP_ATTRIBUTION_HTML');
expect(OSM_ATTRIBUTION_HTML).toContain('openstreetmap.org/copyright');
expect(CARTO_ATTRIBUTION_HTML).toContain('carto.com/attribution');
expect(OPENFREEMAP_ATTRIBUTION_HTML).toContain('openfreemap.org');
});
it('gates the map on the bounded basemap config, not on an open-ended request', () => {
it('gates only long enough to resolve the optional CARTO override', () => {
expect(VIEWER_SRC).toContain('{basemapConfigLoaded && (');
expect(VIEWER_SRC).toMatch(/const \{ cartoApiKey, loaded: basemapConfigLoaded \} = useBasemapConfig\(\)/);
expect(BASEMAP_CONFIG_SOFT_TIMEOUT_MS).toBeLessThan(BASEMAP_CONFIG_HARD_TIMEOUT_MS);
});
it('does not require the old CARTO-only imagery insertion anchor', () => {
expect(VIEWER_SRC).not.toContain('beforeId="imagery-ceiling"');
});
});
describe('useBasemapConfig', () => {
@@ -192,3 +201,4 @@ describe('useBasemapConfig', () => {
expect(e.result.current).toEqual({ cartoApiKey: 'second-try', loaded: true });
});
});
+12 -12
View File
@@ -15,7 +15,12 @@ import Map, {
} from 'react-map-gl/maplibre';
import 'maplibre-gl/dist/maplibre-gl.css';
import { computeNightPolygon } from '@/utils/solarTerminator';
import { buildBasemapStyle } from '@/components/map/styles/mapStyles';
import {
buildBasemapStyle,
CARTO_ATTRIBUTION_HTML,
OPENFREEMAP_ATTRIBUTION_HTML,
OSM_ATTRIBUTION_HTML,
} from '@/components/map/styles/mapStyles';
import { useBasemapConfig } from '@/hooks/useBasemapConfig';
import maplibregl from 'maplibre-gl';
import { AlertTriangle, Radio, Activity, Play, Satellite, ExternalLink, Info } from 'lucide-react';
@@ -430,9 +435,8 @@ const MaplibreViewer = ({
const [mapReady, setMapReady] = useState(false);
const { theme } = useTheme();
const { cartoApiKey, loaded: basemapConfigLoaded } = useBasemapConfig();
const mapThemeStyle = useMemo<maplibregl.StyleSpecification>(
() =>
buildBasemapStyle(theme === 'light' ? 'light' : 'dark', cartoApiKey) as maplibregl.StyleSpecification,
const mapThemeStyle = useMemo<maplibregl.StyleSpecification | string>(
() => buildBasemapStyle(theme === 'light' ? 'light' : 'dark', cartoApiKey),
[theme, cartoApiKey],
);
@@ -1901,8 +1905,8 @@ const MaplibreViewer = ({
className={`relative h-full w-full z-0 isolate ${selectedEntity && ['region_dossier', 'gdelt', 'liveuamap', 'news', 'telegram_osint', 'gt_risk'].includes(selectedEntity.type) ? 'map-focus-active' : ''}`}
style={pinPlacementMode || sarAoiDropMode ? { cursor: 'crosshair' } : undefined}
>
{/* Wait for /api/basemap-config so the first style load already carries the CARTO key.
Bounded: useBasemapConfig fails open to the unkeyed style after a short timeout. */}
{/* Resolve optional CARTO config before first paint. Without a CARTO key,
buildBasemapStyle uses the keyless OpenFreeMap style instead. */}
{basemapConfigLoaded && (
<Map
ref={mapRef}
@@ -2019,8 +2023,8 @@ const MaplibreViewer = ({
<AttributionControl
compact
customAttribution={[
'<a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noopener">© OpenStreetMap contributors</a>',
'<a href="https://carto.com/attribution" target="_blank" rel="noopener">CARTO</a>',
OSM_ATTRIBUTION_HTML,
cartoApiKey ? CARTO_ATTRIBUTION_HTML : OPENFREEMAP_ATTRIBUTION_HTML,
'<a href="https://adsb.lol" target="_blank" rel="noopener">adsb.lol (ODbL)</a>',
'<a href="https://opensky-network.org" target="_blank" rel="noopener">OpenSky</a>',
'<a href="https://celestrak.org" target="_blank" rel="noopener">CelesTrak</a>',
@@ -2045,7 +2049,6 @@ const MaplibreViewer = ({
<Layer
id="esri-world-imagery-layer"
type="raster"
beforeId="imagery-ceiling"
paint={{
'raster-opacity': 1,
'raster-fade-duration': 300,
@@ -2069,7 +2072,6 @@ const MaplibreViewer = ({
<Layer
id="gibs-modis-layer"
type="raster"
beforeId="imagery-ceiling"
paint={{
'raster-opacity': gibsOpacity ?? 0.6,
'raster-fade-duration': 0,
@@ -2093,7 +2095,6 @@ const MaplibreViewer = ({
<Layer
id="viirs-nightlights-layer"
type="raster"
beforeId="imagery-ceiling"
paint={{
'raster-opacity': 0.9,
'raster-fade-duration': 0,
@@ -2117,7 +2118,6 @@ const MaplibreViewer = ({
<Layer
id="sentinel-hub-layer"
type="raster"
beforeId="imagery-ceiling"
paint={{
'raster-opacity': sentinelOpacity ?? 0.6,
'raster-fade-duration': 0,
+31 -20
View File
@@ -1,54 +1,65 @@
import type { StyleSpecification } from 'maplibre-gl';
/**
* MapLibre basemap styles on CARTO raster tiles. CARTO requires an API key
* (unkeyed tiles are watermarked); MaplibreViewer passes one from
* useBasemapConfig() via buildBasemapStyle(). The key is served by the
* backend at GET /api/basemap-config.
* ShadowBroker's zero-config basemap uses OpenFreeMap vector styles.
* Operators who configure CARTO_API_KEY keep the existing CARTO raster
* basemap path. This avoids CARTO's unkeyed "API KEY REQUIRED" watermark
* without taking the configured provider away from existing installs.
*/
export type BasemapTheme = 'dark' | 'light';
export const OPENFREEMAP_STYLE_URLS: Record<BasemapTheme, string> = {
dark: 'https://tiles.openfreemap.org/styles/dark',
light: 'https://tiles.openfreemap.org/styles/positron',
};
const CARTO_SUBDOMAINS = ['a', 'b', 'c', 'd'] as const;
const CARTO_RASTER_STYLE: Record<BasemapTheme, string> = {
dark: 'dark_all',
light: 'light_all',
};
const GLYPHS_URL = 'https://demotiles.maplibre.org/font/{fontstack}/{range}.pbf';
// Declared on the raster source so MapLibre's AttributionControl shows it
// even without the custom list in MaplibreViewer. Same markup as that list so
// the control de-duplicates instead of showing both.
export const OSM_ATTRIBUTION_HTML =
'<a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noopener">© OpenStreetMap contributors</a>';
export const CARTO_ATTRIBUTION_HTML =
'<a href="https://carto.com/attribution" target="_blank" rel="noopener">CARTO</a>';
export const OPENFREEMAP_ATTRIBUTION_HTML =
'<a href="https://openfreemap.org" target="_blank" rel="noopener">OpenFreeMap</a> · <a href="https://openmaptiles.org" target="_blank" rel="noopener">OpenMapTiles</a>';
/** Tile URL templates for a CARTO raster style, keyed when a key is supplied. */
export function cartoTileUrls(theme: BasemapTheme, cartoApiKey?: string | null): string[] {
/** Tile URL templates for the optional CARTO raster style. */
export function cartoTileUrls(theme: BasemapTheme, cartoApiKey: string): string[] {
const style = CARTO_RASTER_STYLE[theme];
const key = (cartoApiKey || '').trim();
const query = key ? `?key=${encodeURIComponent(key)}` : '';
const key = cartoApiKey.trim();
return CARTO_SUBDOMAINS.map(
(s) => `https://${s}.basemaps.cartocdn.com/rastertiles/${style}/{z}/{x}/{y}@2x.png${query}`,
(s) =>
`https://${s}.basemaps.cartocdn.com/rastertiles/${style}/{z}/{x}/{y}@2x.png?key=${encodeURIComponent(key)}`,
);
}
export function buildBasemapStyle(theme: BasemapTheme, cartoApiKey?: string | null) {
/**
* Use OpenFreeMap by default. CARTO is retained as an opt-in compatibility
* path when an operator has already configured CARTO_API_KEY.
*/
export function buildBasemapStyle(
theme: BasemapTheme,
cartoApiKey?: string | null,
): string | StyleSpecification {
const key = (cartoApiKey || '').trim();
if (!key) return OPENFREEMAP_STYLE_URLS[theme];
const sourceId = `carto-${theme}`;
return {
version: 8,
glyphs: GLYPHS_URL,
sources: {
[sourceId]: {
type: 'raster',
tiles: cartoTileUrls(theme, cartoApiKey),
tiles: cartoTileUrls(theme, key),
tileSize: 256,
attribution: `${OSM_ATTRIBUTION_HTML} ${CARTO_ATTRIBUTION_HTML}`,
},
},
layers: [
{ id: `${sourceId}-layer`, type: 'raster', source: sourceId, minzoom: 0, maxzoom: 22 },
{ id: 'imagery-ceiling', type: 'background', paint: { 'background-opacity': 0 } },
],
layers: [{ id: `${sourceId}-layer`, type: 'raster', source: sourceId, minzoom: 0, maxzoom: 22 }],
};
}