@immediately-run/sdk 0.49.0 → 0.51.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/components/MainContent.cjs +16 -3
  2. package/dist/components/MainContent.cjs.map +1 -1
  3. package/dist/components/MainContent.js +16 -3
  4. package/dist/components/MainContent.js.map +1 -1
  5. package/dist/fs.cjs.map +1 -1
  6. package/dist/fs.js.map +1 -1
  7. package/dist/generated/protocol.d.cts +1 -0
  8. package/dist/generated/protocol.d.ts +1 -0
  9. package/dist/index.cjs +6 -1
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +4 -6
  12. package/dist/index.d.ts +4 -6
  13. package/dist/index.js +4 -1
  14. package/dist/index.js.map +1 -1
  15. package/dist/injectedBundler.cjs.map +1 -1
  16. package/dist/injectedBundler.d.cts +18 -2
  17. package/dist/injectedBundler.d.ts +18 -2
  18. package/dist/injectedBundler.js.map +1 -1
  19. package/dist/linkSpace.cjs +4 -36
  20. package/dist/linkSpace.cjs.map +1 -1
  21. package/dist/linkSpace.d.cts +3 -60
  22. package/dist/linkSpace.d.ts +3 -60
  23. package/dist/linkSpace.js +1 -33
  24. package/dist/linkSpace.js.map +1 -1
  25. package/dist/mounts.cjs.map +1 -1
  26. package/dist/mounts.js.map +1 -1
  27. package/dist/safeContent/SafeContent.cjs +2 -27
  28. package/dist/safeContent/SafeContent.cjs.map +1 -1
  29. package/dist/safeContent/SafeContent.d.cts +1 -13
  30. package/dist/safeContent/SafeContent.d.ts +1 -13
  31. package/dist/safeContent/SafeContent.js +1 -26
  32. package/dist/safeContent/SafeContent.js.map +1 -1
  33. package/dist/safeContent/index.cjs +3 -23
  34. package/dist/safeContent/index.cjs.map +1 -1
  35. package/dist/safeContent/index.d.cts +1 -6
  36. package/dist/safeContent/index.d.ts +1 -6
  37. package/dist/safeContent/index.js +1 -14
  38. package/dist/safeContent/index.js.map +1 -1
  39. package/dist/safeContent/mdastDeps.cjs +7 -2
  40. package/dist/safeContent/mdastDeps.js +7 -2
  41. package/dist/safeContent/parseSafeMdast.cjs +2 -53
  42. package/dist/safeContent/parseSafeMdast.cjs.map +1 -1
  43. package/dist/safeContent/parseSafeMdast.d.cts +1 -45
  44. package/dist/safeContent/parseSafeMdast.d.ts +1 -45
  45. package/dist/safeContent/parseSafeMdast.js +1 -42
  46. package/dist/safeContent/parseSafeMdast.js.map +1 -1
  47. package/dist/safeContent/renderMdast.cjs +2 -133
  48. package/dist/safeContent/renderMdast.cjs.map +1 -1
  49. package/dist/safeContent/renderMdast.d.cts +1 -27
  50. package/dist/safeContent/renderMdast.d.ts +1 -27
  51. package/dist/safeContent/renderMdast.js +1 -132
  52. package/dist/safeContent/renderMdast.js.map +1 -1
  53. package/dist/safeContent/sanitizeUrl.cjs +2 -12
  54. package/dist/safeContent/sanitizeUrl.cjs.map +1 -1
  55. package/dist/safeContent/sanitizeUrl.d.cts +1 -9
  56. package/dist/safeContent/sanitizeUrl.d.ts +1 -9
  57. package/dist/safeContent/sanitizeUrl.js +1 -11
  58. package/dist/safeContent/sanitizeUrl.js.map +1 -1
  59. package/dist/safeContent/wikilink.cjs +3 -35
  60. package/dist/safeContent/wikilink.cjs.map +1 -1
  61. package/dist/safeContent/wikilink.d.cts +1 -21
  62. package/dist/safeContent/wikilink.d.ts +1 -21
  63. package/dist/safeContent/wikilink.js +1 -33
  64. package/dist/safeContent/wikilink.js.map +1 -1
  65. package/dist/version.cjs +1 -1
  66. package/dist/version.cjs.map +1 -1
  67. package/dist/version.d.cts +1 -1
  68. package/dist/version.d.ts +1 -1
  69. package/dist/version.js +1 -1
  70. package/dist/version.js.map +1 -1
  71. package/package.json +9 -5
@@ -1,45 +1 @@
1
- interface SafeMdastNode {
2
- type: string;
3
- value?: string;
4
- name?: string | null;
5
- url?: string;
6
- alt?: string | null;
7
- title?: string | null;
8
- depth?: number;
9
- ordered?: boolean;
10
- lang?: string | null;
11
- children?: SafeMdastNode[];
12
- attributes?: SafeMdxAttribute[];
13
- [key: string]: unknown;
14
- }
15
- interface SafeMdxAttribute {
16
- type: 'mdxJsxAttribute' | 'mdxJsxExpressionAttribute';
17
- name?: string;
18
- value?: string | {
19
- type: string;
20
- value?: string;
21
- } | null;
22
- }
23
- interface ParseSafeMdastOptions {
24
- /** `false` ⇒ headings use plain text-slug ids (the R3-186 base; no `sec-…` section
25
- * ids, no `data-slug`) — the `sectionIds:false` frontmatter opt-out, matching the
26
- * compiled path. Default (undefined/true) ⇒ section-like headings get `sec-…` ids
27
- * (R3-211). */
28
- sectionIds?: boolean;
29
- }
30
- /**
31
- * Parse untrusted Markdown/MDX-syntax source to an mdast tree with **no evaluator in
32
- * the pipeline**: JSX-as-data (no acorn), GFM on, the expression extension OFF, no
33
- * raw-HTML re-parse. The returned tree is safe to hand to `renderMdast` — expression
34
- * attributes are inert strings and raw HTML is inert `html` nodes.
35
- *
36
- * After the no-acorn parse it runs the SHARED kernel remark plugins — in the SAME order
37
- * as the compiled path's `compile.ts` (admonitions §12 → wiki-links §13 → heading/section
38
- * anchors §15/R3-211; GFM is already applied via the micromark extension above) — so the
39
- * safe subset renders identically in both standards. The plugins only emit element nodes
40
- * with LITERAL attributes and set `data.hProperties.id` on headings; they add no evaluator
41
- * and no acorn, preserving the §5.1 fail-safe.
42
- */
43
- declare function parseSafeMdast(source: string, options?: ParseSafeMdastOptions): Promise<SafeMdastNode>;
44
-
45
- export { type ParseSafeMdastOptions, type SafeMdastNode, type SafeMdxAttribute, parseSafeMdast };
1
+ export { ParseSafeMdastOptions, SafeMdastNode, SafeMdxAttribute, parseSafeMdast } from '@immediately-run/safe-content';
@@ -1,45 +1 @@
1
- interface SafeMdastNode {
2
- type: string;
3
- value?: string;
4
- name?: string | null;
5
- url?: string;
6
- alt?: string | null;
7
- title?: string | null;
8
- depth?: number;
9
- ordered?: boolean;
10
- lang?: string | null;
11
- children?: SafeMdastNode[];
12
- attributes?: SafeMdxAttribute[];
13
- [key: string]: unknown;
14
- }
15
- interface SafeMdxAttribute {
16
- type: 'mdxJsxAttribute' | 'mdxJsxExpressionAttribute';
17
- name?: string;
18
- value?: string | {
19
- type: string;
20
- value?: string;
21
- } | null;
22
- }
23
- interface ParseSafeMdastOptions {
24
- /** `false` ⇒ headings use plain text-slug ids (the R3-186 base; no `sec-…` section
25
- * ids, no `data-slug`) — the `sectionIds:false` frontmatter opt-out, matching the
26
- * compiled path. Default (undefined/true) ⇒ section-like headings get `sec-…` ids
27
- * (R3-211). */
28
- sectionIds?: boolean;
29
- }
30
- /**
31
- * Parse untrusted Markdown/MDX-syntax source to an mdast tree with **no evaluator in
32
- * the pipeline**: JSX-as-data (no acorn), GFM on, the expression extension OFF, no
33
- * raw-HTML re-parse. The returned tree is safe to hand to `renderMdast` — expression
34
- * attributes are inert strings and raw HTML is inert `html` nodes.
35
- *
36
- * After the no-acorn parse it runs the SHARED kernel remark plugins — in the SAME order
37
- * as the compiled path's `compile.ts` (admonitions §12 → wiki-links §13 → heading/section
38
- * anchors §15/R3-211; GFM is already applied via the micromark extension above) — so the
39
- * safe subset renders identically in both standards. The plugins only emit element nodes
40
- * with LITERAL attributes and set `data.hProperties.id` on headings; they add no evaluator
41
- * and no acorn, preserving the §5.1 fail-safe.
42
- */
43
- declare function parseSafeMdast(source: string, options?: ParseSafeMdastOptions): Promise<SafeMdastNode>;
44
-
45
- export { type ParseSafeMdastOptions, type SafeMdastNode, type SafeMdxAttribute, parseSafeMdast };
1
+ export { ParseSafeMdastOptions, SafeMdastNode, SafeMdxAttribute, parseSafeMdast } from '@immediately-run/safe-content';
@@ -1,46 +1,5 @@
1
1
  import "../chunk-VHAA22YE.js";
