UNPKG

1.62 kBMarkdownView Raw
1---
2title: Security
3---
4
5# Security
6
7[MODES: framework]
8
9<br/>
10<br/>
11
12This is by no means a comprehensive guide, but React Router provides features to help address a few aspects under the _very large_ umbrella that is _Security_.
13
14## `Content-Security-Policy`
15
16If you are implementing a [Content-Security-Policy (CSP)][csp] in your application, specifically one using the `unsafe-inline` directive, you will need to specify a [`nonce`][nonce] attribute on the inline `<script>` elements rendered in your HTML.
17
18Add a nonce to these two spots in [`entry.server.tsx`][entryserver]:
19
20- The [`<ServerRouter nonce>`][serverrouter] prop
21 - This will be proxied along through React Context and used for other Framework Mode components that output `nonce`-aware elements, including [`<Scripts>`][scripts], [`<ScrollRestoration>`][scrollrestoration]
22 - If those components specify their own `nonce` prop, it will override the `ServerRouter` value
23- The `nonce` options of [`renderToPipeableStream`][renderToPipeableStream]/[`renderToReadableStream`][renderToReadableStream]
24
25[csp]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP
26[entryserver]: ../api/framework-conventions/entry.server.tsx
27[nonce]: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce
28[renderToPipeableStream]: https://react.dev/reference/react-dom/server/renderToPipeableStream
29[renderToReadableStream]: https://react.dev/reference/react-dom/server/renderToReadableStream
30[scripts]: ../api/components/Scripts
31[scrollrestoration]: ../api/components/ScrollRestoration
32[serverrouter]: ../api/framework-routers/ServerRouter