Reading and surfaces
The patch
A patch is { surface, from, v, css?, fonts?, nodes }.
surface is an id fixed for one createSurface instance.
v counts drawn states. It goes up on every batch or setData that changes the output, and it is separate from the document revision.
from: 0 marks a full state, so the first v is 1. A call that changes nothing returns from equal to v and no nodes.
nodes is keyed by each element's data-id, and '' is the root. Each entry has the tag, attributes and content in order: child ids, text, and inner elements that have no id.
css holds the CSS, and fonts the font faces, apart from the rest of the CSS. In a partial patch nodes, css and fonts hold only what changed. A full state holds everything.
The mount receives
It does
The mount receives
A full state from a new surface id
It does
Applies it
The mount receives
A full state from the shown id, v not older than shown
It does
Applies it
The mount receives
An older full state from the shown id
It does
Ignores it, returns true
The mount receives
A partial patch whose from is the shown v, same id
It does
Applies it
The mount receives
A partial patch already shown, same id
It does
Ignores it, returns true
The mount receives
Any other partial patch
It does
Returns false: send a snapshot
A full state is reconciled with the elements already there, so typed text survives it.
The mount
mountSurface(el, { onAction }) draws into a shadow root on el.
It sets display: block and contain: layout paint on el, inline with !important. destroy restores what was there.
css goes to the shadow root through adoptedStyleSheets.
fonts goes to a sheet on the product document, which destroy removes. Its face rules are built only from core's font catalogue and the product's fonts, with addresses under fontBase. A batch chooses which faces are used, never their text or address.
It never parses markup. Tags, attribute names and address schemes come from fixed lists. A patch outside them throws before anything changes.
An element is kept while its tag, type, field key and parent stay the same. The rest lose typed text and focus, and the browser may fire blur.
The focused element is not moved within its parent, but it can still move across inline wrappers.
Every submit is cancelled. A form with an action reports submit.
A link click is cancelled and reports goTo once with the absolute address. Every middle-button click (auxclick) on a link is cancelled, and only button 1 reports goTo. An address that URL refuses is cancelled and not reported. A click on an a with no href is not cancelled. Links and goTo triggers resolve against document.baseURI.
A second mountSurface on the same element takes it over.
view.patch returns true for a patch it applied or ignored, and false for a missed patch. It throws on a refused or malformed patch (the message starts "The patch ") and after destroy.
Security
A generating model chooses what a surface holds, and the surface runs inside the product's page. Each row has a passing test.
Threat
Control
Test
Threat
Generated UI injects markup or script
Control
Operations are validated. The mount never parses markup and accepts only listed tags, attribute names and address schemes
Test
packages/surface/__browser__/surface.spec.ts: security: injected markup and script are refused.
packages/surface/__browser__/mount.spec.ts: a refused patch throws and changes nothing
Threat
Generated UI navigates the product page
Control
Links, submits and goTo never navigate. They are reported
Test
packages/surface/__browser__/surface.spec.ts: CUJ 9: a link reaches onAction and the page stays; a form with no action goes nowhere.
packages/surface/__browser__/mount.spec.ts: a goTo trigger reaches onAction and the page stays
Threat
Generated UI imitates a sign-in form
Control
Password fields are refused. A profile can leave out fields
Test
packages/core/__tests__/validate/surface.spec.ts(surface.password)
Threat
A surface reads or writes the page's storage or styles
Control
No script that touches storage runs. Shadow root
Test
packages/surface/__browser__/surface.spec.ts: CUJ 9 and security: the page storage and styles are untouched
Threat
Generated UI sends data out, or calls the product's own addresses
Control
src is refused. Every document file address goes through links.file
Test
packages/core/__tests__/compile/surface.spec.ts: the only file addresses are the ones links.file gave.
packages/surface/__browser__/surface.spec.ts: CUJ 9 and security: hostile values load only what links.file returned, and nothing escapes the host
Threat
Generated UI draws over the product page
Control
Pinned, fixed, popover and dialog content is refused. The host is contained
Test
packages/surface/__browser__/surface.spec.ts: CUJ 9 and security: hostile values load only what links.file returned, and nothing escapes the host.
packages/core/__tests__/validate/surface.spec.ts: a surface refuses what a generated panel must not hold (surface.overlay)
Not prevented
"Open link in new tab" from the browser menu, and dragging a link out. The mount handles only click and auxclick.
A form that asks for something sensitive in an ordinary text field.
Anything the product does with a value it did not check on its server.
A patch must come from the product's own code, over its own transport.
Not tested
Safari and Firefox. The browser tests drive Chromium only.
A real middle click. The test dispatches a synthetic auxclick.
IME composition while a patch lands.
A page policy that blocks style attributes. See the package README.
Previous
Next