Skip to content

Security model

This page is about the sandbox: a dashboard written by someone else, shown inside your application. It says what the sandbox guarantees, how, and what remains your application's job.

In the two other setups you write the dashboard, and there is no sandbox:

The case to design for

A malicious author writes a dashboard (HTML and JavaScript, both allowed), and another person opens it. The dashboard then runs with the rights of the person looking at it.

What the author's code can do, by design

  • Query anything the viewer is allowed to see (your engine and row-level security apply to the viewer, not to the author), and display whatever it wants inside its frame, including wrong numbers or a fake form.
  • Send messages to the Host: queries, filter changes, error reports.

What it cannot do

Attack Stopped by
Read the Host page, its cookies, storage or tokens sandbox="allow-scripts" without allow-same-origin: the dashboard has its own empty origin. embedDashboard creates the iframe itself, with this attribute and no other.
Send data out with fetch, images, CSS, fonts, forms, beacons The content security policy of the dashboard (default-src 'none', connect-src 'none', form-action 'none'). The frame downloads bi-components.js and the files the Host gives it: the policy names each file, and no other address can be requested.
Navigate itself to https://evil.example/?data=... embedDashboard puts the dashboard in a second sandboxed frame, inside a small document written by the library whose policy is frame-src 'none'. The Host needs no configuration for this.
Navigate the Host page, open popups or dialogs, start downloads The sandbox (no allow-top-navigation, allow-popups, allow-modals, allow-downloads).
Run SQL or ask for anything outside the dictionary The validation of every query (no statement, sub-query or unsafe function), then your engine in resolveQuery, which refuses the mode, tables, columns or names it does not allow.
See more than the viewer restrictFilters in resolveQuery, on the Host, and the rights checked again by your server.
Flood the engine in the viewer's name maxPendingQueries (200 at a time by default).

Checked in Chromium by the end-to-end tests (navigation, nested frames, WebRTC, network requests). Other browsers have not been tested.

What your application must do

The browser no longer lets data out directly, so the remaining ways out go through the Host or through the viewer:

  1. Anything the Host stores or shows to other people is a way out. The dashboard chooses the filter values, the options and the text of its error reports. If the Host saves that state in a shared place (a saved view, a shareable URL) or shows a dashboard's errors to its author, the author can encode the viewer's data in it and read it later.
    • Keep what comes from the iframe private to the viewer. Do not persist it in anything the author can read.
    • Never give onRuntimeError messages to the author or to a shared log without review. embedDashboard clips them (500 characters, 2000 for the stack) and bounds filter values (256 characters), which limits the volume but does not close the channel.
  2. variables are readable by the dashboard. Never put tokens, e-mail addresses or anything secret in them.
  3. Other message listeners of your page. The dashboard can call postMessage on any window above it. embedDashboard only accepts messages from its own iframe; your other message listeners must check event.source or event.origin (which is "null" for the dashboard) too.
  4. The viewer can be fooled. The dashboard can ask the viewer to copy a text, scan a QR code or type a password. Show clearly, outside the frame, who wrote the dashboard, and never let a dashboard's content look like your own interface.
  5. Low-volume technical channels. WebRTC and DNS hints are not covered by connect-src. The first script of the dashboard removes the WebRTC constructors and any nested frame (which would get them back), but this is JavaScript defense in depth, not a browser guarantee. A determined author may still leak a few bytes per second.
  6. Availability. A dashboard can freeze the tab with an endless loop. Nothing here prevents it; reloading without the dashboard does.
  7. Your server checks again. The Host runs in the viewer's browser: its rules stop a dashboard, not a viewer who opens the developer tools. Your endpoint validates every query and applies the rights of the session, as any API does.

In short: with these protections a malicious dashboard cannot take over the viewer's session or the Host, and has no direct way to send data out. Treat what it shows as untrusted, and treat what it sends you as untrusted text you keep private.

Every query is checked

Before resolveQuery sees a query:

  • a message is accepted only if event.source is the iframe embedDashboard created (the origin of a sandboxed iframe is "null", so it proves nothing);
  • every query is rebuilt from a strict schema: names as lists of strings, primitives only in filters, a bounded limit, sort_by among the returned columns; unknown fields are dropped;
  • a named query has a plain name (letters, digits, _), and comes with the filters and period of the viewer as the Host holds them, not as the dashboard describes them;
  • with SQL expressions (mode: 'table'), the table is a plain name and each expression is one expression: no statement or sub-query (select, union, attach, pragma...), no comment, no ;, no quote outside string literals, no call to a function outside a list of safe ones (aggregates, dates, text, math), no current_user and the like. Any other word is a column name;
  • params are dropped unless your sanitizeParams accepts them.

Which names, tables and columns exist, and who may read them, is for resolveQuery and your server: see Named measures, SQL expressions, named queries. Every query of the frame goes through resolveQuery, and nothing else reaches your engine: there is no second path to protect.

How the frame is written

embedDashboard writes two documents in the iframe it creates, one inside the other. The outer one only holds a second sandboxed frame and forwards the messages; it is what stops a dashboard from navigating away with data. The inner one is the dashboard:

<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'unsafe-inline' https://.../bi-components.js ...">
<meta name="bi-components" content="embedded">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/daisyui@5.8.3/daisyui.css" crossorigin="anonymous">
<style>/* your css */</style>
<script>/* removes what a policy does not cover: WebRTC, nested frames */</script>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.3.5/dist/index.global.js" crossorigin="anonymous"></script>
<script src="https://unytics.io/bi-components/dist/bi-components.js" defer></script>   <!-- BI Components -->
<body>... the dashboard ...</body>
  • The policy comes first, before any byte of the dashboard. It lists the address of bi-components.js and those of resources, and nothing else: not their domain, not another version, not another file.
  • The marker says where the components run. embedDashboard writes it, you never do. bi-components.js reads it: in a frame it asks the Host for data, and never starts DuckDB-WASM. A script of the dashboard could remove it, since it runs first: the frame would then fail to download DuckDB-WASM, which its policy does not allow, and only break itself.
  • The components are one classic script. It has nothing to import, so nothing has to be resolved in the frame, and it needs no particular header from the server that serves it.
  • A resource must be served with Access-Control-Allow-Origin, as jsDelivr and GitHub Pages do: a sandboxed frame has no origin of its own, so every request it makes for a resource is a cross-origin one.

The frame gets the components of a dashboard: charts, score cards, tables, filters. It does not get <source-table>, <source-api> nor DuckDB: in a frame the data stays with the Host.

What the frame can reach

A dashboard can already run any script of its own, so giving it a library gives it no new power. What matters is the network: which requests the frame can make, and who receives them.

The frame can request bi-components.js and the files of resources, nothing else. Two things remain:

  • The servers of these files see the viewer's address, as for any page that uses a CDN. bi-components.js is usually answered by the browser cache.
  • A dashboard can add a query string to an allowed address (.../bi-components.js?anything): a policy does not compare query strings. Those bytes reach the logs of that server, which the author of the dashboard cannot read.

Serve the files from your own domain (the components option for bi-components.js) to keep third parties out: nobody outside your application then knows a dashboard was opened. Only list files served as they are: an address whose answer depends on its query string must not be given to the frame.

To give every dashboard a small stylesheet without another request, put its text in css.

Report a vulnerability

Found a way out of the sandbox? See SECURITY.md.