Secrets
A secret is a value that must not leave the user's own view: a session token, a card number, a
private note. Mark it with secret(). From then on the compiler follows it, and every place it would
leave the view is a compile error with the path it took.
// src/session.js
import { secret } from '@qatjs/core/secret'
export const token = secret(sessionStorage.getItem('session') ?? 'guest')// src/backend.js
import { reveal } from '@qatjs/core/secret'
import { token } from './session.js'
// the one place it goes: the app's own API, revealed there
export const headers = () => ({ authorization: 'Bearer ' + reveal(token) })reveal(s) is the only way back to the value. qatjs check lists each reveal as QX-SECRET-REVEALED
(info), so every place a secret leaves is written down and can be found.
What follows a secret
The compiler tracks where a value came from, not what it is called. A secret's derived values are secrets too:
- a property of it, or a destructured field;
- a template literal or a concatenation with it;
- an array or an object that holds it;
- what a function returns when it was given one, in this module or another;
- a closure that returns it;
- a
derived,stateorloadover it; - a prop that is given one;
- an emit's payload;
- a
provide, and everyinjectof the same token; - every field of a vault store (
persist: 'vault').
Where it may go
In its own view: a secret may be shown in the markup ({token}, title={token}) and passed to a
child component that shows it. It may also be kept in a vault store. Every other sink is an error,
and the message carries the path the secret took, such as
card → build() → payload → fetch():
| Code | The sink |
|---|---|
QX-SECRET-TO-SERVER |
fetch (under another name, or handed on as a callback, too), navigator.sendBeacon, a WebSocket or EventSource (one a function of the app returns too), an XMLHttpRequest's open() and send(), a load's request, mutate, a qatjs api call, form(), a form's action, a field of a form whose action is another origin's, a scenario's commit queue |
QX-SECRET-IN-SEED |
a load's data (the resume seed, snapshots), report(), snapshot(), repro, a replay trace |
QX-SECRET-IN-CACHE |
a load cached for everyone (cache: 'static' or a duration) |
QX-SECRET-IN-URL |
every attribute the browser fetches or navigates to (href, src, srcset, action, formaction, poster, ping, data, background, xlink:href, a meta refresh's content), a style (style:…, style={…}: a url() is fetched), the same properties set in code (img.src =, new Image().src =, a.href =), navigate(), history.pushState, location (through window or document too), a typed route (to.user({ id })), a query() signal |
QX-SECRET-LOGGED |
console.*, throw (which reaches the error adapters), explain |
QX-SECRET-IN-STORAGE |
localStorage, sessionStorage, IndexedDB, document.cookie, document.title and window.name (the browser keeps them beyond the page), a store persisted anywhere but the vault, a cold store (a secret is never cold) |
QX-SECRET-IN-SYNC |
shared(): its initial value, a write, a push |
QX-SECRET-IN-SCENARIO |
a scenario's of(), mutate() target or scoped(): a secret cannot be branched |
qatjs check and qatjs compress both report them. qatjs compress stops before it writes anything.
What is verified, and what is not
| Verified: followed, then checked at each sink | Not verified: QX-SECRET-ESCAPES-UNCHECKED (a warning; an error with --strict-secrets) |
|---|---|
the app's own modules (.qx, .tsx, .js, .ts) and the imports between them |
a function from a package (node_modules), or an unknown global; a function from a module import() loads, a global's value held in a variable (const f = globalThis.hook), and a function passed in as a parameter |
| a function's parameters and what it returns (a parameter that is ever given a secret is one) | as any (its type no longer says secret) |
props, emits, provide/inject, store fields, {for} items, for…of |
a dynamic key on an object the app does not hold (window[k] = s), and a method chosen by name (obj[m](s)) |
JSON, String(), Object.*, Math.*, Array.*, encodeURIComponent and the other pure built-ins |
eval, new Function, a timer given code as a string |
qat's own entries (qat, qat/*, @qatjs/*) |
a bridged component's prop (React, Vue, Angular), or a package's component |
The analysis does not follow the order in which code runs, and it does not tell one call of a
function from another. A binding that ever holds a secret counts as one everywhere, and so does a
parameter that any call fills with one. That can report a flow that never happens (a false
positive). A flow that misses its sink in the test corpus blocks a release. The corpus is not every
flow there is, though. An outside review found sinks it lacked (an element's src set in
code, XMLHttpRequest, a cross-origin form, a style's url(), xlink:href, document.title).
They are in it now, and no claim of zero misses is made beyond it. It does not follow:
- an implicit flow: code that branches on a secret's value and sends what it learns
(
if (reveal(t).charCodeAt(0) & 1) fetch('/bit')); - a secret written into the fields of an instance of the app's own class
(
QX-SECRET-ESCAPES-UNCHECKED); - a secret written onto a global,
window.x = t(QX-SECRET-ESCAPES-UNCHECKED).
At run time
secret() returns a wrapper, as a second line of defense where the compiler cannot see.
- What you read from it is the value's own:
s.length,s.title,s[0], and an array's own methods (s.map(…),filter,forEach), spread,for…of,Array.fromand destructuring see its elements. What they derive is still a secret to the compiler: sent, stored, logged or put in a URL, it is the same error as the secret itself. - It prints, serializes and spreads as
[secret]:${s},JSON.stringify(s)and{ ...s }. - A string's methods see
[secret]too, so reveal a string before computing with it. - Compare the revealed value, not the wrapper: a wrapper is always truthy.
- In its own view the compiler reveals it for you: what the markup shows is unwrapped there.
Devtools, __qat.explain and the panel show 🔒 secret, never the value. The editor's hover shows
where it came from (token → header). qatjs mcp returns code and graphs, never a value.
// src/card.js
import { reveal, secret } from '@qatjs/core/secret'
const card = secret({ number: '4111 1111 1111 1111', holder: 'Ada' })
JSON.stringify({ card }) // '{"card":"[secret]"}'
reveal(card).number // '4111 1111 1111 1111'Vault stores keep secrets device-encrypted, server-blind: see Vault.