2
- let depsPromise = null;
3
- function loadDeps() {
4
- if (!depsPromise) {
5
- depsPromise = import("./mdastDeps").then((m) => {
6
- const d = m;
7
- return {
8
- fromMarkdown: d.fromMarkdown,
9
- mdxJsx: d.mdxJsx,
10
- mdxJsxFromMarkdown: d.mdxJsxFromMarkdown,
11
- gfm: d.gfm,
12
- gfmFromMarkdown: d.gfmFromMarkdown,
13
- remarkAdmonitions: d.remarkAdmonitions,
14
- remarkWikiLinks: d.remarkWikiLinks,
15
- remarkHeadingAnchors: d.remarkHeadingAnchors
16
- };
17
- });
18
- }
19
- return depsPromise;
20
- }
21
- async function parseSafeMdast(source, options = {}) {
22
- const {
23
- fromMarkdown,
24
- mdxJsx,
25
- mdxJsxFromMarkdown,
26
- gfm,
27
- gfmFromMarkdown,
28
- remarkAdmonitions,
29
- remarkWikiLinks,
30
- remarkHeadingAnchors
31
- } = await loadDeps();
32
- const tree = fromMarkdown(source, {
33
- // `mdxJsx()` WITHOUT an acorn option → JSX tags + literal attrs; expressions are
34
- // raw strings, never estree. The mdx *expression* extension is intentionally
35
- // absent, so `{…}` in body text stays literal. GFM for tables/task-lists.
36
- extensions: [mdxJsx(), gfm()],
37
- mdastExtensions: [mdxJsxFromMarkdown(), gfmFromMarkdown()]
38
- });
39
- remarkAdmonitions()(tree);
40
- remarkWikiLinks()(tree);
41
- remarkHeadingAnchors({ sectionIds: options.sectionIds !== false })(tree);
42
- return tree;
43
- }
2
+ import { parseSafeMdast } from "@immediately-run/safe-content";
44
3
  export {
45
4
  parseSafeMdast
46
5
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/safeContent/parseSafeMdast.ts"],"sourcesContent":["// The no-acorn parse pipeline for the safe content renderer (TRUST_MODES_SPEC §5.1,\n// empirically verified 2026-07-07 against `@mdx-js/mdx` v3 / `micromark-extension-\n// mdx-jsx`). This is the load-bearing half of the fail-safe: `<Component/>` syntax\n// parses to an element node with **literal** attributes, and every expression\n// (`n={1+1}`, `f={fetch(\"/x\")}`, `{...spread}`) is captured as an **inert raw string\n// with no estree** — because we pass **NO acorn option** to `micromark-extension-mdx-\n// jsx`. There is therefore no evaluator anywhere in the pipeline (fail-safe), unlike\n// `@mdx-js/mdx`'s `compile({format:'mdx'})` which always wires acorn.\n//\n// The §5.1 residual guarantees are also here: the expression micromark extension is\n// **not** enabled (body `{…}` stays literal text), and **no `rehype-raw`** / raw-HTML\n// passthrough exists — raw HTML blocks arrive as inert `html` mdast nodes the renderer\n// prints as text, never injected.\n//\n// `micromark`/`mdast` are ESM-only. They are loaded with a memoised dynamic `import()`\n// (the transpiler's `compile.ts` pattern) so this module sits in the package's CJS\n// build too — a CJS consumer that never renders untrusted content never `require()`s\n// an ESM-only package, and one that does gets it via Node's ESM-from-CJS import. The\n// dynamic load changes only *when* the deps resolve, never the produced tree.\n//\n// The dynamic import targets `./mdastDeps` — a SINGLE self-contained artifact that a\n// dedicated build pass (`scripts/build-safecontent-deps.mjs`) inlines the whole ESM tree\n// into (see `mdastDeps.ts` for the WHY). This keeps the `import()` boundary (a consumer\n// that never renders safe content never loads the ~300KB parser) while making the imported\n// target one already-bundled file the immediately.run sandbox resolver can fetch without\n// walking the unified/micromark conditional-exports tree — the R3-213 on-host packaging\n// gap. In jest/ts-jest and the e2e bundle the same `./mdastDeps` resolves to the source\n// re-export module, which pulls the real deps from node_modules; the produced tree is\n// identical either way.\n\n// Type-only — the plugin VALUES are re-exported from (and inlined by) `./mdastDeps`; a\n// value import here would put a bare `@immediately-run/mdx-plugins` specifier in the dist\n// the sandbox resolver can't resolve on-host. `import type` is fully erased at build.\nimport type { HeadingAnchorOptions } from '@immediately-run/mdx-plugins';\n\n// A minimal structural mdast shape — we deliberately avoid a type dependency on the\n// ESM-only `mdast`/`unist` packages (which would break the CJS build's type surface).\nexport interface SafeMdastNode {\n type: string;\n value?: string;\n name?: string | null;\n url?: string;\n alt?: string | null;\n title?: string | null;\n depth?: number;\n ordered?: boolean;\n lang?: string | null;\n children?: SafeMdastNode[];\n attributes?: SafeMdxAttribute[];\n [key: string]: unknown;\n}\n\nexport interface SafeMdxAttribute {\n type: 'mdxJsxAttribute' | 'mdxJsxExpressionAttribute';\n name?: string;\n // A literal attribute carries a string; an expression attribute carries an\n // `mdxJsxAttributeValueExpression` object (a raw string, NO estree) or a string.\n value?: string | { type: string; value?: string } | null;\n}\n\n// `unified`'s `Plugin` type widens the return to `Transformer | void`; the safe path\n// invokes each transformer directly on the tree, so narrow it to a plain in-place mutator.\ntype MdastMutator = (tree: SafeMdastNode) => void;\n\ntype Deps = {\n fromMarkdown: (value: string, options: { extensions: unknown[]; mdastExtensions: unknown[] }) => SafeMdastNode;\n mdxJsx: () => unknown;\n mdxJsxFromMarkdown: () => unknown;\n gfm: () => unknown;\n gfmFromMarkdown: () => unknown;\n // The three shared kernel remark plugins, also inlined into `./mdastDeps` (see there).\n remarkAdmonitions: () => MdastMutator;\n remarkWikiLinks: () => MdastMutator;\n remarkHeadingAnchors: (o?: HeadingAnchorOptions) => MdastMutator;\n};\n\nlet depsPromise: Promise<Deps> | null = null;\n\nfunction loadDeps(): Promise<Deps> {\n if (!depsPromise) {\n // ONE dynamic import of the pre-inlined artifact (see the header note + `mdastDeps.ts`)\n // — the five ESM parser packages AND the shared remark plugins, none of which the\n // sandbox resolver can walk/resolve as bare specifiers on-host.\n depsPromise = import('./mdastDeps').then((m) => {\n const d = m as unknown as Deps;\n return {\n fromMarkdown: d.fromMarkdown,\n mdxJsx: d.mdxJsx,\n mdxJsxFromMarkdown: d.mdxJsxFromMarkdown,\n gfm: d.gfm,\n gfmFromMarkdown: d.gfmFromMarkdown,\n remarkAdmonitions: d.remarkAdmonitions,\n remarkWikiLinks: d.remarkWikiLinks,\n remarkHeadingAnchors: d.remarkHeadingAnchors,\n } as Deps;\n });\n }\n return depsPromise;\n}\n\nexport interface ParseSafeMdastOptions {\n /** `false` ⇒ headings use plain text-slug ids (the R3-186 base; no `sec-…` section\n * ids, no `data-slug`) — the `sectionIds:false` frontmatter opt-out, matching the\n * compiled path. Default (undefined/true) ⇒ section-like headings get `sec-…` ids\n * (R3-211). */\n sectionIds?: boolean;\n}\n\n/**\n * Parse untrusted Markdown/MDX-syntax source to an mdast tree with **no evaluator in\n * the pipeline**: JSX-as-data (no acorn), GFM on, the expression extension OFF, no\n * raw-HTML re-parse. The returned tree is safe to hand to `renderMdast` — expression\n * attributes are inert strings and raw HTML is inert `html` nodes.\n *\n * After the no-acorn parse it runs the SHARED kernel remark plugins — in the SAME order\n * as the compiled path's `compile.ts` (admonitions §12 → wiki-links §13 → heading/section\n * anchors §15/R3-211; GFM is already applied via the micromark extension above) — so the\n * safe subset renders identically in both standards. The plugins only emit element nodes\n * with LITERAL attributes and set `data.hProperties.id` on headings; they add no evaluator\n * and no acorn, preserving the §5.1 fail-safe.\n */\nexport async function parseSafeMdast(source: string, options: ParseSafeMdastOptions = {}): Promise<SafeMdastNode> {\n const {\n fromMarkdown,\n mdxJsx,\n mdxJsxFromMarkdown,\n gfm,\n gfmFromMarkdown,\n remarkAdmonitions,\n remarkWikiLinks,\n remarkHeadingAnchors,\n } = await loadDeps();\n const tree = fromMarkdown(source, {\n // `mdxJsx()` WITHOUT an acorn option → JSX tags + literal attrs; expressions are\n // raw strings, never estree. The mdx *expression* extension is intentionally\n // absent, so `{…}` in body text stays literal. GFM for tables/task-lists.\n extensions: [mdxJsx(), gfm()],\n mdastExtensions: [mdxJsxFromMarkdown(), gfmFromMarkdown()],\n });\n // The SHARED kernel remark plugins, in the SAME order as the compiled path's `compile.ts`\n // (admonitions §12 → wiki-links §13 → heading/section anchors §15/R3-211).\n remarkAdmonitions()(tree);\n remarkWikiLinks()(tree);\n remarkHeadingAnchors({ sectionIds: options.sectionIds !== false })(tree);\n return tree;\n}\n"],"mappings":";AA4EA,IAAI,cAAoC;AAExC,SAAS,WAA0B;AACjC,MAAI,CAAC,aAAa;AAIhB,kBAAc,OAAO,aAAa,EAAE,KAAK,CAAC,MAAM;AAC9C,YAAM,IAAI;AACV,aAAO;AAAA,QACL,cAAc,EAAE;AAAA,QAChB,QAAQ,EAAE;AAAA,QACV,oBAAoB,EAAE;AAAA,QACtB,KAAK,EAAE;AAAA,QACP,iBAAiB,EAAE;AAAA,QACnB,mBAAmB,EAAE;AAAA,QACrB,iBAAiB,EAAE;AAAA,QACnB,sBAAsB,EAAE;AAAA,MAC1B;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO;AACT;AAuBA,eAAsB,eAAe,QAAgB,UAAiC,CAAC,GAA2B;AAChH,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,MAAM,SAAS;AACnB,QAAM,OAAO,aAAa,QAAQ;AAAA;AAAA;AAAA;AAAA,IAIhC,YAAY,CAAC,OAAO,GAAG,IAAI,CAAC;AAAA,IAC5B,iBAAiB,CAAC,mBAAmB,GAAG,gBAAgB,CAAC;AAAA,EAC3D,CAAC;AAGD,oBAAkB,EAAE,IAAI;AACxB,kBAAgB,EAAE,IAAI;AACtB,uBAAqB,EAAE,YAAY,QAAQ,eAAe,MAAM,CAAC,EAAE,IAAI;AACvE,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/safeContent/parseSafeMdast.ts"],"sourcesContent":["// R3-279 (phase 3): re-export shim — the implementation lives in\n// `@immediately-run/safe-content`; this subpath keeps working byte-compatibly.\nexport { parseSafeMdast } from '@immediately-run/safe-content';\nexport type { SafeMdastNode, SafeMdxAttribute, ParseSafeMdastOptions } from '@immediately-run/safe-content';\n"],"mappings":";AAEA,SAAS,sBAAsB;","names":[]}
@@ -18,141 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var renderMdast_exports = {};
20
20
  __export(renderMdast_exports, {
21
- renderMdast: () => renderMdast
21
+ renderMdast: () => import_safe_content.renderMdast
22
22
  });
23
23
  module.exports = __toCommonJS(renderMdast_exports);
24
- var import_react = require("react");
25
- var import_sanitizeUrl = require("./sanitizeUrl");
26
- var import_wikilink = require("./wikilink");
27
- var import_linkSpace = require("../linkSpace");
28
- function literalProps(attributes) {
29
- const props = {};
30
- for (const attr of attributes ?? []) {
31
- if (attr.type !== "mdxJsxAttribute") continue;
32
- if (typeof attr.name !== "string") continue;
33
- if (typeof attr.value === "string") props[attr.name] = attr.value;
34
- else if (attr.value === null || attr.value === void 0) props[attr.name] = "";
35
- }
36
- return props;
37
- }
38
- let keyCounter = 0;
39
- const nextKey = () => `sc-${keyCounter++}`;
40
- function elementFor(tag, components) {
41
- return components?.[tag] ?? tag;
42
- }
43
- function renderWiki(token, opts) {
44
- const label = token.label ?? token.target;
45
- if ((0, import_linkSpace.resolveLinkTarget)(token.target).state === "invalid") return label;
46
- const href = opts.resolveWikiLink?.(token.target);
47
- const safe = href !== void 0 ? (0, import_sanitizeUrl.sanitizeUrl)(href) : void 0;
48
- if (safe === void 0) return label;
49
- return (0, import_react.createElement)(
50
- elementFor("a", opts.components),
51
- { href: safe, "data-wikilink": token.target, key: nextKey() },
52
- label
53
- );
54
- }
55
- function renderText(value, opts) {
56
- const parts = (0, import_wikilink.splitWikiLinks)(value);
57
- if (!parts) return value;
58
- return parts.map(
59
- (p, i) => "text" in p ? (0, import_react.createElement)(import_react.Fragment, { key: `t${i}` }, p.text) : (0, import_react.createElement)(import_react.Fragment, { key: `w${i}` }, renderWiki(p.wiki, opts))
60
- );
61
- }
62
- function renderChildren(node, opts) {
63
- return (node.children ?? []).map((c, i) => renderNode(c, opts, i));
64
- }
65
- const HEADING_TAGS = ["h1", "h2", "h3", "h4", "h5", "h6"];
66
- function renderNode(node, opts, index = 0) {
67
- const key = `n${index}`;
68
- switch (node.type) {
69
- case "root":
70
- return (0, import_react.createElement)(import_react.Fragment, { key }, ...renderChildren(node, opts));
71
- case "text":
72
- return renderText(node.value ?? "", opts);
73
- case "paragraph":
74
- return (0, import_react.createElement)("p", { key }, ...renderChildren(node, opts));
75
- case "heading": {
76
- const tag = HEADING_TAGS[Math.min(Math.max((node.depth ?? 1) - 1, 0), 5)];
77
- const hp = node.data?.hProperties;
78
- const headingProps = {};
79
- if (typeof hp?.id === "string") headingProps.id = hp.id;
80
- if (typeof hp?.["data-slug"] === "string") headingProps["data-slug"] = hp["data-slug"];
81
- return (0, import_react.createElement)(tag, { key, ...headingProps }, ...renderChildren(node, opts));
82
- }
83
- case "strong":
84
- return (0, import_react.createElement)("strong", { key }, ...renderChildren(node, opts));
85
- case "emphasis":
86
- return (0, import_react.createElement)("em", { key }, ...renderChildren(node, opts));
87
- case "delete":
88
- return (0, import_react.createElement)("del", { key }, ...renderChildren(node, opts));
89
- case "inlineCode":
90
- return (0, import_react.createElement)("code", { key }, node.value ?? "");
91
- case "code":
92
- return (0, import_react.createElement)("pre", { key }, (0, import_react.createElement)("code", null, node.value ?? ""));
93
- case "blockquote":
94
- return (0, import_react.createElement)("blockquote", { key }, ...renderChildren(node, opts));
95
- case "list":
96
- return (0, import_react.createElement)(node.ordered ? "ol" : "ul", { key }, ...renderChildren(node, opts));
97
- case "listItem":
98
- return (0, import_react.createElement)("li", { key }, ...renderChildren(node, opts));
99
- case "thematicBreak":
100
- return (0, import_react.createElement)("hr", { key });
101
- case "break":
102
- return (0, import_react.createElement)("br", { key });
103
- case "link": {
104
- const href = (0, import_sanitizeUrl.sanitizeUrl)(node.url);
105
- if (href === void 0) return (0, import_react.createElement)(import_react.Fragment, { key }, ...renderChildren(node, opts));
106
- return (0, import_react.createElement)(
107
- elementFor("a", opts.components),
108
- { key, href, title: node.title ?? void 0 },
109
- ...renderChildren(node, opts)
110
- );
111
- }
112
- case "image": {
113
- const src = (0, import_sanitizeUrl.sanitizeUrl)(node.url);
114
- if (src === void 0) return node.alt ? (0, import_react.createElement)(import_react.Fragment, { key }, node.alt) : null;
115
- return (0, import_react.createElement)(elementFor("img", opts.components), {
116
- key,
117
- src,
118
- alt: node.alt ?? "",
119
- title: node.title ?? void 0
120
- });
121
- }
122
- // GFM tables.
123
- case "table":
124
- return (0, import_react.createElement)("table", { key }, (0, import_react.createElement)("tbody", null, ...renderChildren(node, opts)));
125
- case "tableRow":
126
- return (0, import_react.createElement)("tr", { key }, ...renderChildren(node, opts));
127
- case "tableCell":
128
- return (0, import_react.createElement)("td", { key }, ...renderChildren(node, opts));
129
- // Raw HTML (`<script>`, `<div onclick>` at block level) → INERT TEXT. No
130
- // `rehype-raw`, never `dangerouslySetInnerHTML`. The literal markup is shown, not run.
131
- case "html":
132
- return (0, import_react.createElement)(import_react.Fragment, { key }, node.value ?? "");
133
- // JSX `<Component/>` syntax → registry lookup by NAME, literal props only.
134
- case "mdxJsxFlowElement":
135
- case "mdxJsxTextElement": {
136
- const name = typeof node.name === "string" ? node.name : "";
137
- const Component = name ? opts.components?.[name] : void 0;
138
- const children = renderChildren(node, opts);
139
- if (!Component) return (0, import_react.createElement)(import_react.Fragment, { key }, ...children);
140
- return (0, import_react.createElement)(Component, { key, ...literalProps(node.attributes) }, ...children);
141
- }
142
- // Inert expression nodes (should not occur — expression extension is off — but be
143
- // defensive if a tree from elsewhere carries them): render nothing.
144
- case "mdxFlowExpression":
145
- case "mdxTextExpression":
146
- case "mdxjsEsm":
147
- return null;
148
- default:
149
- return node.children ? (0, import_react.createElement)(import_react.Fragment, { key }, ...renderChildren(node, opts)) : null;
150
- }
151
- }
152
- function renderMdast(tree, options = {}) {
153
- keyCounter = 0;
154
- return renderNode(tree, options);
155
- }
24
+ var import_safe_content = require("@immediately-run/safe-content");
156
25
  // Annotate the CommonJS export names for ESM import in node:
157
26
  0 && (module.exports = {
158
27
  renderMdast
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/safeContent/renderMdast.tsx"],"sourcesContent":["import { createElement, Fragment, type ReactNode } from 'react';\nimport { sanitizeUrl } from './sanitizeUrl';\nimport { splitWikiLinks, type WikiLinkToken } from './wikilink';\nimport { resolveLinkTarget } from '../linkSpace';\nimport type { SafeMdastNode, SafeMdxAttribute } from './parseSafeMdast';\n\n// The mdast→React renderer for the safe content path (TRUST_MODES_SPEC §5.1). PURE\n// and synchronous — it only reads `node.type` off an already-parsed tree, so it\n// carries no ESM dep and is exhaustively unit-testable. Every security property lives\n// here:\n//\n// - **JSX tags resolve ONLY to a component registry, by name.** A `<Component/>`\n// node becomes `registry[name]` with **literal string props only**; an unknown tag\n// renders its children inert (a Fragment, no element) — so author-written `<div\n// onclick=…>`, `<img onerror=…>`, `<script>` never become an intrinsic element with\n// attacker attributes. (Block-level raw HTML arrives as an `html` node, below.)\n// - **Expression attributes are dropped.** `f={fetch(\"/x\")}` / `{...spread}` are\n// `mdxJsxExpressionAttribute` or object-valued `mdxJsxAttribute`s — never passed to\n// a component, never evaluated. (There is also no evaluator to reach — parse used\n// no acorn.)\n// - **Raw HTML is inert text.** `html` nodes render as their literal string via a\n// text node — never `dangerouslySetInnerHTML` (no `rehype-raw`).\n// - **URL-scheme sanitizer** on every `link`/`image` URL (`sanitizeUrl`).\n// - **Wikilinks resolve in-mount only** via an injected resolver; the renderer never\n// fetches.\n\nexport interface SafeContentComponents {\n /** Safe components an app exposes to `<Component/>` syntax (host/app-provided).\n * Looked up by the JSX tag name; anything not here renders inert. */\n [tag: string]: React.ComponentType<Record<string, string>>;\n}\n\nexport interface RenderMdastOptions {\n /** The component registry for `<Component/>` syntax. Absent ⇒ all JSX tags inert. */\n components?: SafeContentComponents;\n /**\n * Resolve a wikilink target to an href, **within the granted mount only** — a pure,\n * synchronous, mount-scoped lookup that MUST NOT fetch or reach out of the mount.\n * Return `undefined` for an unresolvable/out-of-mount target (rendered as inert\n * text). Absent ⇒ every wikilink renders as inert text.\n */\n resolveWikiLink?: (target: string) => string | undefined;\n}\n\n/** Extract the literal string props of a JSX element — `mdxJsxAttribute`s whose value\n * is a plain string. Expression attributes (object value) and spreads are DROPPED. */\nfunction literalProps(attributes: SafeMdxAttribute[] | undefined): Record<string, string> {\n const props: Record<string, string> = {};\n for (const attr of attributes ?? []) {\n if (attr.type !== 'mdxJsxAttribute') continue; // drop `{...spread}`\n if (typeof attr.name !== 'string') continue;\n // A literal attribute's value is a string (or null → boolean-ish `true`). An\n // expression value is an object (`mdxJsxAttributeValueExpression`) — DROP it: it\n // is an inert raw string, never a real value, and must never reach a component.\n if (typeof attr.value === 'string') props[attr.name] = attr.value;\n else if (attr.value === null || attr.value === undefined) props[attr.name] = '';\n // object-valued (expression) → skipped\n }\n return props;\n}\n\nlet keyCounter = 0;\nconst nextKey = () => `sc-${keyCounter++}`;\n\n/**\n * The element to build for a link/image: the host's registered override when it has one,\n * else the intrinsic tag.\n *\n * **Why this is safe.** `components` is the HOST's registry — the same one `<Component/>`\n * syntax resolves against — never author input. An author cannot add to it or choose one\n * here, because the lookup is by a FIXED key (`'a'`/`'img'`), not by anything read out of\n * the document. The URL is still `sanitizeUrl`'d before it is handed over, and only props\n * this renderer controls are passed. The trust boundary is unchanged: author text still\n * reaches nothing but children and a sanitized URL.\n *\n * **Why it is needed.** Without it, a safe-rendered document's links are raw `<a href>`,\n * so a click performs a REAL navigation. Inside an app's sandboxed iframe that is fatal —\n * the frame navigates away from the app, and in a routed host app it dies with\n * `Failed to construct 'URL': Invalid URL`. Hosts route links through a component for\n * exactly this reason, and the compiled-MDX path has always honoured that component; the\n * safe path silently ignored it, so one document behaved differently on the two renderers.\n */\nfunction elementFor(tag: 'a' | 'img', components: RenderMdastOptions['components']): React.ElementType {\n return (components?.[tag] as React.ElementType) ?? tag;\n}\n\n/** Render a wikilink token via the in-mount resolver, or inert text when it can't\n * resolve (never a network call — resolution is the injected mount-scoped callback). */\nfunction renderWiki(token: WikiLinkToken, opts: RenderMdastOptions): ReactNode {\n const label = token.label ?? token.target;\n // R3-273: a malformed `$fs:` target (not mount-absolute — catches scheme\n // smuggling) is inert BEFORE the injected resolver ever sees it, so every\n // consumer fails closed identically. Consumers implement their resolver on the\n // same shared `resolveLinkTarget` for well-formed targets.\n if (resolveLinkTarget(token.target).state === 'invalid') return label;\n const href = opts.resolveWikiLink?.(token.target);\n const safe = href !== undefined ? sanitizeUrl(href) : undefined;\n if (safe === undefined) return label; // inert text — unresolved or out-of-mount\n return createElement(\n elementFor('a', opts.components),\n { href: safe, 'data-wikilink': token.target, key: nextKey() },\n label,\n );\n}\n\n/** Render a `text` node, splitting any `[[…]]` wikilinks out of it. */\nfunction renderText(value: string, opts: RenderMdastOptions): ReactNode {\n const parts = splitWikiLinks(value);\n if (!parts) return value;\n return parts.map((p, i) =>\n 'text' in p\n ? createElement(Fragment, { key: `t${i}` }, p.text)\n : createElement(Fragment, { key: `w${i}` }, renderWiki(p.wiki, opts)),\n );\n}\n\nfunction renderChildren(node: SafeMdastNode, opts: RenderMdastOptions): ReactNode[] {\n return (node.children ?? []).map((c, i) => renderNode(c, opts, i));\n}\n\n// Standard mdast block/inline nodes → a FIXED, safe React element. We control every\n// attribute; author input only reaches text content and (sanitized) URLs.\nconst HEADING_TAGS = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] as const;\n\nfunction renderNode(node: SafeMdastNode, opts: RenderMdastOptions, index = 0): ReactNode {\n const key = `n${index}`;\n switch (node.type) {\n case 'root':\n return createElement(Fragment, { key }, ...renderChildren(node, opts));\n case 'text':\n return renderText(node.value ?? '', opts);\n case 'paragraph':\n return createElement('p', { key }, ...renderChildren(node, opts));\n case 'heading': {\n const tag = HEADING_TAGS[Math.min(Math.max((node.depth ?? 1) - 1, 0), 5)];\n // R3-213: the no-acorn path has no hast stage, so the heading id the shared\n // `remarkHeadingAnchors` plugin sets via `data.hProperties.id` (+ the `data-slug`\n // fallback, R3-211) must be translated to React props HERE, or headings render\n // id-less and deep-linking (`#sec-8-9`) breaks in the safe path. These are\n // plugin-computed literal strings, not author input — safe to pass through.\n const hp = (node.data as { hProperties?: Record<string, unknown> } | undefined)?.hProperties;\n const headingProps: Record<string, string> = {};\n if (typeof hp?.id === 'string') headingProps.id = hp.id;\n if (typeof hp?.['data-slug'] === 'string') headingProps['data-slug'] = hp['data-slug'];\n return createElement(tag, { key, ...headingProps }, ...renderChildren(node, opts));\n }\n case 'strong':\n return createElement('strong', { key }, ...renderChildren(node, opts));\n case 'emphasis':\n return createElement('em', { key }, ...renderChildren(node, opts));\n case 'delete':\n return createElement('del', { key }, ...renderChildren(node, opts));\n case 'inlineCode':\n return createElement('code', { key }, node.value ?? '');\n case 'code':\n return createElement('pre', { key }, createElement('code', null, node.value ?? ''));\n case 'blockquote':\n return createElement('blockquote', { key }, ...renderChildren(node, opts));\n case 'list':\n return createElement(node.ordered ? 'ol' : 'ul', { key }, ...renderChildren(node, opts));\n case 'listItem':\n return createElement('li', { key }, ...renderChildren(node, opts));\n case 'thematicBreak':\n return createElement('hr', { key });\n case 'break':\n return createElement('br', { key });\n case 'link': {\n const href = sanitizeUrl(node.url);\n // A rejected scheme → render the link TEXT only (inert), never an <a href>.\n if (href === undefined) return createElement(Fragment, { key }, ...renderChildren(node, opts));\n return createElement(\n elementFor('a', opts.components),\n { key, href, title: node.title ?? undefined },\n ...renderChildren(node, opts),\n );\n }\n case 'image': {\n const src = sanitizeUrl(node.url);\n if (src === undefined) return node.alt ? createElement(Fragment, { key }, node.alt) : null;\n return createElement(elementFor('img', opts.components), {\n key,\n src,\n alt: node.alt ?? '',\n title: node.title ?? undefined,\n });\n }\n // GFM tables.\n case 'table':\n return createElement('table', { key }, createElement('tbody', null, ...renderChildren(node, opts)));\n case 'tableRow':\n return createElement('tr', { key }, ...renderChildren(node, opts));\n case 'tableCell':\n return createElement('td', { key }, ...renderChildren(node, opts));\n // Raw HTML (`<script>`, `<div onclick>` at block level) → INERT TEXT. No\n // `rehype-raw`, never `dangerouslySetInnerHTML`. The literal markup is shown, not run.\n case 'html':\n return createElement(Fragment, { key }, node.value ?? '');\n // JSX `<Component/>` syntax → registry lookup by NAME, literal props only.\n case 'mdxJsxFlowElement':\n case 'mdxJsxTextElement': {\n const name = typeof node.name === 'string' ? node.name : '';\n const Component = name ? opts.components?.[name] : undefined;\n const children = renderChildren(node, opts);\n // Unknown tag (not in the registry) OR a fragment `<>` → render children inert,\n // NO element, NO author attributes. This is what neutralizes `<script>`/`<div\n // onclick>`/`<img onerror>` written as JSX.\n if (!Component) return createElement(Fragment, { key }, ...children);\n return createElement(Component, { key, ...literalProps(node.attributes) }, ...children);\n }\n // Inert expression nodes (should not occur — expression extension is off — but be\n // defensive if a tree from elsewhere carries them): render nothing.\n case 'mdxFlowExpression':\n case 'mdxTextExpression':\n case 'mdxjsEsm':\n return null;\n default:\n // Unknown node → render its children (never its raw value as markup).\n return node.children ? createElement(Fragment, { key }, ...renderChildren(node, opts)) : null;\n }\n}\n\n/**\n * Render a safe-parsed mdast tree to React. Pure and synchronous; carries every §5.1\n * security property (registry-only JSX, dropped expressions, inert raw HTML, URL\n * sanitizing, in-mount wikilinks). Feed it a tree from {@link parseSafeMdast}.\n */\nexport function renderMdast(tree: SafeMdastNode, options: RenderMdastOptions = {}): ReactNode {\n keyCounter = 0;\n return renderNode(tree, options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAwD;AACxD,yBAA4B;AAC5B,sBAAmD;AACnD,uBAAkC;AA2ClC,SAAS,aAAa,YAAoE;AACxF,QAAM,QAAgC,CAAC;AACvC,aAAW,QAAQ,cAAc,CAAC,GAAG;AACnC,QAAI,KAAK,SAAS,kBAAmB;AACrC,QAAI,OAAO,KAAK,SAAS,SAAU;AAInC,QAAI,OAAO,KAAK,UAAU,SAAU,OAAM,KAAK,IAAI,IAAI,KAAK;AAAA,aACnD,KAAK,UAAU,QAAQ,KAAK,UAAU,OAAW,OAAM,KAAK,IAAI,IAAI;AAAA,EAE/E;AACA,SAAO;AACT;AAEA,IAAI,aAAa;AACjB,MAAM,UAAU,MAAM,MAAM,YAAY;AAoBxC,SAAS,WAAW,KAAkB,YAAiE;AACrG,SAAQ,aAAa,GAAG,KAA2B;AACrD;AAIA,SAAS,WAAW,OAAsB,MAAqC;AAC7E,QAAM,QAAQ,MAAM,SAAS,MAAM;AAKnC,UAAI,oCAAkB,MAAM,MAAM,EAAE,UAAU,UAAW,QAAO;AAChE,QAAM,OAAO,KAAK,kBAAkB,MAAM,MAAM;AAChD,QAAM,OAAO,SAAS,aAAY,gCAAY,IAAI,IAAI;AACtD,MAAI,SAAS,OAAW,QA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AA;AAAA,IAGA,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,IACT;AAEE,aAAO,KAAK,eAAW,4BAAc,uBAAU,EAAE,IAAI,GAAG,GAAG,eAAe,MAAM,IAAI,CAAC,IAAI;AAAA,EAC7F;AACF;AAOO,SAAS,YAAY,MAAqB,UAA8B,CAAC,GAAc;AAC5F,eAAa;AACb,SAAO,WAAW,MAAM,OAAO;AACjC;","names":[]}
1
+ {"version":3,"sources":["../../src/safeContent/renderMdast.tsx"],"sourcesContent":["// R3-279 (phase 3): re-export shim — the implementation lives in\n// `@immediately-run/safe-content`; this subpath keeps working byte-compatibly.\nexport { renderMdast } from '@immediately-run/safe-content';\nexport type { RenderMdastOptions, SafeContentComponents } from '@immediately-run/safe-content';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,0BAA4B;","names":[]}
@@ -1,27 +1 @@
1
- import { ReactNode } from 'react';
2
- import { SafeMdastNode } from './parseSafeMdast.cjs';
3
-
4
- interface SafeContentComponents {
5
- /** Safe components an app exposes to `<Component/>` syntax (host/app-provided).
6
- * Looked up by the JSX tag name; anything not here renders inert. */
7
- [tag: string]: React.ComponentType<Record<string, string>>;
8
- }
9
- interface RenderMdastOptions {
10
- /** The component registry for `<Component/>` syntax. Absent ⇒ all JSX tags inert. */
11
- components?: SafeContentComponents;
12
- /**
13
- * Resolve a wikilink target to an href, **within the granted mount only** — a pure,
14
- * synchronous, mount-scoped lookup that MUST NOT fetch or reach out of the mount.
15
- * Return `undefined` for an unresolvable/out-of-mount target (rendered as inert
16
- * text). Absent ⇒ every wikilink renders as inert text.
17
- */
18
- resolveWikiLink?: (target: string) => string | undefined;
19
- }
20
- /**
21
- * Render a safe-parsed mdast tree to React. Pure and synchronous; carries every §5.1
22
- * security property (registry-only JSX, dropped expressions, inert raw HTML, URL
23
- * sanitizing, in-mount wikilinks). Feed it a tree from {@link parseSafeMdast}.
24
- */
25
- declare function renderMdast(tree: SafeMdastNode, options?: RenderMdastOptions): ReactNode;
26
-
27
- export { type RenderMdastOptions, type SafeContentComponents, renderMdast };
1
+ export { RenderMdastOptions, SafeContentComponents, renderMdast } from '@immediately-run/safe-content';
@@ -1,27 +1 @@
1
- import { ReactNode } from 'react';
2
- import { SafeMdastNode } from './parseSafeMdast.js';
3
-
4
- interface SafeContentComponents {
5
- /** Safe components an app exposes to `<Component/>` syntax (host/app-provided).
6
- * Looked up by the JSX tag name; anything not here renders inert. */
7
- [tag: string]: React.ComponentType<Record<string, string>>;
8
- }
9
- interface RenderMdastOptions {
10
- /** The component registry for `<Component/>` syntax. Absent ⇒ all JSX tags inert. */
11
- components?: SafeContentComponents;
12
- /**
13
- * Resolve a wikilink target to an href, **within the granted mount only** — a pure,
14
- * synchronous, mount-scoped lookup that MUST NOT fetch or reach out of the mount.
15
- * Return `undefined` for an unresolvable/out-of-mount target (rendered as inert
16
- * text). Absent ⇒ every wikilink renders as inert text.
17
- */
18
- resolveWikiLink?: (target: string) => string | undefined;
19
- }
20
- /**
21
- * Render a safe-parsed mdast tree to React. Pure and synchronous; carries every §5.1
22
- * security property (registry-only JSX, dropped expressions, inert raw HTML, URL
23
- * sanitizing, in-mount wikilinks). Feed it a tree from {@link parseSafeMdast}.
24
- */
25
- declare function renderMdast(tree: SafeMdastNode, options?: RenderMdastOptions): ReactNode;
26
-
27
- export { type RenderMdastOptions, type SafeContentComponents, renderMdast };
1
+ export { RenderMdastOptions, SafeContentComponents, renderMdast } from '@immediately-run/safe-content';
@@ -1,136 +1,5 @@
1
1
  import "../chunk-VHAA22YE.js";
2
- import { createElement, Fragment } from "react";
3
- import { sanitizeUrl } from "./sanitizeUrl";
4
- import { splitWikiLinks } from "./wikilink";
5
- import { resolveLinkTarget } from "../linkSpace";
6
- function literalProps(attributes) {
7
- const props = {};
8
- for (const attr of attributes ?? []) {
9
- if (attr.type !== "mdxJsxAttribute") continue;
10
- if (typeof attr.name !== "string") continue;
11
- if (typeof attr.value === "string") props[attr.name] = attr.value;
12
- else if (attr.value === null || attr.value === void 0) props[attr.name] = "";
13
- }
14
- return props;
15
- }
16
- let keyCounter = 0;
17
- const nextKey = () => `sc-${keyCounter++}`;
18
- function elementFor(tag, components) {
19
- return components?.[tag] ?? tag;
20
- }
21
- function renderWiki(token, opts) {
22
- const label = token.label ?? token.target;
23
- if (resolveLinkTarget(token.target).state === "invalid") return label;
24
- const href = opts.resolveWikiLink?.(token.target);
25
- const safe = href !== void 0 ? sanitizeUrl(href) : void 0;
26
- if (safe === void 0) return label;
27
- return createElement(
28
- elementFor("a", opts.components),
29
- { href: safe, "data-wikilink": token.target, key: nextKey() },
30
- label
31
- );
32
- }
33
- function renderText(value, opts) {
34
- const parts = splitWikiLinks(value);
35
- if (!parts) return value;
36
- return parts.map(
37
- (p, i) => "text" in p ? createElement(Fragment, { key: `t${i}` }, p.text) : createElement(Fragment, { key: `w${i}` }, renderWiki(p.wiki, opts))
38
- );
39
- }
40
- function renderChildren(node, opts) {
41
- return (node.children ?? []).map((c, i) => renderNode(c, opts, i));
42
- }
43
- const HEADING_TAGS = ["h1", "h2", "h3", "h4", "h5", "h6"];
44
- function renderNode(node, opts, index = 0) {
45
- const key = `n${index}`;
46
- switch (node.type) {
47
- case "root":
48
- return createElement(Fragment, { key }, ...renderChildren(node, opts));
49
- case "text":
50
- return renderText(node.value ?? "", opts);
51
- case "paragraph":
52
- return createElement("p", { key }, ...renderChildren(node, opts));
53
- case "heading": {
54
- const tag = HEADING_TAGS[Math.min(Math.max((node.depth ?? 1) - 1, 0), 5)];
55
- const hp = node.data?.hProperties;
56
- const headingProps = {};
57
- if (typeof hp?.id === "string") headingProps.id = hp.id;
58
- if (typeof hp?.["data-slug"] === "string") headingProps["data-slug"] = hp["data-slug"];
59
- return createElement(tag, { key, ...headingProps }, ...renderChildren(node, opts));
60
- }
61
- case "strong":
62
- return createElement("strong", { key }, ...renderChildren(node, opts));
63
- case "emphasis":
64
- return createElement("em", { key }, ...renderChildren(node, opts));
65
- case "delete":
66
- return createElement("del", { key }, ...renderChildren(node, opts));
67
- case "inlineCode":
68
- return createElement("code", { key }, node.value ?? "");
69
- case "code":
70
- return createElement("pre", { key }, createElement("code", null, node.value ?? ""));
71
- case "blockquote":
72
- return createElement("blockquote", { key }, ...renderChildren(node, opts));
73
- case "list":
74
- return createElement(node.ordered ? "ol" : "ul", { key }, ...renderChildren(node, opts));
75
- case "listItem":
76
- return createElement("li", { key }, ...renderChildren(node, opts));
77
- case "thematicBreak":
78
- return createElement("hr", { key });
79
- case "break":
80
- return createElement("br", { key });
81
- case "link": {
82
- const href = sanitizeUrl(node.url);
83
- if (href === void 0) return createElement(Fragment, { key }, ...renderChildren(node, opts));
84
- return createElement(
85
- elementFor("a", opts.components),
86
- { key, href, title: node.title ?? void 0 },
87
- ...renderChildren(node, opts)
88
- );
89
- }
90
- case "image": {
91
- const src = sanitizeUrl(node.url);
92
- if (src === void 0) return node.alt ? createElement(Fragment, { key }, node.alt) : null;
93
- return createElement(elementFor("img", opts.components), {
94
- key,
95
- src,
96
- alt: node.alt ?? "",
97
- title: node.title ?? void 0
98
- });
99
- }
100
- // GFM tables.
101
- case "table":
102
- return createElement("table", { key }, createElement("tbody", null, ...renderChildren(node, opts)));
103
- case "tableRow":
104
- return createElement("tr", { key }, ...renderChildren(node, opts));
105
- case "tableCell":
106
- return createElement("td", { key }, ...renderChildren(node, opts));
107
- // Raw HTML (`<script>`, `<div onclick>` at block level) → INERT TEXT. No
108
- // `rehype-raw`, never `dangerouslySetInnerHTML`. The literal markup is shown, not run.
109
- case "html":
110
- return createElement(Fragment, { key }, node.value ?? "");
111
- // JSX `<Component/>` syntax → registry lookup by NAME, literal props only.
112
- case "mdxJsxFlowElement":
113
- case "mdxJsxTextElement": {
114
- const name = typeof node.name === "string" ? node.name : "";
115
- const Component = name ? opts.components?.[name] : void 0;
116
- const children = renderChildren(node, opts);
117
- if (!Component) return createElement(Fragment, { key }, ...children);
118
- return createElement(Component, { key, ...literalProps(node.attributes) }, ...children);
119
- }
120
- // Inert expression nodes (should not occur — expression extension is off — but be
121
- // defensive if a tree from elsewhere carries them): render nothing.
122
- case "mdxFlowExpression":
123
- case "mdxTextExpression":
124
- case "mdxjsEsm":
125
- return null;
126
- default:
127
- return node.children ? createElement(Fragment, { key }, ...renderChildren(node, opts)) : null;
128
- }
129
- }
130
- function renderMdast(tree, options = {}) {
131
- keyCounter = 0;
132
- return renderNode(tree, options);
133
- }
2
+ import { renderMdast } from "@immediately-run/safe-content";
134
3
  export {
135
4
  renderMdast
136
5
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/safeContent/renderMdast.tsx"],"sourcesContent":["import { createElement, Fragment, type ReactNode } from 'react';\nimport { sanitizeUrl } from './sanitizeUrl';\nimport { splitWikiLinks, type WikiLinkToken } from './wikilink';\nimport { resolveLinkTarget } from '../linkSpace';\nimport type { SafeMdastNode, SafeMdxAttribute } from './parseSafeMdast';\n\n// The mdast→React renderer for the safe content path (TRUST_MODES_SPEC §5.1). PURE\n// and synchronous — it only reads `node.type` off an already-parsed tree, so it\n// carries no ESM dep and is exhaustively unit-testable. Every security property lives\n// here:\n//\n// - **JSX tags resolve ONLY to a component registry, by name.** A `<Component/>`\n// node becomes `registry[name]` with **literal string props only**; an unknown tag\n// renders its children inert (a Fragment, no element) — so author-written `<div\n// onclick=…>`, `<img onerror=…>`, `<script>` never become an intrinsic element with\n// attacker attributes. (Block-level raw HTML arrives as an `html` node, below.)\n// - **Expression attributes are dropped.** `f={fetch(\"/x\")}` / `{...spread}` are\n// `mdxJsxExpressionAttribute` or object-valued `mdxJsxAttribute`s — never passed to\n// a component, never evaluated. (There is also no evaluator to reach — parse used\n// no acorn.)\n// - **Raw HTML is inert text.** `html` nodes render as their literal string via a\n// text node — never `dangerouslySetInnerHTML` (no `rehype-raw`).\n// - **URL-scheme sanitizer** on every `link`/`image` URL (`sanitizeUrl`).\n// - **Wikilinks resolve in-mount only** via an injected resolver; the renderer never\n// fetches.\n\nexport interface SafeContentComponents {\n /** Safe components an app exposes to `<Component/>` syntax (host/app-provided).\n * Looked up by the JSX tag name; anything not here renders inert. */\n [tag: string]: React.ComponentType<Record<string, string>>;\n}\n\nexport interface RenderMdastOptions {\n /** The component registry for `<Component/>` syntax. Absent ⇒ all JSX tags inert. */\n components?: SafeContentComponents;\n /**\n * Resolve a wikilink target to an href, **within the granted mount only** — a pure,\n * synchronous, mount-scoped lookup that MUST NOT fetch or reach out of the mount.\n * Return `undefined` for an unresolvable/out-of-mount target (rendered as inert\n * text). Absent ⇒ every wikilink renders as inert text.\n */\n resolveWikiLink?: (target: string) => string | undefined;\n}\n\n/** Extract the literal string props of a JSX element — `mdxJsxAttribute`s whose value\n * is a plain string. Expression attributes (object value) and spreads are DROPPED. */\nfunction literalProps(attributes: SafeMdxAttribute[] | undefined): Record<string, string> {\n const props: Record<string, string> = {};\n for (const attr of attributes ?? []) {\n if (attr.type !== 'mdxJsxAttribute') continue; // drop `{...spread}`\n if (typeof attr.name !== 'string') continue;\n // A literal attribute's value is a string (or null → boolean-ish `true`). An\n // expression value is an object (`mdxJsxAttributeValueExpression`) — DROP it: it\n // is an inert raw string, never a real value, and must never reach a component.\n if (typeof attr.value === 'string') props[attr.name] = attr.value;\n else if (attr.value === null || attr.value === undefined) props[attr.name] = '';\n // object-valued (expression) → skipped\n }\n return props;\n}\n\nlet keyCounter = 0;\nconst nextKey = () => `sc-${keyCounter++}`;\n\n/**\n * The element to build for a link/image: the host's registered override when it has one,\n * else the intrinsic tag.\n *\n * **Why this is safe.** `components` is the HOST's registry — the same one `<Component/>`\n * syntax resolves against — never author input. An author cannot add to it or choose one\n * here, because the lookup is by a FIXED key (`'a'`/`'img'`), not by anything read out of\n * the document. The URL is still `sanitizeUrl`'d before it is handed over, and only props\n * this renderer controls are passed. The trust boundary is unchanged: author text still\n * reaches nothing but children and a sanitized URL.\n *\n * **Why it is needed.** Without it, a safe-rendered document's links are raw `<a href>`,\n * so a click performs a REAL navigation. Inside an app's sandboxed iframe that is fatal —\n * the frame navigates away from the app, and in a routed host app it dies with\n * `Failed to construct 'URL': Invalid URL`. Hosts route links through a component for\n * exactly this reason, and the compiled-MDX path has always honoured that component; the\n * safe path silently ignored it, so one document behaved differently on the two renderers.\n */\nfunction elementFor(tag: 'a' | 'img', components: RenderMdastOptions['components']): React.ElementType {\n return (components?.[tag] as React.ElementType) ?? tag;\n}\n\n/** Render a wikilink token via the in-mount resolver, or inert text when it can't\n * resolve (never a network call — resolution is the injected mount-scoped callback). */\nfunction renderWiki(token: WikiLinkToken, opts: RenderMdastOptions): ReactNode {\n const label = token.label ?? token.target;\n // R3-273: a malformed `$fs:` target (not mount-absolute — catches scheme\n // smuggling) is inert BEFORE the injected resolver ever sees it, so every\n // consumer fails closed identically. Consumers implement their resolver on the\n // same shared `resolveLinkTarget` for well-formed targets.\n if (resolveLinkTarget(token.target).state === 'invalid') return label;\n const href = opts.resolveWikiLink?.(token.target);\n const safe = href !== undefined ? sanitizeUrl(href) : undefined;\n if (safe === undefined) return label; // inert text — unresolved or out-of-mount\n return createElement(\n elementFor('a', opts.components),\n { href: safe, 'data-wikilink': token.target, key: nextKey() },\n label,\n );\n}\n\n/** Render a `text` node, splitting any `[[…]]` wikilinks out of it. */\nfunction renderText(value: string, opts: RenderMdastOptions): ReactNode {\n const parts = splitWikiLinks(value);\n if (!parts) return value;\n return parts.map((p, i) =>\n 'text' in p\n ? createElement(Fragment, { key: `t${i}` }, p.text)\n : createElement(Fragment, { key: `w${i}` }, renderWiki(p.wiki, opts)),\n );\n}\n\nfunction renderChildren(node: SafeMdastNode, opts: RenderMdastOptions): ReactNode[] {\n return (node.children ?? []).map((c, i) => renderNode(c, opts, i));\n}\n\n// Standard mdast block/inline nodes → a FIXED, safe React element. We control every\n// attribute; author input only reaches text content and (sanitized) URLs.\nconst HEADING_TAGS = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] as const;\n\nfunction renderNode(node: SafeMdastNode, opts: RenderMdastOptions, index = 0): ReactNode {\n const key = `n${index}`;\n switch (node.type) {\n case 'root':\n return createElement(Fragment, { key }, ...renderChildren(node, opts));\n case 'text':\n return renderText(node.value ?? '', opts);\n case 'paragraph':\n return createElement('p', { key }, ...renderChildren(node, opts));\n case 'heading': {\n const tag = HEADING_TAGS[Math.min(Math.max((node.depth ?? 1) - 1, 0), 5)];\n // R3-213: the no-acorn path has no hast stage, so the heading id the shared\n // `remarkHeadingAnchors` plugin sets via `data.hProperties.id` (+ the `data-slug`\n // fallback, R3-211) must be translated to React props HERE, or headings render\n // id-less and deep-linking (`#sec-8-9`) breaks in the safe path. These are\n // plugin-computed literal strings, not author input — safe to pass through.\n const hp = (node.data as { hProperties?: Record<string, unknown> } | undefined)?.hProperties;\n const headingProps: Record<string, string> = {};\n if (typeof hp?.id === 'string') headingProps.id = hp.id;\n if (typeof hp?.['data-slug'] === 'string') headingProps['data-slug'] = hp['data-slug'];\n return createElement(tag, { key, ...headingProps }, ...renderChildren(node, opts));\n }\n case 'strong':\n return createElement('strong', { key }, ...renderChildren(node, opts));\n case 'emphasis':\n return createElement('em', { key }, ...renderChildren(node, opts));\n case 'delete':\n return createElement('del', { key }, ...renderChildren(node, opts));\n case 'inlineCode':\n return createElement('code', { key }, node.value ?? '');\n case 'code':\n return createElement('pre', { key }, createElement('code', null, node.value ?? ''));\n case 'blockquote':\n return createElement('blockquote', { key }, ...renderChildren(node, opts));\n case 'list':\n return createElement(node.ordered ? 'ol' : 'ul', { key }, ...renderChildren(node, opts));\n case 'listItem':\n return createElement('li', { key }, ...renderChildren(node, opts));\n case 'thematicBreak':\n return createElement('hr', { key });\n case 'break':\n return createElement('br', { key });\n case 'link': {\n const href = sanitizeUrl(node.url);\n // A rejected scheme → render the link TEXT only (inert), never an <a href>.\n if (href === undefined) return createElement(Fragment, { key }, ...renderChildren(node, opts));\n return createElement(\n elementFor('a', opts.components),\n { key, href, title: node.title ?? undefined },\n ...renderChildren(node, opts),\n );\n }\n case 'image': {\n const src = sanitizeUrl(node.url);\n if (src === undefined) return node.alt ? createElement(Fragment, { key }, node.alt) : null;\n return createElement(elementFor('img', opts.components), {\n key,\n src,\n alt: node.alt ?? '',\n title: node.title ?? undefined,\n });\n }\n // GFM tables.\n case 'table':\n return createElement('table', { key }, createElement('tbody', null, ...renderChildren(node, opts)));\n case 'tableRow':\n return createElement('tr', { key }, ...renderChildren(node, opts));\n case 'tableCell':\n return createElement('td', { key }, ...renderChildren(node, opts));\n // Raw HTML (`<script>`, `<div onclick>` at block level) → INERT TEXT. No\n // `rehype-raw`, never `dangerouslySetInnerHTML`. The literal markup is shown, not run.\n case 'html':\n return createElement(Fragment, { key }, node.value ?? '');\n // JSX `<Component/>` syntax → registry lookup by NAME, literal props only.\n case 'mdxJsxFlowElement':\n case 'mdxJsxTextElement': {\n const name = typeof node.name === 'string' ? node.name : '';\n const Component = name ? opts.components?.[name] : undefined;\n const children = renderChildren(node, opts);\n // Unknown tag (not in the registry) OR a fragment `<>` → render children inert,\n // NO element, NO author attributes. This is what neutralizes `<script>`/`<div\n // onclick>`/`<img onerror>` written as JSX.\n if (!Component) return createElement(Fragment, { key }, ...children);\n return createElement(Component, { key, ...literalProps(node.attributes) }, ...children);\n }\n // Inert expression nodes (should not occur — expression extension is off — but be\n // defensive if a tree from elsewhere carries them): render nothing.\n case 'mdxFlowExpression':\n case 'mdxTextExpression':\n case 'mdxjsEsm':\n return null;\n default:\n // Unknown node → render its children (never its raw value as markup).\n return node.children ? createElement(Fragment, { key }, ...renderChildren(node, opts)) : null;\n }\n}\n\n/**\n * Render a safe-parsed mdast tree to React. Pure and synchronous; carries every §5.1\n * security property (registry-only JSX, dropped expressions, inert raw HTML, URL\n * sanitizing, in-mount wikilinks). Feed it a tree from {@link parseSafeMdast}.\n */\nexport function renderMdast(tree: SafeMdastNode, options: RenderMdastOptions = {}): ReactNode {\n keyCounter = 0;\n return renderNode(tree, options);\n}\n"],"mappings":";AAAA,SAAS,eAAe,gBAAgC;AACxD,SAAS,mBA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S,MAAM,GAAG,eAAe,MAAM,IAAI,CAAC,CAAC;AAAA,IACpG,KAAK;AACH,aAAO,cAAc,MAAM,EAAE,IAAI,GAAG,GAAG,eAAe,MAAM,IAAI,CAAC;AAAA,IACnE,KAAK;AACH,aAAO,cAAc,MAAM,EAAE,IAAI,GAAG,GAAG,eAAe,MAAM,IAAI,CAAC;AAAA;AAAA;AAAA,IAGnE,KAAK;AACH,aAAO,cAAc,UAAU,EAAE,IAAI,GAAG,KAAK,SAAS,EAAE;AAAA;AAAA,IAE1D,KAAK;AAAA,IACL,KAAK,qBAAqB;AACxB,YAAM,OAAO,OAAO,KAAK,SAAS,WAAW,KAAK,OAAO;AACzD,YAAM,YAAY,OAAO,KAAK,aAAa,IAAI,IAAI;AACnD,YAAM,WAAW,eAAe,MAAM,IAAI;AAI1C,UAAI,CAAC,UAAW,QAAO,cAAc,UAAU,EAAE,IAAI,GAAG,GAAG,QAAQ;AACnE,aAAO,cAAc,WAAW,EAAE,KAAK,GAAG,aAAa,KAAK,UAAU,EAAE,GAAG,GAAG,QAAQ;AAAA,IACxF;AAAA;AAAA;AAAA,IAGA,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,IACT;AAEE,aAAO,KAAK,WAAW,cAAc,UAAU,EAAE,IAAI,GAAG,GAAG,eAAe,MAAM,IAAI,CAAC,IAAI;AAAA,EAC7F;AACF;AAOO,SAAS,YAAY,MAAqB,UAA8B,CAAC,GAAc;AAC5F,eAAa;AACb,SAAO,WAAW,MAAM,OAAO;AACjC;","names":[]}
1
+ {"version":3,"sources":["../../src/safeContent/renderMdast.tsx"],"sourcesContent":["// R3-279 (phase 3): re-export shim — the implementation lives in\n// `@immediately-run/safe-content`; this subpath keeps working byte-compatibly.\nexport { renderMdast } from '@immediately-run/safe-content';\nexport type { RenderMdastOptions, SafeContentComponents } from '@immediately-run/safe-content';\n"],"mappings":";AAEA,SAAS,mBAAmB;","names":[]}
@@ -18,20 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var sanitizeUrl_exports = {};
20
20
  __export(sanitizeUrl_exports, {
21
- sanitizeUrl: () => sanitizeUrl
21
+ sanitizeUrl: () => import_safe_content.sanitizeUrl
22
22
  });
23
23
  module.exports = __toCommonJS(sanitizeUrl_exports);
24
- const SCHEME = /^([a-zA-Z][a-zA-Z0-9+.-]*):/;
25
- const ALLOWED_SCHEMES = /* @__PURE__ */ new Set(["http", "https", "mailto"]);
26
- const CONTROL_CHARS = /[\u0000-\u001F\u007F]/g;
27
- function sanitizeUrl(url) {
28
- if (typeof url !== "string") return void 0;
29
- const cleaned = url.replace(CONTROL_CHARS, "").trim();
30
- if (cleaned === "") return void 0;
31
- const m = SCHEME.exec(cleaned);
32
- if (!m) return cleaned;
33
- return ALLOWED_SCHEMES.has(m[1].toLowerCase()) ? cleaned : void 0;
34
- }
24
+ var import_safe_content = require("@immediately-run/safe-content");
35
25
  // Annotate the CommonJS export names for ESM import in node:
36
26
  0 && (module.exports = {
37
27
  sanitizeUrl
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/safeContent/sanitizeUrl.ts"],"sourcesContent":["// URL-scheme sanitizer for the safe content renderer (TRUST_MODES_SPEC §5.1,\n// AGENT_AUTHORING §10). A §5.1 residual requirement: link/image URLs in untrusted\n// content are allowlisted to `http`/`https`/`mailto` and relative URLs; every other\n// scheme — `javascript:`, `data:`, `vbscript:`, `file:`, … — is rejected. We do NOT\n// rely on React to neutralize `javascript:` (it does not, on an `<a href>`), so this\n// is the single chokepoint every rendered `href`/`src` passes through.\n\n// A leading `scheme:` per RFC 3986 (`ALPHA *( ALPHA / DIGIT / \"+\" / \"-\" / \".\" )`).\n// Anything before the first `:` that matches this is an absolute-URI scheme; if the\n// URL has no such prefix it is relative (path/query/fragment) and allowed.\nconst SCHEME = /^([a-zA-Z][a-zA-Z0-9+.-]*):/;\nconst ALLOWED_SCHEMES = new Set(['http', 'https', 'mailto']);\n\n// ASCII control chars (0x00–0x1F, 0x7F) that browsers ignore INSIDE a scheme — the\n// `java\\tscript:` / `java\\nscript:` obfuscation — stripped anywhere before testing.\n// eslint-disable-next-line no-control-regex\nconst CONTROL_CHARS = /[\\u0000-\\u001F\\u007F]/g;\n\n/**\n * Return the URL if its scheme is allowed (or it is relative/anchor), else\n * `undefined`. Control chars are stripped first so an obfuscated scheme cannot slip\n * past. A protocol-relative `//host` URL is treated as relative-with-authority and\n * allowed (it inherits the page's https scheme).\n */\nexport function sanitizeUrl(url: unknown): string | undefined {\n if (typeof url !== 'string') return undefined;\n const cleaned = url.replace(CONTROL_CHARS, '').trim();\n if (cleaned === '') return undefined;\n const m = SCHEME.exec(cleaned);\n if (!m) return cleaned; // no scheme → relative / anchor / query — allowed\n return ALLOWED_SCHEMES.has(m[1].toLowerCase()) ? cleaned : undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,MAAM,SAAS;AACf,MAAM,kBAAkB,oBAAI,IAAI,CAAC,QAAQ,SAAS,QAAQ,CAAC;AAK3D,MAAM,gBAAgB;AAQf,SAAS,YAAY,KAAkC;AAC5D,MAAI,OAAO,QAAQ,SAAU,QAAO;AACpC,QAAM,UAAU,IAAI,QAAQ,eAAe,EAAE,EAAE,KAAK;AACpD,MAAI,YAAY,GAAI,QAAO;AAC3B,QAAM,IAAI,OAAO,KAAK,OAAO;AAC7B,MAAI,CAAC,EAAG,QAAO;AACf,SAAO,gBAAgB,IAAI,EAAE,CAAC,EAAE,YAAY,CAAC,IAAI,UAAU;AAC7D;","names":[]}
1
+ {"version":3,"sources":["../../src/safeContent/sanitizeUrl.ts"],"sourcesContent":["// R3-279 (phase 3): re-export shim — the implementation lives in\n// `@immediately-run/safe-content`; this subpath keeps working byte-compatibly.\nexport { sanitizeUrl } from '@immediately-run/safe-content';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,0BAA4B;","names":[]}
@@ -1,9 +1 @@
1
- /**
2
- * Return the URL if its scheme is allowed (or it is relative/anchor), else
3
- * `undefined`. Control chars are stripped first so an obfuscated scheme cannot slip
4
- * past. A protocol-relative `//host` URL is treated as relative-with-authority and
5
- * allowed (it inherits the page's https scheme).
6
- */
7
- declare function sanitizeUrl(url: unknown): string | undefined;
8
-
9
- export { sanitizeUrl };
1
+ export { sanitizeUrl } from '@immediately-run/safe-content';