SSR + strict CSP for cached pages: let hydration data be inert so inline-script hashes are build-time constants (and streaming works under a hash-based CSP)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 8/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- html, javascript, typescript
Hướng nghiên cứu
This is a design proposal with no maintainer response yet, so decide scope with maintainers before coding. Start by reading the inline-script constants (REPLACE_SCRIPT, HEAD_SCRIPT, HydrationScript) and the renderToStream / renderToString entry points the issue names. Done means a failing test that shows which inline scripts change between renders, as the issue's first deliverable.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Problem. We run a Solid 2 storefront (rc.13, @solidjs/vite-plugin start mode) behind a
shared CDN cache, with a CSP that has no 'unsafe-inline'. Three facts collide:
- A nonce is unusable on a cached page. The stored response publishes its CSP header and its
<script nonce>attributes together, to every later visitor, for the whole cache lifetime. The
published constant becomes the grant. SvelteKit forbids nonces on prerendered pages for the
same reason, and Next.js documents that nonces force dynamic rendering and disable static, ISR
and CDN caching. - Hashes are the remaining mechanism, but Solid's inline scripts cannot be hashed ahead of
time.- Every script that carries hydration data is per render: the seroval cross-reference header,
the stub batch, the resolutions,$df("k"), head ops,window.location=. - The constant runtimes (
REPLACE_SCRIPT,HEAD_SCRIPT, seroval's promise-resolver factory)
are concatenated into the same element as that data. - Only
HydrationScriptis a standalone constant.
So a host must render, re-read the finished body, and hash the scripts. That only works with
the async render mode, where the head is sent after the body.
- Every script that carries hydration data is per render: the seroval cross-reference header,
- Streaming is impossible under a hash-based CSP. The header is gone before the late scripts
exist.
A side effect we measured: in async mode, the order of the resolution chunks (and their $R ids)
follows the order in which async sources settle. Identical data with different API latency gives
different bytes (12 renders, 2 variants), so a body-digest ETag misses revalidations that should
be 304s.
Proposals, ranked.
- Inert hydration data plus constant executable code (opt-in, for example
renderToStream(…, { dataMode: 'json' })):- Write every serialized record as
<script type="application/json" data-hy>using the JSON
codec@solidjs/web/serializationalready ships (createJSONSerializer/
createJSONDataTable). - Keep all executable bytes constant per build: the runtime in its own
<script>, or an
external module, and a fixed pump such as<script>_$HY.p()</script>after each flush. - Make the late redirect a
<meta http-equiv="refresh">or a data record. - Two details to handle: the decoder must stamp
p.s/p.von settled promises, as
PROMISE_SUCCESSdoes today, since hydration reads them synchronously; and seroval's
cross-JSON already resolves out-of-order promise nodes by id.
Result: CSP hashes are build-time constants (a static header, no body re-parse), and streaming
SSR works under a strict, hash-only CSP. The cost from our measurement is about 5% larger
payloads after compression and slower decode (0.7 vs 0.1 ms for a 120-product payload on a
laptop).
- Write every serialized record as
- Interim, small: the renderer records the SHA-256 of every inline script it writes and
exposes the set on the settled result (or the request event), for hosts that render in async
mode or withrenderToString. Authored<script>in JSX stays the app's job, since the
compiler bakes it into the template. - Determinism: in async mode, emit resolutions in a stable order (for example, by
serialization key at flush) rather than in settle order, so identical data gives identical
bytes.
Prior art.
- SvelteKit:
csp.mode: 'hash' | 'nonce' | 'auto'. The framework adds hashes or nonces for
the inline scripts and styles it generates.autouses hashes for prerendered pages and nonces
for dynamic ones, and "using nonces with prerendered pages is insecure and therefore forbidden". - Astro 6:
security.cspcomputes SHA-256 hashes of the page's scripts and styles and emits
them in a<meta http-equiv>policy. - Next.js: nonces only for inline scripts, which require dynamic rendering. Experimental SRI
covers external files only. - React Router / Remix and Qwik: nonce props only.
- SolidStart v2 already moved server-function payloads to seroval's JSON mode by default
(solid-start#2042, after #1825).
What we would contribute.
- A failing test for each claim above: the per-render inventory, and the settle-order variance.
- A prototype of (1) behind an option: the serializer switch, the pump and the decoder wrapper
that stampss/v. - Size and decode benchmarks on a real catalogue page.
- The docs section on running Solid behind a shared cache with a strict CSP.
We are happy to start with (2) or (3) if (1) is too large for 2.0.
- Ngôn ngữ chính
- TypeScript
- Star
- 36.1k
- Fork
- 1.1k
- Merge trung bình
- 11 giờ 49 phút
- Pull request đã merge (30 ngày)
- 346
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của solidjs/solid
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 18/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 55/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[2.0 / next] Error formatting and async iterator protocol failures escape memo error handlingĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 14/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của solidjs/solid
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 83/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ranxianglei/billion-context#3583 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug:new
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
callstackincubator/simlock#673 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation v3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
anomalyco/opencode#56380 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày