@izumisy/md-react-preview 0.1.0 → 0.1.1

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.
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @izumisy/md-react-preview
2
2
 
3
+ [![npm](https://img.shields.io/npm/v/@izumisy/md-react-preview)](https://www.npmjs.com/package/@izumisy/md-react-preview)
4
+
3
5
  CLI and programmatic API for md-react-preview — a zero-config component previewer for React projects.
4
6
 
5
7
  Drop Markdown files into `docs/` with `` ```tsx preview `` fenced blocks and get a Vite-powered dev server with live component previews and syntax-highlighted source code.
@@ -113,11 +113,17 @@ export function PreviewBlock({
113
113
  const initialColorScheme = useRef(colorScheme);
114
114
  useEffect(() => {
115
115
  if (colorScheme === initialColorScheme.current) return;
116
- iframeRef.current?.contentWindow?.postMessage({ type: "mrp-theme", theme: colorScheme }, "*");
116
+ // Security: specify origin instead of "*" to restrict postMessage recipients
117
+ iframeRef.current?.contentWindow?.postMessage(
118
+ { type: "mrp-theme", theme: colorScheme },
119
+ window.location.origin,
120
+ );
117
121
  }, [colorScheme]);
118
122
 
119
123
  useEffect(() => {
120
124
  function onMessage(e: MessageEvent) {
125
+ // Security: validate postMessage origin to prevent cross-origin message spoofing
126
+ if (e.origin !== window.location.origin) return;
121
127
  if (e.data?.type === "mrp-resize" && e.data?.blockId === blockId) {
122
128
  setIframeHeight(e.data.height);
123
129
  }
@@ -198,6 +204,14 @@ export function PreviewBlock({
198
204
  >
199
205
  <ExternalLinkIcon />
200
206
  </a>
207
+ {/*
208
+ Security note: no sandbox attribute is set on this iframe.
209
+ Preview blocks are authored by trusted developers (markdown authors),
210
+ and adding sandbox="allow-scripts" alone would break ES module loading
211
+ (CORS) and postMessage origin checks. Adding both allow-scripts and
212
+ allow-same-origin together provides no real security benefit for
213
+ same-origin iframes.
214
+ */}
201
215
  <iframe
202
216
  ref={iframeRef}
203
217
  src={previewUrl}
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { n as runPreview, r as startDev, t as runBuild } from "./server-C2ZxWhHj.mjs";
2
+ import { n as runPreview, r as startDev, t as runBuild } from "./server-CUf5QIH2.mjs";
3
3
  import { defineCommand, runMain } from "citty";
4
4
  import { loadConfig } from "c12";
5
5
  import fg from "fast-glob";
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { a as escapeJsString, c as DEFAULT_GLOB, i as createPreviewerViteConfig, l as defineConfig, n as runPreview, o as extractPreviewBlocks, r as startDev, s as hasPreviewBlocks, t as runBuild } from "./server-C2ZxWhHj.mjs";
1
+ import { a as escapeJsString, c as DEFAULT_GLOB, i as createPreviewerViteConfig, l as defineConfig, n as runPreview, o as extractPreviewBlocks, r as startDev, s as hasPreviewBlocks, t as runBuild } from "./server-CUf5QIH2.mjs";
2
2
  export { DEFAULT_GLOB, createPreviewerViteConfig, defineConfig, escapeJsString, extractPreviewBlocks, hasPreviewBlocks, runBuild, runPreview, startDev };
@@ -33,7 +33,7 @@ function extractPreviewBlocks(source) {
33
33
  return blocks;
34
34
  }
35
35
  function escapeJsString(s) {
36
- return s.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/\n/g, "\\n");
36
+ return s.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
37
37
  }
38
38
  /**
39
39
  * Check whether a source string contains ` ```tsx preview ` blocks.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@izumisy/md-react-preview",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "md-react-preview — component previewer powered by MDX",
5
5
  "bin": {
6
6
  "mrp": "./dist/cli.mjs"
@@ -16,9 +16,17 @@
16
16
  "default": "./dist/index.mjs"
17
17
  }
18
18
  },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/IzumiSy/md-react-preview",
22
+ "directory": "packages/md-react-preview"
23
+ },
19
24
  "keywords": [],
20
- "author": "",
21
- "license": "ISC",
25
+ "author": "IzumiSy",
26
+ "license": "MIT",
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
22
30
  "dependencies": {
23
31
  "@mdx-js/react": "^3.1.0",
24
32
  "@mdx-js/rollup": "^3.1.0",
@@ -35,7 +43,7 @@
35
43
  "remark-mdx-frontmatter": "^5.2.0",
36
44
  "shiki": "^4.0.2",
37
45
  "vite": "^6.3.5",
38
- "@izumisy/vite-plugin-react-preview": "0.1.0"
46
+ "@izumisy/vite-plugin-react-preview": "0.1.1"
39
47
  },
40
48
  "devDependencies": {
41
49
  "@types/node": "^22",