Security and Sandboxing¶
A Custom Gizmo runs code that someone in your organization wrote, inside a page where a user is signed in. The platform isolates it so that the gizmo cannot read the user's session, the task page or other gizmos. This page lists exactly what the sandbox allows, how to open it for your own services, and what that means for your server.
At a glance
- Sandbox Iframe with
sandbox="allow-scripts"only; opaque origin, so requests carryOrigin: null - Files Loaded through signed links that expire after 5 minutes
- Outside calls Only to origins in
whitelist.txt, and the server must allowOrigin: nullin CORS - KnowledgeLake calls Only through
gizmo.API, made by the task page with the user's session - Secrets Never in gizmo files; every task user can read them
The iframe sandbox¶
The gizmo runs in an iframe with sandbox="allow-scripts" and nothing else. As a result:
| Blocked | Effect in your code |
|---|---|
| Same origin | The gizmo has an opaque origin. Its requests carry Origin: null. |
| Cookies | document.cookie throws. No cookies are sent with your requests. |
| Storage | localStorage and sessionStorage throw. Keep state in memory or publish it as a result. |
| Parent access | The platform sets window.parent to null. You cannot reach the task page. |
| Popups | window.open and target="_blank" links do nothing |
| Modals | alert, confirm and prompt do nothing. Draw your own messages. |
| Form submission | <form> submit does nothing. Use type="button" and handle clicks in JavaScript. |
| Top navigation | The gizmo cannot navigate the task page |
When it loads, the gizmo runtime checks that it is isolated. If the checks fail, it shows "Page Not Isolated!" and does not run your code.
How the files load¶
sequenceDiagram
participant T as Task page
participant K as KnowledgeLake
participant G as Gizmo iframe
T->>K: Ask for a signature for this user, time and gizmo
K-->>T: Signature, if the user has Use Custom Gizmos
T->>G: Load the frame page with its content security policy
G->>K: Fetch index.html and project files with the signature
K-->>G: Files, while the signature is under 5 minutes old
- The task page asks KnowledgeLake for a signature (HMAC) over the user token, the current time and the task's gizmo id. This needs the permission Use Custom Gizmos.
- It loads the gizmo frame page, which carries the content security policy below.
- The frame page fetches
index.htmland every project file through a file endpoint, with the signature in the URL.
The file endpoint checks the signature and refuses it after 5 minutes (tenant setting CustomGizmosHMACTimeoutInMinutes, default 5). It also refuses requests that come from a signed-in browser tab, that carry a Referer, that carry an Origin other than null, or that are a direct page navigation. So you cannot open a project file URL in a browser tab, and other sites cannot load your gizmo files.
The signature covers file loading only. It does not authenticate gizmo.API calls (the task page makes those with the user's session), and it does not reach your own server.
A new signature is issued each time the gizmo is shown. A project file your code loads later (for example an image added to the page after a click) uses the signature from load time and fails once it is older than 5 minutes. Load project files when the gizmo starts.
Content security policy¶
The frame page sends this policy. <whitelist> stands for every line of whitelist.txt.
connect-src 'self' <whitelist>;
script-src 'self' <whitelist>;
img-src 'self' <whitelist>;
media-src 'self' <whitelist>;
object-src 'self' <whitelist>;
style-src-elem 'self' 'unsafe-inline' <whitelist>;
frame-ancestors 'self' <KnowledgeLake cloud domains> <whitelist>;
What it means in practice:
| You want to | Allowed? |
|---|---|
Load project files ({project}/main.js, images, CSS) |
Yes |
Call https://api.example.com with fetch |
Only if the origin is in whitelist.txt |
| Load a script from a CDN | Only if the CDN origin is in whitelist.txt |
Use an inline <script> block or onclick="..." |
No. Put code in a .js file and use addEventListener. |
Use eval or new Function |
No. Libraries that compile templates at run time fail. |
Use an inline <style> block or a style="..." attribute |
Yes |
Show a data: image |
Only if data: is in whitelist.txt |
| Load font files | Yes. The policy does not restrict fonts. A stylesheet from another origin still needs that origin in whitelist.txt. |
There is no default-src, so any directive not listed above is not restricted by this policy.
whitelist.txt syntax¶
// Lookup service for vendor records
https://records.example.com
// Charting library
https://cdn.jsdelivr.net
// All subdomains of our API domain
https://*.api.example.com
- One source per line.
- A line that starts with
//is a comment. Blank lines are ignored. Spaces at the start and end of a line are trimmed. - Each line is added, as written, to every directive in the policy. A CDN you list for scripts can also be called with
fetch, and the reverse. - Use the scheme and host:
https://records.example.com. A wildcard for subdomains (https://*.example.com) works. - A line
'self'is ignored; it is already in the policy. - Do not add
'unsafe-inline'or'unsafe-eval'. They would apply to scripts too and remove the main protection of the sandbox.
Changes take effect the next time the gizmo loads.
CORS: your server must accept Origin: null¶
The browser sends every request from the gizmo with Origin: null. Your server must answer with CORS headers that allow it, or the browser blocks the response. Answer the preflight (OPTIONS) and the real request with:
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Origin: null also works. A request with Content-Type: application/json or any custom header triggers a preflight, so your server must answer OPTIONS.
What this means for your server¶
Treat every request from a gizmo as anonymous
- The gizmo cannot prove who the user is. No cookie and no KnowledgeLake token reach your server.
- Do not put secrets in gizmo files. Every user who opens the task can read
main.jsin the browser developer tools. - Design for exposure. Expose a narrow, read-only endpoint for the gizmo, for example "look up one vendor by number". Put anything sensitive behind a service that holds its own credentials.
- For KnowledgeLake data, use
gizmo.API. It runs as the signed-in user, with that user's permissions.
Related¶
- API Reference: permissions and
gizmo.API - Look Up a Record in Your Own System
- Debugging Custom Gizmos