Adopt SES / Hardened JS lockdown() as the systematic control for artifact isolation
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 15/100
- Issue type
- Refactor
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- javascript, typescript
Research direction
This is a design proposal rather than a bug, so start by reading the companion script v1.js and find where it relies on built-in intrinsics for trust decisions, plus the artifact CSP that currently blocks unsafe-eval. Done means a agreed decision on adopting SES lockdown() and a compatibility assessment against existing artifacts, not a patch. Expect to discuss scope with maintainers before writing code.
Written by the indexing model from the issue text.
Description
Summary
Primer's companion runtime is trusted code that runs in the same JavaScript realm as the untrusted artifact it serves. Today it defends itself against a hostile artifact with targeted, per-property hardening. This issue proposes basing artifact isolation on a catalogued, maintained control — SES / Hardened JS lockdown() — instead of on fixes added one exploit variant at a time.
Background
Artifacts run in a sandboxed, opaque-origin iframe (no allow-same-origin), and a strict CSP blocks network access. That boundary is strong and browser-enforced. But the companion (v1.js) has to run inside the artifact's realm, because much of its job — comment anchoring, hover/selection, DOM geometry — requires reading and decorating the artifact's live DOM, which the cross-origin parent page cannot do. So the companion is a trusted component that shares primordials (prototypes, built-in functions, global intrinsics) with untrusted code.
That shared-realm arrangement exposes the companion to a well-known class of attacks: prototype pollution, per-instance property shadowing, tampering with built-in functions, and dynamic code evaluation. A hostile artifact can redefine or shadow the objects and functions the companion relies on to make trust decisions.
Why per-property hardening does not scale
The current approach freezes the specific intrinsics the companion depends on. This works for the properties it targets, but it addresses instances, not the class:
- Closing one tampering vector (for example, a redefined prototype getter) does not close the equivalent variant (shadowing the same property on a specific instance, or tampering with the reflection primitive used to read it). Each variant is the same underlying weakness surfacing in a new place, and each must be found and patched separately.
- At least one member of the class — dynamic code evaluation via
new Function/eval— is currently closed only incidentally, by the artifact CSP omittingunsafe-eval. The companion's own defenses do not address it. Thescript-srchas already been broadened to permit inline scripts and several CDN hosts; ifunsafe-evalis ever added for a legitimate artifact need, this vector reopens silently.
Because it depends on anticipating each variant, per-property hardening cannot be shown to be complete.
Recommendation
Adopt SES / Hardened JS (lockdown(), from the Endo project) as the isolation control:
- Run
lockdown()before any artifact script executes. This freezes the realm's shared intrinsics, closing prototype pollution and built-in tampering across the whole class in one audited step rather than property by property. It also tames the dynamic evaluators (Function,eval), removing the reliance on CSP for that vector. - Make it a platform rule that artifacts may not mutate the base environment. This is consistent with the existing strict-CSP posture; a self-contained review artifact has no legitimate need to patch built-in prototypes or generate code at runtime.
- For the narrow cases
lockdown()does not cover — reading a security-relevant value off a dynamically-created DOM instance, which can still be shadowed per-instance — read through a native accessor captured before any artifact code runs. With intrinsics frozen, that capture is trivially safe.
Tradeoffs to weigh
- Compatibility.
lockdown()breaks artifacts that rely on two patterns: writing to properties inherited from now-frozen prototypes (the "override mistake," tunable via lockdown'soverrideTamingoption), and runtime code generation. Both should be rare in self-contained artifacts and are arguably things the platform should forbid, but a compatibility pass against the existing artifact backlog is needed before enabling it. - Cost. SES adds a dependency to the injected companion bundle and a per-load cost to freeze intrinsics.
- Maintenance. It is a real dependency and audit surface — but a maintained, catalogued one, versus continuing to hand-roll and re-verify isolation logic in-house.
Note on LavaMoat
LavaMoat is built on SES but targets supply-chain risk (isolating npm dependencies under per-package policy). The primitive relevant to artifact isolation is SES lockdown() / Compartments, not LavaMoat's package-policy layer. LavaMoat may be worth separate consideration for Primer's own build dependencies.
Scope
This is a hardening and architecture proposal, not an active incident — the specific tampering vectors found so far are either already fixed or currently mitigated by CSP. The goal is to make artifact isolation rest on a catalogued, maintained control, so that completeness no longer depends on anticipating each exploit variant individually.
- Dominant language
- TypeScript
- Stars
- 2
- Forks
- 1
- Avg merge
- 13h 38m
- Merged PRs (30d)
- 24
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from 0xPolygon/primer
-
triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Feature: @-mention people and agents in documents and comments; a mention notifies and subscribesOpen
Difficulty 5/5 Over a week Newbie friendliness 18/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 Half a day Newbie friendliness 45/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
0xPolygon/primer#185 · 1 comment ·
Maintainers usually reply within 1 day
All issues in 0xPolygon/primer
Similar issues
-
P3
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
bug L3 level 1 needs-review wocs
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
SatyamPandey-07/WorkSphere#10739 · 1 comment ·
Maintainers usually reply within 1 day
-
maintenance
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
assistant-ui/assistant-ui#10946 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:auth-provider issue-rating: 🦞 diamond lobster no-stale P2
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
openclaw/openclaw#206303 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day