Apps
Islands and trust
An island is a piece of a page that JavaScript draws once the page has loaded. A page with no island is the static file it always was. This page says what runs where, what each kind of island can reach, and what is not stopped.
There are three kinds, by where the code can run:
Declarative. No JavaScript of yours: only Culm's own scripts run. The default, and what an agent produces.
In-page island. Your own module, running in the page. It is fully trusted, the same as the rest of the site's code.
Framed island. A module in a sandboxed frame with scripts allowed and nothing else. It is the default for an island that comes from a package.
Making an island
An island is two files in the project's islands/ folder, islands/<name>.js and islands/<name>.json. The name is 1 to 32 lower-case letters, digits and dashes, starting with a letter. The .js is read as text, never run by Culm and never judged for syntax. The descriptor holds:
budget: the most bytes the module may be, at most 20,000.
size: { h, w?, maxH? }. h is the height in pixels reserved before it mounts, so the page does not jump.
load: now, idle, visible or interact.
acts: optional. Things the module can be asked to do, each { name, description, class, input? }: see Acts.
settings, sources, persistent, guide: optional. sources are the live sources of the site its module may load.
A page draws one with a node { "kind": "island", "props": { "island": "<name>", "settings": { … } } }. Its children are the fallback, shown with scripts off, until the module mounts, and in place of the module if it throws. See islands/chart.js in the sample application for the shortest working one.
The module's default export is mount(el, settings, ctx). A function it returns runs when the page drops the island. A page that is built does not run a module at build time.
The module contract in the page
ctx is { get, set, load, on, size }:
ctx.get(name) and ctx.set(name, value) read and write site values. They do nothing on a page that has no live script, that is, a page with no live node, no live island source and no value it reads.
ctx.load(source, send?) loads a source the island declared in sources, with the visitor's key, and returns its rows. A source it did not declare is refused without a request. This is advisory for in-page code: see "In-page islands" below.
ctx.on('size' | 'visible', fn) and ctx.size ({ w, h, x, y, visible }, one live object).
Timing: now mounts at once; idle in an idle callback; visible when the element is within 200 pixels of the screen; interact on the first pointer-over, press, key or focus inside it (a hover counts). visible and interact defer only the mount. The module's file is loaded, and its top-level code runs, when the page loads.
How a module loads under the policy
Under a hash-only script-src, import() of a same-origin module is refused (measured, even with 'strict-dynamic'). So the compiler writes a
<script type="module" src="/_culm/islands/<name>.<8 hex>.js" integrity="sha256-…">tag for every island a page draws and lists each hash in the site policy; the islands script then import()s the same address, and the browser reuses the module the tag loaded. A module a page did not load as a tag is refused. Safari and Firefox have not been run on this; treat it as a Chromium result.
Module bytes count toward the page's appScripts ceiling of 12,000, with the live, navigation and islands scripts and every frame's runtime (live-data.md). In the sample application, the frame's module is 270 bytes and the chart is 651.
Acts
An in-page island can declare acts, which a page offers as tools with acts: ["name"] on the island node (actions.md). A framed island offers none.
"acts": [
{
"name": "highlight",
"description": "Highlight the bar of one row.",
"class": "page",
"input": [{ "key": "row", "label": "Row number, from 0", "type": "number" }]
}
]name follows the tool name grammar, description is plain text, names are unique in the island, class is read, page or send, and input is a list of settings of any type but link.
The event an island answers. The contract is below. The tool script of @culmjs/webmcp sends it when an offered act is called; a page's own code or a test can send it too.
new CustomEvent('culm-act', { cancelable: true, detail: { name, input, reply } }), dispatched on the island's element (the el of mount). It does not bubble.
The island acknowledges by calling preventDefault() during the dispatch. The tool script returns not-ready for an act nobody acknowledged: the island has not mounted (its load timing has not come, or its mount failed), or does not listen for it.
The first reply call wins.
The reply is JSON data. The tool script copies it through JSON, and returns null for one that cannot be copied.
An island adds its listener only once it can act, so a mount that fails acknowledges nothing. The sample chart adds it after the bars are drawn.
In-page islands
An in-page island is trusted code. It runs in the page's own context with the page's rights. It can read anything the page can read:
The key: from sessionStorage when the value is kept for the tab, by watching the sign-in form's password field, by replacing fetch or by calling __culm.load (which sends it), whatever ctx.load is told. A secret held for the view lives in the page's memory, but code in the page can still use it by making requests.
Every form field, every row on the page, every storage entry.
window.__culm. The sources list of an island and the ctx.load check are a convenience for honest code; they do not stop an in-page module that reaches for __culm directly.
It can also act as the visitor: make the requests the page can make, to the origins the policy allows.
So an in-page island is as safe as the person who wrote it. The files in the project's own islands/ folder are the person's, and run in the page. An island that comes from a package does not, unless a person says so (packages.md), and the build refuses run: "in-page" on an island from a package that is not trusted (on a page with sign-in, the message says why it matters; see packages.md).
Framed islands
A framed island's module runs in <iframe sandbox="allow-scripts" srcdoc="…">. The sandbox has no allow-same-origin, so the frame has an opaque origin and cannot reach the page, its storage, its cookies or its form fields. The frame document carries its own policy first (default-src 'none', its own script hash, no network), and the page's policy applies to it as well.
What it can do: receive its settings, the three colours of the look, and its size, and ask the page for rows of the sources it is granted. What it never gets: a site value, the key, the password, a cookie. A frame does not ask for rows with the key; the page's broker does, and hands over only the rows.
Grants
site.json grants is a list of { island, source }. A framed island may read exactly the sources granted to its own name, and only GET sources (a POST source cannot be granted). A grant is a person's decision: the default MCP guard refuses setGrants, a restore that changes the grants, and a setLiveSources that changes or removes a source that is granted (mcp.md). Declaring sources in an island's descriptor is not a grant.
The broker accepts only the two message shapes it knows, from a frame the compiler wrote, and answers a get for a granted source only if none for that source from that frame is in flight and the last answer was over a second ago. The rest get an error. A frame may therefore make one request a second for each source it is granted, and a module that asks 300 times in a burst makes one call.
What a framed island can still do
These are limits, stated plainly.
It can leak the rows it was granted. It has them, and it can tell them to whoever it can reach. Through the height it reports (a number the page accepts) and the time it takes, it can pass a message to the page; through anything it can still send, to the outside. A grant is a decision that the rows are the island's to see.
WebRTC is open: measured in Chromium with the test driver's two flags dropped; Safari and Firefox were not run. CSP has no directive for it and the sandbox does not remove it. A frame measured sending a STUN packet to a host of its choosing, which carries data in its host, port and credentials, and tells the host that the visitor is there and from which address. The repository's test driver launches Chromium with two flags that hide this (and DNS prefetch), so the driver does not see it; a visitor's Chromium has no such flags (other engines were not run). WebSocket, preconnect and dns-prefetch could not be shown under the driver; treat them as open too. This is accepted as a residual, and recorded as an owner item for the stage 5 exit. The frame is not patched: a replaced constructor is bypassed by a child about:blank document. Recipe and numbers: limits.md.
What leaks is what it was granted, never the token or the password. Nothing carries either into a frame; the test reads_password_field and reads_key asserts that no message the page sends a frame holds the token or the password, typed or after sign-in.
The frame script's hash also authorises that exact text in the top-level page. A srcdoc frame inherits the page's policy, so the hash of its script has to be in it, and a policy cannot say "only inside a frame". Only the module text the site already ships, with the runtime, has that hash.
Its top-level code runs at page load. loading="lazy" does not defer a srcdoc frame (measured). The island mounts, and asks for rows, only when the frame is within 200 pixels of the screen; its module's top level is not held back.
A frame that fails stays blank at its reserved height; it has no fallback in a built page.
What a framed module looks like
export default function mount(el, settings, ctx), standalone: no import, and the default export as export default <expression> or export { name as default } (a function declaration named elsewhere and used elsewhere breaks, because the compiler takes the export as var __m = …; an /u regular expression or a bare a<!--b in the module also breaks, and harms only that module). A module with no default export is refused at validation. Here el is the frame's body and ctx is { look, size, load(source), height(px), on('size', fn) }.
ctx.load(source) returns the rows. ctx.height(px) asks the page to make the frame taller; the page lets a frame grow, never shrink, to a cap of min(max(size.h, 900), maxH). That is the one channel a page can read, and it is how the sample application's test sees what a frame shows.
Persistent islands
persistent: true keeps an in-page island's element across an in-place page change, so it keeps its state. It is limited: no trigger on it or inside it, no live setting, no component use, not inside a repeating node, and one per name on a page. A framed island is never persistent (moving a frame reloads it); validation refuses it.
Bytes
The frame runtime is 714 bytes and counts once for each frame the page draws, with its own copy of the module's text: a page with three frames carries three copies of each, and all of it counts. A page with live, navigation, islands and one frame has 1,223 bytes left for every module on it. A frame that is granted a source needs the live script, so a page with one pays for it as well.
What is not measured
Safari and Firefox: the sandbox, policy inheritance, srcdoc handling, and module tags with integrity under a hash-only policy have been run in Chromium only. An owner item.
A frame reloaded after it started; a page with embeds (they add frame-src origins a frame could send itself to).
Anything beyond the tests in
packages/tools/__browser__/frame-attacks.spec.tsand cuj6.spec.ts. A safety property counts as established only when its test exists and passes; these two files are the tests.
Previous
Next