Bento Spaces documentation
Security
The threat model is not "attackers everywhere". It is: a shared link forwarded in a chat, a wall panel left unattended, a widget that phones home, and a folder synced to the cloud by mistake. Every rule below exists for one of those.
Accounts
- PBKDF2-HMAC-SHA256, 600 000+ iterations, 16-byte salt, same implementation as
- bottlereturnpoints.com. No package.
- Unknown user costs the same time as a wrong password (dummy verify).
- Login throttled per username + IP;
Retry-Afteron 429. - Sessions: random 256-bit token, stored hashed, httpOnly,
SameSite=Lax,Securein - production, 30-day sliding expiry, server-side revocation on logout.
- Change password requires the current password; it rewrites the PBKDF2 hash and revokes
- every other session for that account. The session that made the change stays signed in.
- Operator recovery:
scripts/reset-password.mjswrites a new hash for a locked-out account - and revokes all its sessions. Run it on the API host with the storage root; the password is
- read from stdin and never printed.
Plans and lapsed access
- Entitlements are computed server-side from the account plan; the client never decides them.
- A paid plan remains active until
PlanRenewsAt; a cancelled plan with a future renewal keeps - access until that date.
- Once lapsed, the effective plan is Free: 3 spaces, no wallpaper or sync, and content writes are
- refused with
403 subscription_read_only. Existing spaces, widgets and data are untouched. - Authentication, API tokens, notification read state, billing and operator routes stay open so
- the owner can renew or sign out.
Billing adapter
Billing:Providerisnone,fakeorpaddle.fakeruns only when storage is disposable- (
/api/healthreportstest: true), so a real host can never self-upgrade. - Paddle is the merchant of record. Checkout is a server-to-server
POST /transactionswith - the API key; the browser only ever receives the hosted checkout URL. The key stays on the
- server and is never sent to the client.
- Webhooks are verified before parsing:
Paddle-Signature: ts=…;h1=…is an HMAC-SHA256 over "{ts}:{raw body}"with the webhook secret, compared in constant time. A timestamp older than- five minutes is refused so a captured delivery cannot be replayed.
- Only
subscription.*events change entitlements; other events are acknowledged and ignored. - Paddle's status is normalized (
active/trialing→ active,canceled→ canceled, everything - else → past-due) and its period end becomes
PlanRenewsAt. - Provider ids and the account are bridged by a record under
private/billing/subscriptions/{subscriptionId}.json. It lets a renewal that carries only the- subscription resolve the account, and keeps the last known plan and price for support.
- Invoices, receipts, payment-detail updates and cancellation live in Paddle's customer portal.
- Bento Spaces only mints a short-lived, authenticated portal session for the signed-in account's own
- customer id; the token in that link is temporary and is never stored or logged.
- Provider events carry an
eventId; the receipt underprivate/billing/events/makes webhooks - idempotent.
- The fake checkout is a random 30-minute token bound to one user and one plan, under
private/billing/checkouts/; it is consumed once, behindX-Billing-Secret.- Every provider keeps the same normalized event contract, so
PlanCatalogstays the single - entitlement source and no provider payload reaches storage.
Operator sessions
/managesigns in with a normal account session; an account is an operator only when its- username is listed in
Manage:Operators(*is allowed in local development only). - Cookie-authenticated writes require the custom
X-Manage-Session: 1header; a cross-site - form cannot set it and a cross-origin fetch would need a CORS preflight.
- Automation uses
X-Manage-TokenmatchingManage:Token, constant-time compared. The browser - never stores or pastes a token, and no token appears in a URL or HTML.
- Signing out revokes the normal session. Login uses the ordinary PBKDF2 account path and its
- throttle.
API tokens
- A personal token is a 256-bit secret prefixed
bt_, shown once at creation. - Only its SHA-256 hash is stored, under
private/api-tokens/; it never entersdata/, - exports, logs or a list response.
- Scopes are
readandread+write. A read-only token is refused onPOST/PUT/PATCH/ DELETEwith403 token_read_only.- Optional expiry (1–3650 days), immediate revocation, and
lastUsedAtat minute granularity. - Token management requires the cookie session: a leaked token can use the account, but cannot
- create or revoke other tokens.
Secrets
- Widget credentials never reach a browser; anything secret lives in
App_Data/private/. - Declarative widgets that need a secret must use
data.mode: "proxy".clientmode with a - secret is rejected by the editor.
- The proxy allows
http/httpsonly, 5 s timeout, 1 MB response cap, no scheme-changing - redirects. Private LAN addresses are allowed only when the space opts in (IoT).
- Secrets are excluded from exports, releases, archives and the synced
data/tree. - Honest limitation, documented for users: whoever runs the host can read the secrets. That
- is why company-hosted deployments are the recommended shape, and why CORS-capable APIs can
- keep credentials in the browser instead.
Share links and view sessions
- Sharing is per space, not per person: a link opens one space read-only.
- The optional PIN is chosen by the owner when creating the link, stored PBKDF2-hashed.
- A view link is a 128-bit token, stored hashed, revocable. Opening
/v/{token}exchanges - it for a 12-hour read-only session cookie; the token stays in the URL only for the first
- request.
lastOpenedAtis recorded. - A view session can read one space and unlock with the link's PIN. Every write endpoint
- still requires the account cookie, so a shared view cannot mutate anything.
- PIN attempts are throttled per session (10/min); widgets are removed from the DOM while
- locked, not merely dimmed.
View links and PIN
- A view link is a bearer token: 128-bit random, stored hashed, revocable, with
lastOpened. GET /v/{token}exchanges it for a **read-only session cookie scoped to one space + one- space**, then redirects to the same path, so the token does not appear in every request or
- in
Referer. - The client can never choose a space. The session decides.
- Capabilities per link:
actions: falsemakes a lobby screen data-only. - PIN: 4–6 digits, set by the owner when creating the link, PBKDF2-hashed, 10
- attempts → 60 s lockout, logged. The business sets the policy (idle timeout, lock mode); the
- person holds the PIN. The owner can only revoke and reissue, never read or reset it.
- Idle: widgets are unmounted (not merely faded) so no data remains in the DOM; wake
- remounts and refetches.
Registries
- The server fetches a registry index (8 s timeout, 1 MB cap) and a manifest (8 s, 256 KB).
- Every install verifies the manifest's sha256 against the registry entry; a mismatch is
- refused. Hashes pin bytes, they do not vouch for people (D25).
- Manifests are validated (
id,version,sizes,fit, render type, http(s) URLs only) by - the same module the browser and
scripts/check-widgets.mjsuse. - Declarative widgets never execute code.
- Module widgets run in an iframe with
sandbox="allow-scripts"and no allow-same-origin: opaque origin, no cookies, no storage, no parent DOM. The frame is served- from the host with `Content-Security-Policy: sandbox allow-scripts; default-src 'none';
- script-src 'unsafe-inline'; connect-src 'none'`, so it cannot reach the network. A 12-hour
- frame token authenticates it because cookies do not travel to an opaque origin. Source is
- capped at 64 KB and may not contain
</script. - Known limitation: the fetcher will reach private hosts if a registry points there. Fine on a
- company-hosted instance; a public host should add an address allowlist before launch.
Widget data
A widget never hands its audience a URL it can fetch directly.
- Installed only. The proxy loads the user's installed manifest for
{id}/{version}. - Declared origins only.
permissions.networkis the allowlist.selfmeans this Bento Spaces - origin;
selfrequests may read static assets but never/api/*. - Consent is the registry index. The install endpoint rejects a manifest whose network or
- action permissions are not a subset of what the index advertised. The dialog shows them
- before install.
- Connector actions are a second consent. A declarative
actionis refused at install - unless the manifest sets
permissions.connector, even when the index advertises it, so the - detail panel's connector tag always precedes the install. The command itself runs through
- the connector proxy, inheriting its token handling, path rules and timeouts; the widget can
- name a path and a JSON body, never a URL, a header or a token.
- Connector reads use the same gate.
data.mode: "connector"is also refused without permissions.connector, and the read travels through the same proxy, so a registry cannot read- an account's devices by pretending the data section is a normal URL.
- GET only. No headers or bodies from the caller. The host client sends no cookies, does
- not follow redirects, times out after 8 s and caps the body at 256 KB. JSON and
text/*are - accepted; anything else is refused.
- No private networks. Literal private/loopback/link-local addresses are refused, and every
- resolved address for an external host must be public. This is best-effort DNS protection;
- it does not claim to defeat rebinding.
- Cache.
data.cacheTtl(0–10 min) is the only caching. Responses areno-storeto the - browser.
- Module bridge.
ctx.requestgoes through the same proxy.openneeds theopenaction - and a URL inside the declared origins;
refreshandsetPropsneed their actions.
Connectors
A connector is an account-configured base URL and one credential — bearer, a custom header, basic auth, a query parameter, or none. It is not a widget manifest and cannot be added by a shared view.
- credentials live in the AES-GCM
SecretStore, never inconnectors.json - the API is write-only; only
hasToken,authandauthNameare returned - a header credential is written verbatim, so a line break is refused at add time; the header
- name is
[A-Za-z0-9][A-Za-z0-9_-]{0,39}, which keeps it a header and not a CRLF injection - a query credential is URL-encoded into the target URL by the server
- an OAuth access token and its refresh token are two separate AES-GCM entries; the connector
- stores only the expiry and scope
- the OAuth state is random, single use and expires in ten minutes; PKCE
S256protects the code - exchange, and the client secret never leaves the server
- the proxy refreshes an expiring token before the request; a failed refresh is
502 oauth_reconnectrather than an unauthenticated call- the master key is
Bento:SecretKeyor a0600file underApp_Data/private - the proxy allows only
GET/POST, only a relative path on the connector origin, no cookies, - no redirects, 8 s, 256 KB
- link-local and cloud metadata addresses are always refused
Connectors:AllowPrivatedefaults to true for a self-hosted LAN bridge; a public deployment- must set it to false
- connectors are account-only; shared views cannot read them
- health checks reuse the proxy, so they obey the same allowlist, token and timeout; the cached
- row stores only
ok/status/latency, never the token or response body
Browser push
- The VAPID key pair is generated on this host and kept in
private/push/vapid.json; rotating - it invalidates every subscription, so it is part of the backup set.
- A subscription is an endpoint (a capability URL) plus the browser's public
p256dhkey and - a 16-byte
authsecret. Only the owning account can list, replace or delete its rows. - Endpoints must be
httpsand a public host: literal loopback, RFC 1918, CGNAT, link-local, .localand.internalnames are refused. This is an SSRF guard, not a promise that the- host is trustworthy.
- Payloads are encrypted per RFC 8291 (
aes128gcm) with an ephemeral ECDH key; the server - never sends the payload in clear, never logs it, and only logs the endpoint host on failure.
- Delivery is release notifications only, gated by the publisher's plan and publisher status.
- A 404/410 from a push service removes the stale subscription.
Pairing
A bridge has no browser session, so POST /api/connectors/pair is anonymous. The one-time code is the credential:
- 8 characters from a 32-symbol alphabet (no
0/O/1/I),ABCD-EFGH, ~40 bits - bound to one account at creation; ten-minute expiry; single use, replayed codes are refused
- a malformed URL is rejected before the code is spent
- the bridge supplies its own bearer token and Bento Spaces stores it encrypted; nothing is echoed back
- only the account that minted the code can see the connector afterwards
- read-only accounts cannot mint a code (the lapsed-plan guard blocks the POST)
Live feed proxy
GET /api/live/feed?url=… exists because feeds do not send CORS headers.
- account-only (
401for an anonymous PWA session) http/httpsonly, public internet only: loopback, RFC 1918, CGNAT,169.254.0.0/16- (metadata), multicast and IPv6 unique-local addresses are refused with
403 - redirects are followed by hand, at most three, and every hop is re-checked by the same
- private-address guard; no cookies, 12 s timeout, 512 KB body cap
- an HTML response is treated as "not a feed" (
422) rather than parsed - the body is returned as XML and parsed in the browser by
web/src/lib/feed.js— never - evaluated, and every extracted string is escaped before rendering
Client
- CSP:
default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'. Scripts are - locked; inline style attributes are allowed because containers are positioned that way
- (CSSOM writes are unaffected by CSP). No inline
<script>, ever. connect-srcallows exactly seven public data hosts —api.open-meteo.com,api.coingecko.com,api.frankfurter.app,air-quality-api.open-meteo.com,date.nager.at,api.tfl.gov.ukandv6.bvg.transport.rest— plus'self'. Adding a host is a- security decision, not a setting.
- No third-party scripts, fonts, images or trackers. Widget data goes to declared hosts only.
- Sandboxed module widgets: iframe without
allow-same-origin; opaque origin; postMessage API. - The service worker is same-origin only: it never intercepts
/api/*, non-GET requests or - cross-origin traffic, and its precache list contains local paths only. It cannot widen the
- network surface or read a connector.
- Web app manifest is served as
application/manifest+json; icons are static PNGs. - All text from widget data is escaped;
innerHTMLis only used with template strings built - from trusted model values (ids and numbers), never from API payloads.
Server
X-Content-Type-Options: nosniff,Referrer-Policy: strict-origin-when-cross-origin,Permissions-Policydenying camera/mic/geolocation.- HSTS + HTTPS redirection in production;
www→ apex redirect. - Rate limits: login 10/min/IP, unlock 10/min/view, writes 60/min/user. The widget data
- proxy is bounded by origin, time and size but is not per-user rate-limited yet.
- Path safety: ids validated against
^[a-z0-9_]{3,40}$, thenPath.GetFullPathmust stay - inside the user root. No symlinks. No usernames in paths.
- Uploads: 2 MB, jpg/png/webp only, verified by signature sniff rather than the client's
- content type, stored outside
wwwroot, served through an authenticated route with Cache-Control: private.App_Datais never served, never published, never archived, never exported.
What we deliberately do not do
- No publisher signing or key pinning: hashes pin bytes, they do not vouch for people.
- No SSO, no admin roles, no audit dashboards. One owner per account, links for viewers.
- No telemetry. Logs are operational (requests, errors, lockouts) and never contain secrets.
Paired displays
A display pairing is a shared view with Display = true: read-only, no PIN, and exempt from the idle lock (a panel must not show a lock screen). The pairing URL is a bearer token stored hashed server-side and revoked from the same Share dialog as any other link. The 30-day display session cookie still gates every API call; the URL only exchanges into a session.