Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

Add open preview-iframe network CSP policy (#1696)

Andrew Mikofalvy2c510713aa59
diff --git a/.changeset/preview-open-network-policy.md b/.changeset/preview-open-network-policy.md
new file mode 100644
index 000000000..143156ae9
--- /dev/null
+++ b/.changeset/preview-open-network-policy.md
@@ -0,0 +1,11 @@
+---
+"@inkeep/open-knowledge-core": minor
+"@inkeep/open-knowledge-app": minor
+"@inkeep/open-knowledge-server": minor
+---
+
+Preview embeds can now reach the network. The code-block `html preview` iframe runs with an open network CSP, so embeds that load external stylesheets, `fetch` live data, pull map tiles / remote images, use web fonts, or embed third-party iframes (over `https:`/`wss:`/`data:`/`blob:`) render — Leaflet maps, live-data charts, and the like work out of the box. `'unsafe-eval'` is not granted (the common libraries don't need it), and `*` / plaintext `http:`/`ws:` schemes are excluded.
+
+The iframe stays a sandboxed null-origin frame (`sandbox="allow-scripts"`, no `allow-same-origin`), so an embed can reach the network but can never read the knowledge base, cookies, or auth — it widens network reach, not document access.
+
+Breaking: the `preview.scriptSrc` config field is removed — the preview network policy is no longer configurable. A stale `preview.scriptSrc` key is rejected loudly on config load with a migration message (and handled by `ok config migrate`), not a silent no-op. A future multi-tenant host that needs to lock the preview network down will do so with an operator-level control (an env / build flag the tenant can't edit), not a content-editable config field.
diff --git a/docs/content/reference/configuration.mdx b/docs/content/reference/configuration.mdx
index bb3a861f2..c8d081f52 100644
--- a/docs/content/reference/configuration.mdx
+++ b/docs/content/reference/configuration.mdx
@@ -32,7 +32,6 @@ The **Scope** column says which file a setting belongs in: **project** → `.ok/
| `autoSync.enabled` | `boolean \| null` | `null` | project-local | Per-machine git auto-sync toggle. `null` means "unanswered"; the editor's onboarding modal triggers on first remote-detected open. |
| `editor.wordWrap` | boolean | `true` | user | Soft-wrap long lines in the source-mode CodeMirror editor. A personal preference, not project-shared. Toggle from the Settings pane. |
| `appearance.preview.autoOpen` | boolean | `true` | user | Whether the agent should open or refresh the Open Knowledge preview when it edits a doc through the MCP. Default `true` lets the agent route the preview by host capability: the host's in-app browser (Cursor preview pane, Codex's built-in browser, Claude Code Desktop) when one exists, the system browser otherwise. Set `false` to keep the agent's hands off your preview window. This is useful when you're already viewing the doc in OK Desktop, a browser tab on a second display, a non-default browser, or any flow where your extensions / accessibility tooling only work in your own browser. The agent then surfaces the URL on request but does not navigate. The change takes effect on the next preview-related tool call. Toggle from **Settings → Preferences → "Open preview when agent edits"**. |
-| `preview.scriptSrc` | `"cdn-allowlist" \| "inline-only"` | `"cdn-allowlist"` | project | Content Security Policy `script-src` for the code-block HTML preview iframe. `cdn-allowlist` lets preview embeds load library `<script src>` tags from a fixed set of trusted static CDNs (cdnjs, jsDelivr, unpkg, esm.sh), so interactive embeds like chart.js render. The allowlist is fixed: only `cdnjs.cloudflare.com`, `cdn.jsdelivr.net`, `unpkg.com`, and `esm.sh` are permitted and custom origins can't be added. If a script from another origin is blocked (a `script-src` CSP error in the browser console), inline the library directly in the code block or load a copy one of these CDNs hosts. `inline-only` is the strict policy a cloud / multi-tenant deployment opts into: inline scripts only, no external script origins. Shared across collaborators so everyone gets one policy, and AI agents can't change it. Every other preview-iframe protection (`connect-src 'none'`, sandboxed null-origin frame, etc.) holds under both values. |
| `telemetry.localSink.enabled` | boolean | `true` | project | Write local diagnostic spans + logs under `.ok/local/` for `ok diagnose bundle` to collect. Local-only: nothing leaves the machine until you run `bundle`. Set `false` for sensitive workspaces. |
| `telemetry.localSink.spans.maxBytes` | number | `52428800` (~50 MB) | project | Max size of the local diagnostic spans file before it rotates. |
| `telemetry.localSink.logs.maxBytes` | number | `26214400` (~25 MB) | project | Max size of the local diagnostic logs file before it rotates. |
diff --git a/packages/app/src/editor/extensions/CodeBlockView.dom.test.tsx b/packages/app/src/editor/extensions/CodeBlockView.dom.test.tsx
index c30f2756d..bb57b805b 100644
--- a/packages/app/src/editor/extensions/CodeBlockView.dom.test.tsx
+++ b/packages/app/src/editor/extensions/CodeBlockView.dom.test.tsx
@@ -4,7 +4,6 @@ import { cleanup, fireEvent, render } from '@testing-library/react';
import type { NodeViewProps } from '@tiptap/core';
import { ConfigContext, type ConfigContextValue } from '@/lib/config-context';
import { CodeBlockView } from './CodeBlockView';
-import { PREVIEW_SCRIPT_SRC_CDN_ALLOWLIST } from './preview-iframe-header';
function makeConfigValue(merged: Config | null): ConfigContextValue {
return {
@@ -48,9 +47,9 @@ function makeProps(): NodeViewProps {
} as unknown as NodeViewProps;
}
-function renderSrcdoc(merged: Config | null): string {
+function renderSrcdoc(): string {
const { container } = render(
- <ConfigContext value={makeConfigValue(merged)}>
+ <ConfigContext value={makeConfigValue(null)}>
<CodeBlockView {...makeProps()} />
</ConfigContext>,
);
@@ -64,28 +63,15 @@ describe('CodeBlockView preview-CSP wiring', () => {
cleanup();
});
- test('inline-only config produces a strict script-src with no CDN origins', () => {
- const srcdoc = renderSrcdoc({ preview: { scriptSrc: 'inline-only' } } as Config);
- expect(srcdoc).toContain("script-src 'unsafe-inline'");
- for (const origin of PREVIEW_SCRIPT_SRC_CDN_ALLOWLIST) {
- expect(srcdoc).not.toContain(origin);
- }
+ test('renders the fixed open-network CSP in the iframe srcdoc', () => {
+ const srcdoc = renderSrcdoc();
+ expect(srcdoc).toContain("script-src 'unsafe-inline' https:");
+ expect(srcdoc).toContain('connect-src https:');
+ expect(srcdoc).toContain('img-src https:');
+ expect(srcdoc).not.toContain("connect-src 'none'");
+ expect(srcdoc).not.toContain("'unsafe-eval'");
expect(srcdoc).toContain('<div id="probe">hello</div>');
});
-
- test('cdn-allowlist config admits every allowlisted CDN origin', () => {
- const srcdoc = renderSrcdoc({ preview: { scriptSrc: 'cdn-allowlist' } } as Config);
- for (const origin of PREVIEW_SCRIPT_SRC_CDN_ALLOWLIST) {
- expect(srcdoc).toContain(origin);
- }
- });
-
- test('falls back to cdn-allowlist when merged config is null (pre-sync)', () => {
- const srcdoc = renderSrcdoc(null);
- for (const origin of PREVIEW_SCRIPT_SRC_CDN_ALLOWLIST) {
- expect(srcdoc).toContain(origin);
- }
- });
});
describe('CodeBlockView edit-source modal language wiring', () => {
@@ -95,7 +81,7 @@ describe('CodeBlockView edit-source modal language wiring', () => {
test('html-preview fence opens edit-source modal with language="html"', () => {
const { container } = render(
- <ConfigContext value={makeConfigValue({ preview: { scriptSrc: 'inline-only' } } as Config)}>
+ <ConfigContext value={makeConfigValue(null)}>
<CodeBlockView {...makeProps()} />
</ConfigContext>,
);
diff --git a/packages/app/src/editor/extensions/CodeBlockView.tsx b/packages/app/src/editor/extensions/CodeBlockView.tsx
index dc7ec853e..1ca31c365 100644
--- a/packages/app/src/editor/extensions/CodeBlockView.tsx
+++ b/packages/app/src/editor/extensions/CodeBlockView.tsx
@@ -14,7 +14,6 @@ import {
} from '@/components/ui/command';
import { Input } from '@/components/ui/input';
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
-import { useConfigContext } from '@/lib/config-provider';
import { cn } from '@/lib/utils';
import { OPT_OUT_ATTR } from '../clipboard/index.ts';
import { CodePreviewEditModal } from '../components/CodePreviewEditModal';
@@ -82,8 +81,6 @@ export function CodeBlockView({ node, updateAttributes, editor, getPos, selected
const appTheme: PreviewTheme =
resolvedTheme === 'dark' || resolvedTheme === 'light' ? resolvedTheme : readAppTheme();
const [bakedTheme] = useState<PreviewTheme>(readAppTheme);
- const { merged } = useConfigContext();
- const previewScriptSrc = merged?.preview?.scriptSrc ?? 'cdn-allowlist';
const rawLanguage = (node.attrs.language as string | null) ?? null;
const rawMeta = (node.attrs.meta as string | null) ?? null;
const title = getMetaTitle(rawMeta);
@@ -223,7 +220,7 @@ export function CodeBlockView({ node, updateAttributes, editor, getPos, selected
ref={previewFrameRef}
sandbox="allow-scripts"
referrerPolicy="no-referrer"
- srcDoc={buildPreviewIframeHeader(previewScriptSrc, bakedTheme) + node.textContent}
+ srcDoc={buildPreviewIframeHeader(bakedTheme) + node.textContent}
className="ok-codeblock-preview-frame"
onLoad={() => {
previewFrameRef.current?.contentWindow?.postMessage(
@@ -454,7 +451,7 @@ export function CodeBlockView({ node, updateAttributes, editor, getPos, selected
title={t`HTML preview`}
sandbox="allow-scripts"
className="size-full border-0"
- srcDoc={buildPreviewIframeHeader(previewScriptSrc, bakedTheme) + value}
+ srcDoc={buildPreviewIframeHeader(bakedTheme) + value}
/>
)}
onSave={handleEditSave}
diff --git a/packages/app/src/editor/extensions/code-block-preview-csp.test.ts b/packages/app/src/editor/extensions/code-block-preview-csp.test.ts
index e845ce134..25813b61e 100644
--- a/packages/app/src/editor/extensions/code-block-preview-csp.test.ts
+++ b/packages/app/src/editor/extensions/code-block-preview-csp.test.ts
@@ -1,81 +1,50 @@
import { describe, expect, test } from 'bun:test';
-import {
- buildPreviewIframeHeader,
- PREVIEW_SCRIPT_SRC_CDN_ALLOWLIST,
-} from './preview-iframe-header';
+import { buildPreviewIframeHeader } from './preview-iframe-header';
-const POLICIES = ['cdn-allowlist', 'inline-only'] as const;
+function cspOf(header: string): string {
+ return header.match(/content="([^"]+)"/)?.[1] ?? '';
+}
describe('buildPreviewIframeHeader — CSP directives', () => {
- for (const policy of POLICIES) {
- describe(`policy: ${policy}`, () => {
- const header = buildPreviewIframeHeader(policy, 'light');
+ const header = buildPreviewIframeHeader('light');
+ const csp = cspOf(header);
- test('contains a CSP <meta> tag', () => {
- expect(header).toMatch(/<meta http-equiv="Content-Security-Policy" content="[^"]+">/);
- });
-
- test('blocks all outbound network requests', () => {
- expect(header).toContain("connect-src 'none'");
- });
-
- test('blocks external resource loads by default', () => {
- expect(header).toContain("default-src 'none'");
- });
-
- test('blocks form submission', () => {
- expect(header).toContain("form-action 'none'");
- });
-
- test('blocks <base> manipulation', () => {
- expect(header).toContain("base-uri 'none'");
- });
-
- test('blocks nested iframes', () => {
- expect(header).toContain("frame-src 'none'");
- expect(header).toContain("child-src 'none'");
- });
+ test('contains a CSP <meta> tag', () => {
+ expect(header).toMatch(/<meta http-equiv="Content-Security-Policy" content="[^"]+">/);
+ });
- test('permits inline scripts (the whole point of the preview)', () => {
- expect(header).toContain("script-src 'unsafe-inline'");
- });
+ test('keeps the default-src deny baseline', () => {
+ expect(csp).toContain("default-src 'none'");
+ });
- test('permits inline styles + `data:` for embedded SVG / fonts', () => {
- expect(header).toContain("style-src 'unsafe-inline' data:");
- expect(header).toContain('img-src data:');
- expect(header).toContain('font-src data:');
- });
+ test('opens the network surface to https:/wss: scheme-sources', () => {
+ expect(csp).toContain("script-src 'unsafe-inline' https:");
+ expect(csp).toContain("style-src 'unsafe-inline' https: data:");
+ expect(csp).toContain('img-src https: data: blob:');
+ expect(csp).toContain('font-src https: data:');
+ expect(csp).toContain('connect-src https: wss: data: blob:');
+ expect(csp).toContain('media-src https: data: blob:');
+ expect(csp).toContain('frame-src https:');
+ expect(csp).toContain('child-src https:');
+ });
- test('never permits `*` or a bare `https:` scheme-source in script-src', () => {
- expect(header).not.toMatch(/script-src[^;]*https:(?!\/)/);
- expect(header).not.toMatch(/script-src[^;]*\*/);
- });
- });
- }
+ test('permits inline scripts + styles (the whole point of the preview)', () => {
+ expect(csp).toContain("script-src 'unsafe-inline'");
+ expect(csp).toContain("style-src 'unsafe-inline'");
+ });
- test('cdn-allowlist script-src permits unsafe-inline plus every allowlisted CDN origin', () => {
- const header = buildPreviewIframeHeader('cdn-allowlist', 'light');
- expect(header).toContain("script-src 'unsafe-inline'");
- for (const origin of PREVIEW_SCRIPT_SRC_CDN_ALLOWLIST) {
- expect(header).toContain(origin);
- }
+ test('keeps form-action + base-uri locked', () => {
+ expect(csp).toContain("form-action 'none'");
+ expect(csp).toContain("base-uri 'none'");
});
- test('inline-only script-src permits unsafe-inline only, no external origin', () => {
- const header = buildPreviewIframeHeader('inline-only', 'light');
- expect(header).toContain("script-src 'unsafe-inline'");
- for (const origin of PREVIEW_SCRIPT_SRC_CDN_ALLOWLIST) {
- expect(header).not.toContain(origin);
- }
- expect(header).not.toMatch(/script-src[^;]*https:/);
+ test("never grants 'unsafe-eval'", () => {
+ expect(csp).not.toContain("'unsafe-eval'");
});
- test('the CDN allowlist is exactly the four trusted static CDNs', () => {
- expect(PREVIEW_SCRIPT_SRC_CDN_ALLOWLIST).toEqual([
- 'https://cdnjs.cloudflare.com',
- 'https://cdn.jsdelivr.net',
- 'https://unpkg.com',
- 'https://esm.sh',
- ]);
+ test('never opens to `*` or a plaintext http:/ws: scheme-source', () => {
+ expect(csp).not.toContain('*');
+ expect(csp).not.toMatch(/[\s;]http:(?!\/)/);
+ expect(csp).not.toMatch(/[\s;]ws:(?!\/)/);
});
});
diff --git a/packages/app/src/editor/extensions/preview-iframe-header.ts b/packages/app/src/editor/extensions/preview-iframe-header.ts
index b2897d6b7..80d9a5b37 100644
--- a/packages/app/src/editor/extensions/preview-iframe-header.ts
+++ b/packages/app/src/editor/extensions/preview-iframe-header.ts
@@ -1,8 +1,5 @@
-import type { Config } from '@inkeep/open-knowledge-core';
import { PREVIEW_THEME_TOKENS } from '@inkeep/open-knowledge-core';
-export type PreviewScriptSrcPolicy = Config['preview']['scriptSrc'];
-
export type PreviewTheme = 'light' | 'dark';
const PREVIEW_THEME_MESSAGE_KEY = 'okPreviewTheme';
@@ -23,13 +20,6 @@ export function parsePreviewHeightMessage(data: unknown): number | null {
return typeof h === 'number' && Number.isFinite(h) && h > 0 ? Math.ceil(h) : null;
}
-export const PREVIEW_SCRIPT_SRC_CDN_ALLOWLIST = [
- 'https://cdnjs.cloudflare.com',
- 'https://cdn.jsdelivr.net',
- 'https://unpkg.com',
- 'https://esm.sh',
-] as const;
-
const PREVIEW_SCROLLBAR_STYLE = `<style>
html, body { scrollbar-width: thin; scrollbar-color: rgba(115,115,115,0.4) transparent; }
html::-webkit-scrollbar, body::-webkit-scrollbar,
@@ -83,27 +73,18 @@ function previewBootstrapScript(theme: PreviewTheme): string {
);
}
-function scriptSrcDirective(policy: PreviewScriptSrcPolicy): string {
- switch (policy) {
- case 'cdn-allowlist':
- return `script-src 'unsafe-inline' ${PREVIEW_SCRIPT_SRC_CDN_ALLOWLIST.join(' ')}`;
- case 'inline-only':
- return "script-src 'unsafe-inline'";
- default: {
- const _exhaustive: never = policy;
- throw new Error(
- `Unhandled preview script-src policy: ${JSON.stringify(_exhaustive as unknown)}`,
- );
- }
- }
-}
+const PREVIEW_CSP =
+ "default-src 'none'; " +
+ "script-src 'unsafe-inline' https:; " +
+ "style-src 'unsafe-inline' https: data:; " +
+ 'img-src https: data: blob:; ' +
+ 'font-src https: data:; ' +
+ 'connect-src https: wss: data: blob:; ' +
+ 'media-src https: data: blob:; ' +
+ "frame-src https:; child-src https:; form-action 'none'; base-uri 'none';";
-export function buildPreviewIframeHeader(
- policy: PreviewScriptSrcPolicy,
- theme: PreviewTheme,
-): string {
- const csp = `default-src 'none'; ${scriptSrcDirective(policy)}; style-src 'unsafe-inline' data:; img-src data:; font-src data:; connect-src 'none'; frame-src 'none'; child-src 'none'; form-action 'none'; base-uri 'none';`;
- return `<meta http-equiv="Content-Security-Policy" content="${csp}">
+export function buildPreviewIframeHeader(theme: PreviewTheme): string {
+ return `<meta http-equiv="Content-Security-Policy" content="${PREVIEW_CSP}">
${themeTokenStyle()}
${PREVIEW_SCROLLBAR_STYLE}
${previewBootstrapScript(theme)}`;
diff --git a/packages/app/src/editor/extensions/preview-iframe-theme.test.ts b/packages/app/src/editor/extensions/preview-iframe-theme.test.ts
index 15ddb09a3..c52d7f44b 100644
--- a/packages/app/src/editor/extensions/preview-iframe-theme.test.ts
+++ b/packages/app/src/editor/extensions/preview-iframe-theme.test.ts
@@ -7,7 +7,6 @@ import {
parsePreviewHeightMessage,
} from './preview-iframe-header';
-const POLICIES = ['cdn-allowlist', 'inline-only'] as const;
const THEMES: readonly PreviewTheme[] = ['light', 'dark'];
const INITIAL_CLASS_STATEMENT = "d.classList.add('dark');";
@@ -16,54 +15,50 @@ function count(s: string, sub: string): number {
}
describe('buildPreviewIframeHeader — theme token injection', () => {
- for (const policy of POLICIES) {
- for (const theme of THEMES) {
- const header = buildPreviewIframeHeader(policy, theme);
-
- test(`[${policy}/${theme}] injects both :root and :root.dark token blocks`, () => {
- expect(header).toContain(':root{');
- expect(header).toContain(':root.dark{');
- });
-
- test(`[${policy}/${theme}] delivers every token in both light and dark`, () => {
- for (const t of PREVIEW_THEME_TOKENS) {
- expect(header).toContain(`${t.name}:${t.light}`);
- expect(header).toContain(`${t.name}:${t.dark}`);
- }
- });
-
- test(`[${policy}/${theme}] sets color-scheme so native controls theme`, () => {
- expect(header).toContain('color-scheme:light');
- expect(header).toContain('color-scheme:dark');
- });
-
- test(`[${policy}/${theme}] injects themed body defaults`, () => {
- expect(header).toContain('background:var(--background)');
- expect(header).toContain('color:var(--foreground)');
- });
-
- test(`[${policy}/${theme}] wires the postMessage theme listener`, () => {
- expect(header).toContain('<script>');
- expect(header).toContain("addEventListener('message'");
- const messageKey = Object.keys(buildPreviewThemeMessage('light'))[0];
- expect(header).toContain(`e.data.${messageKey}`);
- });
- }
+ for (const theme of THEMES) {
+ const header = buildPreviewIframeHeader(theme);
+
+ test(`[${theme}] injects both :root and :root.dark token blocks`, () => {
+ expect(header).toContain(':root{');
+ expect(header).toContain(':root.dark{');
+ });
+
+ test(`[${theme}] delivers every token in both light and dark`, () => {
+ for (const t of PREVIEW_THEME_TOKENS) {
+ expect(header).toContain(`${t.name}:${t.light}`);
+ expect(header).toContain(`${t.name}:${t.dark}`);
+ }
+ });
+
+ test(`[${theme}] sets color-scheme so native controls theme`, () => {
+ expect(header).toContain('color-scheme:light');
+ expect(header).toContain('color-scheme:dark');
+ });
+
+ test(`[${theme}] injects themed body defaults`, () => {
+ expect(header).toContain('background:var(--background)');
+ expect(header).toContain('color:var(--foreground)');
+ });
+
+ test(`[${theme}] wires the postMessage theme listener`, () => {
+ expect(header).toContain('<script>');
+ expect(header).toContain("addEventListener('message'");
+ const messageKey = Object.keys(buildPreviewThemeMessage('light'))[0];
+ expect(header).toContain(`e.data.${messageKey}`);
+ });
}
test('dark bakes one extra initial-class statement vs light', () => {
- const light = buildPreviewIframeHeader('cdn-allowlist', 'light');
- const dark = buildPreviewIframeHeader('cdn-allowlist', 'dark');
+ const light = buildPreviewIframeHeader('light');
+ const dark = buildPreviewIframeHeader('dark');
expect(count(light, INITIAL_CLASS_STATEMENT)).toBe(1);
expect(count(dark, INITIAL_CLASS_STATEMENT)).toBe(2);
});
- test('per policy, light and dark headers differ ONLY by the baked class', () => {
- for (const policy of POLICIES) {
- const light = buildPreviewIframeHeader(policy, 'light');
- const dark = buildPreviewIframeHeader(policy, 'dark');
- expect(dark.replace(INITIAL_CLASS_STATEMENT, '')).toBe(light);
- }
+ test('light and dark headers differ ONLY by the baked class', () => {
+ const light = buildPreviewIframeHeader('light');
+ const dark = buildPreviewIframeHeader('dark');
+ expect(dark.replace(INITIAL_CLASS_STATEMENT, '')).toBe(light);
});
});
@@ -75,20 +70,18 @@ describe('buildPreviewThemeMessage', () => {
});
describe('buildPreviewIframeHeader — auto-height reporting', () => {
- for (const policy of POLICIES) {
- for (const theme of THEMES) {
- const header = buildPreviewIframeHeader(policy, theme);
-
- test(`[${policy}/${theme}] the bootstrap script reports content height`, () => {
- expect(header).toContain('okPreviewHeight');
- expect(header).toContain('getBoundingClientRect');
- expect(header).toContain('ResizeObserver');
- });
- }
+ for (const theme of THEMES) {
+ const header = buildPreviewIframeHeader(theme);
+
+ test(`[${theme}] the bootstrap script reports content height`, () => {
+ expect(header).toContain('okPreviewHeight');
+ expect(header).toContain('getBoundingClientRect');
+ expect(header).toContain('ResizeObserver');
+ });
}
test('the theme listener honors only the parent window', () => {
- expect(buildPreviewIframeHeader('cdn-allowlist', 'light')).toContain('e.source!==parent');
+ expect(buildPreviewIframeHeader('light')).toContain('e.source!==parent');
});
});
diff --git a/packages/core/src/config/field-registry.test.ts b/packages/core/src/config/field-registry.test.ts
index 0da319e28..761476018 100644
--- a/packages/core/src/config/field-registry.test.ts
+++ b/packages/core/src/config/field-registry.test.ts
@@ -136,7 +136,7 @@ describe('ConfigSchema coverage (NR3 — every leaf has fieldRegistry metadata)'
]);
});
- test('project-strict fields cover content.dir + preview.scriptSrc + telemetry.localSink.*', () => {
+ test('project-strict fields cover content.dir + telemetry.localSink.*', () => {
const leaves: { path: string[]; schema: unknown }[] = [];
walkLeaves(ConfigSchema, [], leaves);
const projectStrict = leaves
@@ -145,7 +145,6 @@ describe('ConfigSchema coverage (NR3 — every leaf has fieldRegistry metadata)'
.sort();
expect(projectStrict).toEqual([
'content.dir',
- 'preview.scriptSrc',
'telemetry.localSink.attributeDenylist',
'telemetry.localSink.enabled',
'telemetry.localSink.logs.maxBytes',
diff --git a/packages/core/src/config/removed-keys.ts b/packages/core/src/config/removed-keys.ts
index b70945bfe..0ca8141c4 100644
--- a/packages/core/src/config/removed-keys.ts
+++ b/packages/core/src/config/removed-keys.ts
@@ -94,6 +94,14 @@ export const REMOVED_KEYS: readonly RemovedKey[] = [
MIGRATE_HINT,
].join(' '),
},
+ {
+ path: ['preview', 'scriptSrc'],
+ redirect: [
+ 'preview.scriptSrc has been removed.',
+ 'The code-block preview iframe now runs a fixed open network policy (it is no longer configurable).',
+ MIGRATE_HINT,
+ ].join(' '),
+ },
];
function isPlainObject(value: unknown): value is Record<string, unknown> {
diff --git a/packages/core/src/config/schema-jsonschema.test.ts b/packages/core/src/config/schema-jsonschema.test.ts
index b0245c352..db4668584 100644
--- a/packages/core/src/config/schema-jsonschema.test.ts
+++ b/packages/core/src/config/schema-jsonschema.test.ts
@@ -58,21 +58,6 @@ const FIXTURES: Fixture[] = [
input: { editor: { wordWrap: 'false' } },
shouldAccept: false,
},
- {
- name: 'preview.scriptSrc=cdn-allowlist accepted',
- input: { preview: { scriptSrc: 'cdn-allowlist' } },
- shouldAccept: true,
- },
- {
- name: 'preview.scriptSrc=inline-only accepted',
- input: { preview: { scriptSrc: 'inline-only' } },
- shouldAccept: true,
- },
- {
- name: 'preview.scriptSrc=wide-open rejected',
- input: { preview: { scriptSrc: 'wide-open' } },
- shouldAccept: false,
- },
{
name: 'appearance.preview.autoOpen=false accepted',
input: { appearance: { preview: { autoOpen: false } } },
@@ -178,16 +163,6 @@ describe('loose-mode forgiveness', () => {
expect(config.appearance.preview.autoOpen).toBe(false);
});
- test("preview.scriptSrc defaults to 'cdn-allowlist'", () => {
- const config = ConfigSchema.parse({});
- expect(config.preview.scriptSrc).toBe('cdn-allowlist');
- });
-
- test("preview.scriptSrc preserves an explicit 'inline-only'", () => {
- const config = ConfigSchema.parse({ preview: { scriptSrc: 'inline-only' } });
- expect(config.preview.scriptSrc).toBe('inline-only');
- });
-
test('telemetry.localSink defaults to enabled with built-in caps + denylist', () => {
const config = ConfigSchema.parse({});
expect(config.telemetry.localSink.enabled).toBe(true);
diff --git a/packages/core/src/config/schema-leaf.test.ts b/packages/core/src/config/schema-leaf.test.ts
index ef20770e1..40569b399 100644
--- a/packages/core/src/config/schema-leaf.test.ts
+++ b/packages/core/src/config/schema-leaf.test.ts
@@ -35,16 +35,6 @@ describe('getLeafFieldMeta', () => {
});
});
- test('returns metadata for the project-strict preview.scriptSrc leaf', () => {
- const meta = getLeafFieldMeta(ConfigSchema, ['preview', 'scriptSrc']);
- expect(meta).toEqual({
- scope: 'project',
- agentSettable: false,
- defaultScope: 'project',
- description: expect.any(String),
- });
- });
-
test('returns metadata for the user-scope appearance.theme leaf', () => {
const meta = getLeafFieldMeta(ConfigSchema, ['appearance', 'theme']);
expect(meta).toEqual({
diff --git a/packages/core/src/config/schema.ts b/packages/core/src/config/schema.ts
index 2abdc3a8f..c7b1cd62b 100644
--- a/packages/core/src/config/schema.ts
+++ b/packages/core/src/config/schema.ts
@@ -32,20 +32,6 @@ export const ConfigSchema = z.looseObject({
.default({
dir: '.',
}),
- preview: z
- .looseObject({
- scriptSrc: z
- .enum(['cdn-allowlist', 'inline-only'])
- .register(fieldRegistry, {
- scope: 'project',
- agentSettable: false,
- defaultScope: 'project',
- description:
- "Security policy for scripts in code-block preview embeds. 'cdn-allowlist' allows <script src> from a fixed set of trusted CDNs; 'inline-only' is the strict policy for cloud / multi-tenant deployments. Shared across collaborators.",
- })
- .default('cdn-allowlist'),
- })
- .default({ scriptSrc: 'cdn-allowlist' }),
appearance: z
.looseObject({
theme: z
diff --git a/packages/server/assets/skills/project/SKILL.md b/packages/server/assets/skills/project/SKILL.md
index 679994448..a34241232 100644
--- a/packages/server/assets/skills/project/SKILL.md
+++ b/packages/server/assets/skills/project/SKILL.md
@@ -198,6 +198,8 @@ const c1 = getComputedStyle(document.documentElement).getPropertyValue('--chart-
**Boundary.** Reach for a canonical (via its markdown-native form) when one matches the semantic need — it is themed and integrated. Reach for ` ```html preview ` for interactive or bespoke content no canonical covers. ` ```<lang> ` fences for other languages are plain syntax-highlighted code, no preview.
+**External resources load directly.** The preview iframe has open network access — an embed can load external stylesheets, `fetch` live data, pull map tiles / remote images, use web fonts, or embed third-party iframes over `https:`. A Leaflet map, a live-`fetch` chart, or a Google-Font embed renders with no extra setup. The iframe is a sandboxed null-origin frame, so an embed can reach the network but can never read the knowledge base, cookies, or auth. (`'unsafe-eval'` is not granted — Chart.js / Leaflet / Plotly don't need it; a library that compiles expression strings at runtime won't run.)
+
## Grounding — every factual claim needs a source (MUST)
Knowledge-base docs are factual artifacts — whether the project is a wiki, an LLM brain, a spec collection, a research log, or anything else markdown-shaped. Every claim must be traceable, and **the source has to live inside the knowledge base**, not float on the public web.
diff --git a/packages/server/src/mcp/tools/config.ts b/packages/server/src/mcp/tools/config.ts
index 88f9c2ec9..57db36273 100644
--- a/packages/server/src/mcp/tools/config.ts
+++ b/packages/server/src/mcp/tools/config.ts
@@ -14,7 +14,7 @@ export const DESCRIPTION = [
'',
'Read returns the FULL merged config or a sub-tree when `key` is provided. There is no allowlist on reads — every field is readable.',
'',
- 'Note: the `server.*`, `mcp.*`, and `github.*` config sub-trees, plus `preview.baseUrl`, were removed; their values are now built-in constants in `@inkeep/open-knowledge-core`. Reading those keys returns `exists: false`. (`preview.scriptSrc` and `appearance.preview.autoOpen` are still live keys.)',
+ 'Note: the `server.*`, `mcp.*`, and `github.*` config sub-trees, plus `preview.baseUrl` and `preview.scriptSrc`, were removed; their values are now built-in constants in `@inkeep/open-knowledge-core` (or, for the preview iframe, a fixed open network policy). Reading those keys returns `exists: false`. (`appearance.preview.autoOpen` is still a live key.)',
'',
'**Parameters:**',
'- `key` (optional) — Dotted config key. `"content"` returns the content sub-tree; `"appearance.theme"` returns just that leaf. Omit for full config.',
diff --git a/packages/server/src/mcp/tools/palette.ts b/packages/server/src/mcp/tools/palette.ts
index 55cad4fec..793e69649 100644
--- a/packages/server/src/mcp/tools/palette.ts
+++ b/packages/server/src/mcp/tools/palette.ts
@@ -18,6 +18,8 @@ export const DESCRIPTION = [
'- `embedPatterns` — copy-ready ` ```html preview ` starters (chart, stat cards, custom SVG, interactive control) already wired to the theme tokens, so an embed tracks light/dark with no hand-picked colors.',
'- `tokens` — the CSS custom properties injected into every preview iframe; reference them as `var(--chart-1)`, `var(--foreground)`, … inside an `html preview` embed.',
'',
+ 'External resources load directly: the preview iframe has open network access, so an embed can load external stylesheets, `fetch` live data, or pull map tiles / remote images / web fonts over `https:`. The iframe is a sandboxed null-origin frame — an embed can reach the network but never the knowledge base, cookies, or auth.',
+ '',
'Pass `components: [ids]` to ALSO get the full JSX-form prop schema for specific canonicals (e.g. `palette({ components: ["Callout", "Tabs"] })`) — merged from the former `get_components`.',
'',
'**Parameters:**',