Subresource Integrity (SRI)
knitkit build computes a sha384 hash for each shared asset and records it in the manifest’s
integrity field:
- Node SSR
Limitation: exposed modules in the browser
Content Security Policy (CSP)
A federated page fetches modules and manifests from one or more remote origins. Your CSP must allow those origins explicitly. Here is a starting-point header — tighten the origin lists to exactly the CDN hostnames you use:- Import map nonce — the import map is a
<script type="importmap">inline tag. Under a strict CSP, allow it with a per-requestnonceattribute (e.g.<script type="importmap" nonce="abc123">). This is strongly preferred over'unsafe-inline', which would defeat inline-script protection for your entire page. connect-src— must include every origin from which youfetcha manifest or a module.registerRemotesandloadRemoteboth usefetchinternally; a missingconnect-srcentry silently blocks the request.- Prefer an allowlist over wildcards —
script-src 'self' https://cdn.example.comis significantly safer thanscript-src *. Each remote origin you add toscript-srcis a trust decision; make it explicit.
CORS
Remote servers must sendAccess-Control-Allow-Origin headers for three categories of
resources: manifests (knit.manifest.json), exposed module files, and shared asset files.
Without CORS headers, cross-origin fetch calls fail silently in the browser.
Configure your remote’s static host (CDN, object storage, or web server) to return:
* is acceptable:
registerRemotes and loadRemote fail with a coded KNIT_ERR_LOAD_FAILED error. The error
message includes a suggestion pointing at CORS configuration and reachability as the likely
cause.
CORS errors in the browser are opaque — the browser’s network tab shows a failed request but
does not expose the response body. If you see
KNIT_ERR_LOAD_FAILED, open the browser
console and check for a CORS policy message alongside the knitkit error.Trust model
Every remote origin you federate into your host executes JavaScript with your page’s full privileges — the same cookies, storage, DOM access, and CSP context as your own first-party code. Keep that in mind when making trust decisions:- Use HTTPS for all remote assets. HTTP origins are trivially intercepted; never federate over unencrypted connections.
- Pin hashes wherever the platform supports it. SRI on the import map catches CDN compromises and supply-chain attacks for shared dependencies.
- Scope your CSP to the smallest set of origins necessary. Each entry in
script-srcis an explicit grant of code-execution trust. - Only federate origins you control or have a contractual relationship with. A third-party CDN that serves one of your remotes is part of your trusted computing base. Vet it accordingly.
@knitkit/node.