Security Model
Why widget values are never markup or code, and where widget settings are validated.
This page explains the security rules of the library and the three places where widget settings are checked.
The Problem It Solves
Section titled “The Problem It Solves”When a campaign carries HTML and JavaScript, anyone who can edit that campaign can run code on a customer’s website, on every page the campaign is shown, including the basket. Nothing reviews that code.
The library removes the possibility instead of trying to detect misuse: a widget config has no field that carries code.
Rules in the Library
Section titled “Rules in the Library”| Rule | How it is enforced |
|---|---|
| Every value is drawn as text | The widget builds DOM with createElement and textContent. A browser test feeds <img onerror=...> into every text field and checks that it stays text. |
| No HTML strings | Lint bans innerHTML, outerHTML and insertAdjacentHTML. |
| No dynamic code | Lint bans eval and new Function. |
| No legacy globals | Lint bans _SgmntfY_, jQuery and Mustache. |
| Unknown schema versions are refused | The widget draws nothing and reports UNSUPPORTED_SCHEMA. |
These rules apply to everything in the repository, including per-account extensions.
Three Layers of Checking
Section titled “Three Layers of Checking”No single place is trusted on its own.
| Layer | Rule | Status |
|---|---|---|
| Sauron, the panel backend | Reject on write. A config that does not match the schema and the value rules is not saved. | Planned |
| The widget | Do not trust on render. Values are text; unknown versions are refused. | Done |
| gandalf, the engine | Carry, do not interpret. The config is passed on as data; no expression inside it is evaluated. | Planned |
Sauron is the right place to reject bad settings because every write from the panel goes through it, and a check in the panel’s user interface can be bypassed. It is not the only layer because data can reach the database by other routes.
What Sauron Validates
Section titled “What Sauron Validates”- The config matches the JSON Schema generated from this repository’s contract.
- Unknown fields are rejected, not stored. The exception is account-specific fields on products.
- Theme values match a colour, size or font format. Free text is refused, so a value cannot smuggle in
url(...). - URLs are
https.javascript:anddata:are refused. - Selectors, paths and texts have length limits.
- An extension id must belong to an extension registered in a repository.
The schema has one source: this repository. Sauron validates a stored campaign with the settings schema (schema/recommendation-widget-settings.v1.schema.json) and the example settings under fixtures/settings/; it does not keep its own copy. The settings schema has no field of one response (no campaign id, no interaction id, no product), so a stored campaign can be checked alone. See Stored Settings and Served Payload.
The Schema and Its Fixtures
Section titled “The Schema and Its Fixtures”The JSON Schema is generated from the TypeScript contract, so a rule is written once.
| Path | What it holds |
|---|---|
src/contract/config.ts |
The contract. JSDoc tags such as @pattern and @maxLength are the value rules. |
schema/recommendation-widget-config.v1.schema.json |
The generated schema (draft-07). Published in the npm package. |
fixtures/valid/ |
Configs that must be accepted, including one whose texts look like markup. |
fixtures/invalid/ |
Configs that must be rejected. Each is one attack or mistake. |
fixtures/invalid/index.json |
For each invalid config: why it is invalid and where. |
pnpm schema regenerates the schema. CI fails if the committed schema is not what the contract generates.
The invalid fixtures cover: an unknown top-level field such as postJsCode, an HTML template field, an unknown theme token, url() and declaration breaks in theme values, javascript:, data: and http: URLs, an overlong selector, markup in a selector, a malformed custom field path, an unknown display type, a malformed extension id, an unknown schema version, an overlong title, too many products, a breakpoint with zero columns and a missing campaign id.
Text that looks like markup, for example <script> in a title, is valid. It is accepted and drawn as the characters it is made of.
Two rules are not in the schema because they need knowledge the schema does not have: whether an extension id is registered, and whether the caller is authorized. Sauron checks both.
Custom Code
Section titled “Custom Code”Some accounts need behaviour no setting can express. That code lives in the @segmentify/integration repository as a per-account extension, bound to typed hooks. It goes through pull request review and CI, and the same lint rules apply to it. It is never typed into the panel. On mobile there are no extensions.
The widget does not trust an extension either. It can only remove or reorder products and veto the widget: it works on frozen copies, and its answer is applied to the original, validated products. So an extension cannot put an unvalidated URL or text on the page. See Extensions.
The slot (slot) is a setting too: a kind from a closed list, a moment and a display text. It has no field for markup or code, and what happens at the end of a countdown is fixed.
A badge of the card (card.badges) is a setting, not code: a fixed display text or a plain dot path into the product. A path follows only the product’s own properties, there are no expressions, and whatever it reads is written as text.
An account’s product card is custom code of a second kind, with more power: it draws the inside of a card itself. The widget guards what it can. The product link and the buttons come from the widget already wired, so a card cannot lose or change an event, a card that fails is replaced by the library card, and so is a card that holds a script, a frame, an inline event handler or a javascript: address. What the widget cannot check is the texts, links and images a card draws. That is guarded in the integration repository: review, tests and the same lint rules. See The Account’s Product Card.
Next Steps
Section titled “Next Steps”- Config Schema shows that no field carries code.
- Development lists the lint rules.