Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): bundle the fonts instead of loading Google Fonts

Yudhi Armyndharisb88d0c70c754
diff --git a/dashboard/package-lock.json b/dashboard/package-lock.json
index 888f16b71..1171bd59e 100644
--- a/dashboard/package-lock.json
+++ b/dashboard/package-lock.json
@@ -8,6 +8,10 @@
"name": "dashboard",
"version": "0.10.2",
"dependencies": {
+ "@fontsource-variable/heebo": "^5.3.0",
+ "@fontsource-variable/jetbrains-mono": "^5.3.0",
+ "@fontsource-variable/noto-sans-arabic": "^5.3.0",
+ "@fontsource-variable/plus-jakarta-sans": "^5.3.0",
"@tanstack/react-query": "^5.103.1",
"@tanstack/react-table": "^9.2.4",
"i18next": "^26.4.2",
@@ -668,6 +672,42 @@
}
}
},
+ "node_modules/@fontsource-variable/heebo": {
+ "version": "5.3.0",
+ "resolved": "https://registry.npmjs.org/@fontsource-variable/heebo/-/heebo-5.3.0.tgz",
+ "integrity": "sha512-gaCKIbnx83+Za844O2dn4XYoAitS2jjBSj08bELHfCIL5gKMBDWl82oWte2CEBrnXwNMVJNd3ojZqFOd9+mCFg==",
+ "license": "OFL-1.1",
+ "funding": {
+ "url": "https://github.com/sponsors/ayuhito"
+ }
+ },
+ "node_modules/@fontsource-variable/jetbrains-mono": {
+ "version": "5.3.0",
+ "resolved": "https://registry.npmjs.org/@fontsource-variable/jetbrains-mono/-/jetbrains-mono-5.3.0.tgz",
+ "integrity": "sha512-F32xpS2NsGYoQi2ADSkKTgpJj7ozajsGgDJ8woTnqjmIB+dxDIqImjl4pXZVEExu8UFZ2ndhmX18EBS/hdz3Lw==",
+ "license": "OFL-1.1",
+ "funding": {
+ "url": "https://github.com/sponsors/ayuhito"
+ }
+ },
+ "node_modules/@fontsource-variable/noto-sans-arabic": {
+ "version": "5.3.0",
+ "resolved": "https://registry.npmjs.org/@fontsource-variable/noto-sans-arabic/-/noto-sans-arabic-5.3.0.tgz",
+ "integrity": "sha512-Rz8+DBzza3//cmN+DBQajJhx3x+Dx12eUgnQsTOgPWbOT0+In6APmE8z4I/QQnUWfAx+s8l93+60qDT5vJH1sA==",
+ "license": "OFL-1.1",
+ "funding": {
+ "url": "https://github.com/sponsors/ayuhito"
+ }
+ },
+ "node_modules/@fontsource-variable/plus-jakarta-sans": {
+ "version": "5.3.0",
+ "resolved": "https://registry.npmjs.org/@fontsource-variable/plus-jakarta-sans/-/plus-jakarta-sans-5.3.0.tgz",
+ "integrity": "sha512-/l/4r0yyWK9JzAlmA0LiYgGgmJe/Gswt4jTJEzr5QhJfwMbvJZDmYWyW0M4X7yCK69BajMVlV/Lx8g7WDc1+sw==",
+ "license": "OFL-1.1",
+ "funding": {
+ "url": "https://github.com/sponsors/ayuhito"
+ }
+ },
"node_modules/@humanfs/core": {
"version": "0.19.1",
"resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.1.tgz",
diff --git a/dashboard/package.json b/dashboard/package.json
index 7537e06ee..d4cbf14d4 100644
--- a/dashboard/package.json
+++ b/dashboard/package.json
@@ -17,6 +17,10 @@
"test:cov": "node --experimental-strip-types --test --test-timeout=120000 --experimental-test-coverage --test-coverage-exclude=\"src/**/*.test.ts\" --test-coverage-exclude=\"src/test-helpers/**\" \"src/**/*.test.ts\""
},
"dependencies": {
+ "@fontsource-variable/heebo": "^5.3.0",
+ "@fontsource-variable/jetbrains-mono": "^5.3.0",
+ "@fontsource-variable/noto-sans-arabic": "^5.3.0",
+ "@fontsource-variable/plus-jakarta-sans": "^5.3.0",
"@tanstack/react-query": "^5.103.1",
"@tanstack/react-table": "^9.2.4",
"i18next": "^26.4.2",
diff --git a/dashboard/src/App.css b/dashboard/src/App.css
index 78d6dc509..2b7209fe7 100644
--- a/dashboard/src/App.css
+++ b/dashboard/src/App.css
@@ -1,5 +1,3 @@
-@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:ital,wght@0,200..800;1,200..800&family=JetBrains+Mono:ital,wght@0,100..800;1,100..800&display=swap');
-
:root {
--primary: #25d366;
/* The brand green as FOREGROUND is 1.98:1 on white, far under the 4.5:1 AA needs for text.
@@ -104,6 +102,7 @@
body {
margin: 0;
font-family:
+ 'Plus Jakarta Sans Variable',
'Plus Jakarta Sans',
-apple-system,
BlinkMacSystemFont,
diff --git a/dashboard/src/components/FilterBuilder.css b/dashboard/src/components/FilterBuilder.css
index 86486d569..0300f66fc 100644
--- a/dashboard/src/components/FilterBuilder.css
+++ b/dashboard/src/components/FilterBuilder.css
@@ -278,7 +278,7 @@
.chips-suggestion-id {
font-size: 0.6875rem;
color: var(--text-secondary);
- font-family: 'JetBrains Mono', monospace;
+ font-family: 'JetBrains Mono Variable', 'JetBrains Mono', monospace;
}
.chips-suggestion-add {
diff --git a/dashboard/src/fonts-local.test.ts b/dashboard/src/fonts-local.test.ts
new file mode 100644
index 000000000..6541acc5b
--- /dev/null
+++ b/dashboard/src/fonts-local.test.ts
@@ -0,0 +1,53 @@
+import { test } from 'node:test';
+import assert from 'node:assert/strict';
+import { readFileSync, readdirSync } from 'node:fs';
+import { fileURLToPath } from 'node:url';
+import { dirname, join } from 'node:path';
+
+// The dashboard bundles its fonts and the gateway CSP allows fonts and styles only from 'self', so a
+// remote stylesheet or a family name the bundled packages do not register falls back to a system font.
+
+const SRC = dirname(fileURLToPath(import.meta.url));
+const cssFiles = (readdirSync(SRC, { recursive: true }) as string[]).filter(f => f.endsWith('.css'));
+
+test('no stylesheet loads a remote font or stylesheet', () => {
+ for (const file of cssFiles) {
+ const css = readFileSync(join(SRC, file), 'utf8');
+ assert.doesNotMatch(css, /fonts\.googleapis|fonts\.gstatic|@import\s+url\(\s*['"]?https?:/, file);
+ }
+});
+
+test('every bundled family is named by the name its package registers', () => {
+ for (const family of ['Plus Jakarta Sans', 'JetBrains Mono', 'Heebo', 'Noto Sans Arabic']) {
+ for (const file of cssFiles) {
+ const css = readFileSync(join(SRC, file), 'utf8');
+ const plain = css.split(`'${family}'`).length - 1;
+ const variable = css.split(`'${family} Variable'`).length - 1;
+ assert.equal(plain, variable, `${file}: '${family}' without '${family} Variable' before it`);
+ }
+ }
+});
+
+test('the entry point imports every bundled font', () => {
+ const main = readFileSync(join(SRC, 'main.tsx'), 'utf8');
+ for (const spec of [
+ '@fontsource-variable/plus-jakarta-sans',
+ '@fontsource-variable/plus-jakarta-sans/wght-italic.css',
+ '@fontsource-variable/jetbrains-mono',
+ '@fontsource-variable/heebo',
+ '@fontsource-variable/noto-sans-arabic',
+ ]) {
+ assert.ok(main.includes(`import '${spec}';`), `main.tsx does not import ${spec}`);
+ }
+});
+
+test('the build never inlines a font as a data: URI', async () => {
+ const { default: config } = (await import('../vite.config.ts')) as {
+ default: { build?: { assetsInlineLimit?: unknown } };
+ };
+ const limit = config.build?.assetsInlineLimit;
+ assert.equal(typeof limit, 'function');
+ const inline = limit as (file: string, content: Buffer) => boolean | undefined;
+ assert.equal(inline('/x/plus-jakarta-sans-cyrillic-ext-wght-normal.woff2', Buffer.alloc(1_700)), false);
+ assert.equal(inline('/x/icon.svg', Buffer.alloc(100)), undefined);
+});
diff --git a/dashboard/src/index.css b/dashboard/src/index.css
index c7b877c2d..1ca75a642 100644
--- a/dashboard/src/index.css
+++ b/dashboard/src/index.css
@@ -1,19 +1,16 @@
-@import url('https://fonts.googleapis.com/css2?family=Heebo:wght@400;500;600;700&display=swap');
-@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Arabic:wght@400;500;600;700&display=swap');
-
:root {
- font-family: 'Plus Jakarta Sans', system-ui, Avenir, Helvetica, Arial, sans-serif;
+ font-family: 'Plus Jakarta Sans Variable', 'Plus Jakarta Sans', system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.6;
font-weight: 400;
}
html[lang='he'],
html[dir='rtl'] {
- font-family: 'Heebo', 'Rubik', 'Noto Sans Hebrew', 'Segoe UI', Arial, sans-serif;
+ font-family: 'Heebo Variable', 'Heebo', 'Rubik', 'Noto Sans Hebrew', 'Segoe UI', Arial, sans-serif;
}
html[lang='ar'] {
- font-family: 'Noto Sans Arabic', 'Cairo', 'Tajawal', 'Segoe UI', Arial, sans-serif;
+ font-family: 'Noto Sans Arabic Variable', 'Noto Sans Arabic', 'Cairo', 'Tajawal', 'Segoe UI', Arial, sans-serif;
}
:root {
diff --git a/dashboard/src/main.tsx b/dashboard/src/main.tsx
index 90b7def3c..8840516e5 100644
--- a/dashboard/src/main.tsx
+++ b/dashboard/src/main.tsx
@@ -1,6 +1,11 @@
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import { i18nReady } from './i18n';
+import '@fontsource-variable/plus-jakarta-sans';
+import '@fontsource-variable/plus-jakarta-sans/wght-italic.css';
+import '@fontsource-variable/jetbrains-mono';
+import '@fontsource-variable/heebo';
+import '@fontsource-variable/noto-sans-arabic';
import './index.css';
import App from './App.tsx';
diff --git a/dashboard/src/pages/Dashboard.css b/dashboard/src/pages/Dashboard.css
index 24398612c..5090e8f1e 100644
--- a/dashboard/src/pages/Dashboard.css
+++ b/dashboard/src/pages/Dashboard.css
@@ -191,7 +191,7 @@
}
.dashboard .session-id {
- font-family: 'JetBrains Mono', monospace;
+ font-family: 'JetBrains Mono Variable', 'JetBrains Mono', monospace;
font-size: 0.8125rem;
color: var(--text-primary);
white-space: nowrap;
diff --git a/dashboard/src/pages/MessageTester.css b/dashboard/src/pages/MessageTester.css
index 14583b77b..13d50d576 100644
--- a/dashboard/src/pages/MessageTester.css
+++ b/dashboard/src/pages/MessageTester.css
@@ -199,7 +199,7 @@
margin: 0;
color: #e2e8f0;
font-size: 0.8125rem;
- font-family: 'JetBrains Mono', monospace;
+ font-family: 'JetBrains Mono Variable', 'JetBrains Mono', monospace;
white-space: pre-wrap;
}
diff --git a/dashboard/src/pages/Sessions.css b/dashboard/src/pages/Sessions.css
index 1725497b2..7b433c7c7 100644
--- a/dashboard/src/pages/Sessions.css
+++ b/dashboard/src/pages/Sessions.css
@@ -406,7 +406,7 @@
background: var(--bg-light);
padding: 0.125rem 0.375rem;
border-radius: 4px;
- font-family: 'JetBrains Mono', monospace;
+ font-family: 'JetBrains Mono Variable', 'JetBrains Mono', monospace;
font-size: 0.7rem;
}
@@ -550,7 +550,7 @@
}
.sessions-page .detail-value.mono {
- font-family: 'JetBrains Mono', monospace;
+ font-family: 'JetBrains Mono Variable', 'JetBrains Mono', monospace;
font-size: 0.8125rem;
background: var(--bg-light);
padding: 0.5rem;
@@ -797,7 +797,7 @@
padding: 1rem 2rem;
border-radius: 12px;
letter-spacing: 0.1em;
- font-family: 'JetBrains Mono', monospace;
+ font-family: 'JetBrains Mono Variable', 'JetBrains Mono', monospace;
margin: 1.5rem 0;
}
diff --git a/dashboard/src/pages/Templates.css b/dashboard/src/pages/Templates.css
index d1c077532..17f5341d3 100644
--- a/dashboard/src/pages/Templates.css
+++ b/dashboard/src/pages/Templates.css
@@ -192,7 +192,7 @@
.templates-page .template-list-meta {
overflow: hidden;
color: var(--text-muted);
- font-family: 'JetBrains Mono', ui-monospace, monospace;
+ font-family: 'JetBrains Mono Variable', 'JetBrains Mono', ui-monospace, monospace;
font-size: 0.6875rem;
text-overflow: ellipsis;
white-space: nowrap;
@@ -318,7 +318,7 @@
border-radius: 8px;
background: var(--bg-white);
color: var(--text-primary);
- font-family: 'JetBrains Mono', ui-monospace, monospace;
+ font-family: 'JetBrains Mono Variable', 'JetBrains Mono', ui-monospace, monospace;
font-size: 0.875rem;
line-height: 1.6;
white-space: pre-wrap;
@@ -345,7 +345,7 @@
.templates-page .placeholder-list label > span {
color: var(--primary-text);
- font-family: 'JetBrains Mono', ui-monospace, monospace;
+ font-family: 'JetBrains Mono Variable', 'JetBrains Mono', ui-monospace, monospace;
}
.templates-page .template-muted {
diff --git a/dashboard/src/pages/Webhooks.css b/dashboard/src/pages/Webhooks.css
index 3a364d8e0..8d47d2bbc 100644
--- a/dashboard/src/pages/Webhooks.css
+++ b/dashboard/src/pages/Webhooks.css
@@ -146,7 +146,7 @@
text-overflow: ellipsis;
white-space: nowrap;
min-width: 0;
- font-family: 'JetBrains Mono', monospace;
+ font-family: 'JetBrains Mono Variable', 'JetBrains Mono', monospace;
}
.webhooks-page .webhook-card-actions {
@@ -237,7 +237,7 @@
white-space: nowrap;
border: 1px solid rgba(37, 211, 102, 0.25);
cursor: default;
- font-family: 'JetBrains Mono', monospace;
+ font-family: 'JetBrains Mono Variable', 'JetBrains Mono', monospace;
letter-spacing: -0.01em;
}
diff --git a/dashboard/vite.config.ts b/dashboard/vite.config.ts
index 2fe11ca6b..cce84dd10 100644
--- a/dashboard/vite.config.ts
+++ b/dashboard/vite.config.ts
@@ -20,6 +20,8 @@ const { version: pkgVersion } = JSON.parse(
export default defineConfig({
plugins: [react()],
appType: 'spa', // Enable SPA fallback for client-side routing
+ // Fonts stay files: a small subset inlined as a data: URI is blocked by the gateway CSP (font-src 'self').
+ build: { assetsInlineLimit: file => (file.endsWith('.woff2') ? false : undefined) },
define: {
__APP_VERSION__: JSON.stringify(process.env.APP_VERSION || pkgVersion),
__BUILD_TIME__: JSON.stringify(new Date().toISOString()),
diff --git a/docs/04-security-design.md b/docs/04-security-design.md
index 0079f3568..6389ad64c 100644
--- a/docs/04-security-design.md
+++ b/docs/04-security-design.md
@@ -431,15 +431,15 @@ app.use(helmet({
contentSecurityPolicy: {
directives: {
defaultSrc: ["'self'"],
- // The bundled dashboard pulls webfonts from Google Fonts.
- styleSrc: ["'self'", "'unsafe-inline'", 'https://fonts.googleapis.com'],
+ // The dashboard bundles its fonts; Bull Board's Google Fonts link is blocked (system-font fallback).
+ styleSrc: ["'self'", "'unsafe-inline'"],
// Per-response nonce; the served dashboard document carries the same value.
scriptSrc: ["'self'", (_req, res) => `'nonce-${res.locals.cspNonce}'`],
// blob: for the outgoing attachment preview, data: for chat media rendered inline.
imgSrc: ["'self'", 'data:', 'blob:', 'https:'],
mediaSrc: ["'self'", 'data:', 'blob:', 'https:'],
connectSrc: ["'self'"],
- fontSrc: ["'self'", 'https://fonts.gstatic.com'],
+ fontSrc: ["'self'"],
objectSrc: ["'none'"],
// On in production, unless CSP_UPGRADE_INSECURE_REQUESTS opts an HTTP-only
// private-network deployment out (#611).
diff --git a/src/configure-app.ts b/src/configure-app.ts
index dc362f41b..17dfd93bc 100644
--- a/src/configure-app.ts
+++ b/src/configure-app.ts
@@ -138,10 +138,10 @@ export function configureApp(app: INestApplication, options: ConfigureAppOptions
contentSecurityPolicy: {
directives: {
defaultSrc: ["'self'"],
- // The bundled dashboard pulls webfonts from Google Fonts (CSS from fonts.googleapis.com,
- // font files from fonts.gstatic.com). Now that NestJS serves the dashboard under this CSP,
- // allow those origins or the @import'd fonts are blocked and the UI falls back to system fonts.
- styleSrc: ["'self'", "'unsafe-inline'", 'https://fonts.googleapis.com'],
+ // The dashboard bundles its fonts, so no third-party style or font origin is allowed. The Bull Board
+ // UI (/api/admin/queues) links IBM Plex from Google Fonts; that stylesheet is blocked and it falls
+ // back to system fonts.
+ styleSrc: ["'self'", "'unsafe-inline'"],
scriptSrc: ["'self'", (_req, res) => `'nonce-${(res as Response).locals.cspNonce as string}'`],
// `blob:` is needed for the outgoing image-attachment preview, which the dashboard renders
// from a URL.createObjectURL(file) blob before the message is sent (Chats.tsx).
@@ -151,7 +151,7 @@ export function configureApp(app: INestApplication, options: ConfigureAppOptions
// Mirror imgSrc so audio/video render the same way images already do.
mediaSrc: ["'self'", 'data:', 'blob:', 'https:'],
connectSrc: ["'self'"],
- fontSrc: ["'self'", 'https://fonts.gstatic.com'],
+ fontSrc: ["'self'"],
objectSrc: ["'none'"],
// Auto-upgrade HTTP→HTTPS in production, unless CSP_UPGRADE_INSECURE_REQUESTS opts out for an
// HTTP-only private-network deployment (otherwise the browser forces the dashboard to https). (#611)
diff --git a/test/configure-app.e2e-spec.ts b/test/configure-app.e2e-spec.ts
index a294a6e87..e1dfab144 100644
--- a/test/configure-app.e2e-spec.ts
+++ b/test/configure-app.e2e-spec.ts
@@ -133,6 +133,14 @@ describe('production HTTP surface (configureApp)', () => {
expect(await nonceOf()).not.toEqual(await nonceOf());
});
+ it('allows styles and fonts only from its own origin', async () => {
+ const res = await request(app.getHttpServer()).get('/').set('Accept', 'text/html').expect(200);
+
+ const csp = res.headers['content-security-policy'];
+ expect(csp).toMatch(/(?:^|;)font-src 'self'(?:;|$)/);
+ expect(csp).toMatch(/(?:^|;)style-src 'self' 'unsafe-inline'(?:;|$)/);
+ });
+
it('echoes the CORS header for an allowed Origin', async () => {
const res = await request(app.getHttpServer())
.post('/api/echo')