You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 9, 2026. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+20-1Lines changed: 20 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -292,7 +292,7 @@ export async function getStaticProps() {
292
292
293
293
This library exposes a function and a component, `serialize` and `<MDXRemote />`. These two are purposefully isolated into their own files -- `serialize` is intended to be run **server-side**, so within `getStaticProps`, which runs on the server/at build time. `<MDXRemote />` on the other hand is intended to be run on the client side, in the browser.
**`serialize`** consumes a string of MDX. It can also optionally be passed options which are [passed directly to MDX](https://mdxjs.com/docs/extending-mdx/), and a scope object that can be included in the MDX scope. The function returns an object that is intended to be passed into `<MDXRemote />` directly.
298
298
@@ -313,6 +313,13 @@ This library exposes a function and a component, `serialize` and `<MDXRemote />`
313
313
},
314
314
// Indicates whether or not to parse the frontmatter from the MDX source
315
315
parseFrontmatter: false,
316
+
// Block JavaScript expressions in MDX (e.g., {variable}, {func()})
317
+
// When true, these expressions are removed. Defaults to true.
318
+
blockJS: true,
319
+
// Provides a best effort option to block dangerous JavaScript when blockJS is false (JS is allowed).
320
+
// Prevents access to eval, Function, process, require, and other dangerous globals.
321
+
// Only applies when blockJS is false. Defaults to true for security.
322
+
blockDangerousJS: true,
316
323
}
317
324
)
318
325
```
@@ -383,6 +390,18 @@ This library evaluates a string of JavaScript on the client side, which is how i
383
390
384
391
If you have a CSP on your website that disallows code evaluation via `eval` or `new Function()`, you will need to loosen that restriction in order to utilize `next-mdx-remote`, which can be done using [`unsafe-eval`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#common_sources).
385
392
393
+
### JavaScript Expressions in MDX
394
+
395
+
By default, JavaScript expressions (like `{variable}` or `{func()}`) are **disabled for security** for versions 6.0.0 and above.
396
+
397
+
If you need to enable JavaScript expressions:
398
+
399
+
1.**Trusted content with protection (recommended)**: Set `blockJS: false` in serialize options. By default, `blockDangerousJS: true` is enabled, which will provide a best effort option to blocks dangerous operations like `eval`, `Function`, `process`, `require`, and other globals that could lead to remote code execution (RCE).
400
+
401
+
2.**Completely trusted content only**: Set both `blockJS: false` and `blockDangerousJS: false` to allow all JavaScript.
402
+
403
+
**Warning:** Only set `blockDangerousJS: false` if you completely trust the MDX content source. This removes critical security protections and could allow RCE attacks.
404
+
386
405
## TypeScript
387
406
388
407
This project does include native types for TypeScript use. Both `serialize` and `<MDXRemote />` have types normally as you'd expect, and the library also exports a type which you can use to type the result of `getStaticProps`.
0 commit comments