@rsc-kit/mcp 0.30.54 → 0.31.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/dist/recipes.js +59 -1
- package/dist/recipes.js.map +1 -1
- package/guides/content-security-policy.md +119 -0
- package/guides/edge-caching.md +9 -0
- package/guides/index.json +5 -0
- package/guides/isr.md +3 -1
- package/guides/response-headers.md +5 -5
- package/package.json +2 -2
package/dist/recipes.js
CHANGED
|
@@ -710,7 +710,8 @@ not prerendered.
|
|
|
710
710
|
|
|
711
711
|
FOR AN EDGE THAT CACHES PAGES: rsc-kit implements the edge contract (v2,
|
|
712
712
|
docs: reference/edge-contract). Every server build writes .output/edge.json -
|
|
713
|
-
{ v: 2, build, shells, static, bypass }
|
|
713
|
+
{ v: 2, build, shells, static, bypass } (+ nonceShells under a
|
|
714
|
+
contentSecurityPolicy) - whose shells are url patterns ("/",
|
|
714
715
|
"/[team]/[app]", "/docs/[...slug]"), the ◐ pages, and whose static are
|
|
715
716
|
concrete paths, the ○ pages at the path each was rendered at: both less every
|
|
716
717
|
page with middleware (middleware.ts or the host's export const middleware) or
|
|
@@ -1672,6 +1673,63 @@ that strips framework identifiers; X-RSC-Kit stays. Do not strip X-RSC-Kit
|
|
|
1672
1673
|
at the proxy - it is what tells you whether a stored page was served.
|
|
1673
1674
|
|
|
1674
1675
|
Full guide: read_guide({ slug: 'response-headers' }).`,
|
|
1676
|
+
},
|
|
1677
|
+
{
|
|
1678
|
+
topic: 'content-security-policy',
|
|
1679
|
+
summary: 'A strict Content-Security-Policy on every page - rscKit({ contentSecurityPolicy }) adds each page\'s hashes, and a nonce where it streams',
|
|
1680
|
+
body: `\`\`\`ts title="vite.config.ts"
|
|
1681
|
+
rscKit({ contentSecurityPolicy: {} }) // strict default
|
|
1682
|
+
rscKit({
|
|
1683
|
+
contentSecurityPolicy: {
|
|
1684
|
+
directives: { 'default-src': ["'self'"], 'img-src': ["'self'", 'data:'], 'frame-ancestors': ["'none'"] },
|
|
1685
|
+
reportOnly: false, // true: Content-Security-Policy-Report-Only
|
|
1686
|
+
},
|
|
1687
|
+
})
|
|
1688
|
+
\`\`\`
|
|
1689
|
+
|
|
1690
|
+
{} is: default-src 'self'; base-uri 'self'; object-src 'none'; style-src-attr
|
|
1691
|
+
'unsafe-inline'. The engine adds a script-src and style-src naming the page's
|
|
1692
|
+
OWN inline code - the boot script, React's streaming scripts - so the policy
|
|
1693
|
+
needs no 'unsafe-inline'. How, by page:
|
|
1694
|
+
|
|
1695
|
+
- stored at build, or kept by revalidate: the hash of each inline script and
|
|
1696
|
+
style; no nonce, so caches still share it
|
|
1697
|
+
- a PPR shell: the shell's hashes plus a nonce for the holes resumed into it
|
|
1698
|
+
- rendered per request: a nonce, new per response, which React puts on every
|
|
1699
|
+
script it writes
|
|
1700
|
+
|
|
1701
|
+
The payload a page hydrates from is <script type="application/json"> data
|
|
1702
|
+
blocks: never run, never judged by the policy. A directive you wrote with
|
|
1703
|
+
'unsafe-inline' is left alone (a hash beside it would switch it off).
|
|
1704
|
+
|
|
1705
|
+
YOUR OWN inline code: a <script> or <style> in a stored page or shell is hashed
|
|
1706
|
+
and runs. One inside a <Suspense> hole, on a per-request page, or brought by a
|
|
1707
|
+
navigation is REFUSED - put CSS in a stylesheet and code in a module, or add
|
|
1708
|
+
'unsafe-inline' to style-src. Keep style-src-attr 'unsafe-inline': React's
|
|
1709
|
+
style={{...}} is an attribute, which no hash or nonce can allow.
|
|
1710
|
+
|
|
1711
|
+
Everywhere: Node, Bun, Docker, Workers, functions. A static export carries a
|
|
1712
|
+
<meta http-equiv="Content-Security-Policy"> per page (no frame-ancestors,
|
|
1713
|
+
report-uri, report-to, sandbox or report-only in a meta). An edge gets each
|
|
1714
|
+
static page's policy with its hashes. Under a policy edge.json moves the shells
|
|
1715
|
+
to nonceShells: an edge serves them only if it mints a nonce per response
|
|
1716
|
+
(Edge-Accept: nonce, the {edge-nonce} placeholder in the page's policy,
|
|
1717
|
+
Edge-Nonce on the resume); any other edge leaves them to the origin.
|
|
1718
|
+
|
|
1719
|
+
In vite dev the same policy is sent, plus 'unsafe-eval' (React's development
|
|
1720
|
+
build) and the dev server's origin when the page comes from another one. Every
|
|
1721
|
+
dev page renders per request, so it runs by nonce - Vite's CSS updates and
|
|
1722
|
+
error overlay included - and your own inline <script>/<style> is refused there
|
|
1723
|
+
even on a page the build stores. A refusal shows in dev first, never only in
|
|
1724
|
+
production. Never 'unsafe-eval' in a build.
|
|
1725
|
+
|
|
1726
|
+
Do NOT also put a Content-Security-Policy in rscKit({ headers }) - the build
|
|
1727
|
+
refuses both. Do NOT set a nonce policy in a middleware or in the backend in
|
|
1728
|
+
front (a Laravel CSP package): React never sees that nonce, so every streamed
|
|
1729
|
+
page is refused, and two policies are both enforced. A middleware that does set
|
|
1730
|
+
one keeps it, and the engine adds nothing.
|
|
1731
|
+
|
|
1732
|
+
Full guide: read_guide({ slug: 'content-security-policy' }).`,
|
|
1675
1733
|
},
|
|
1676
1734
|
{
|
|
1677
1735
|
topic: 'backend',
|