VIII · Security
Security
On this page
Introduction
This page lists what a Marmeon app protects by itself, what it leaves to you, and where each part is explained. The defaults are chosen to be safe when nobody changes them. Where a protection costs something, such as a dependency, a migration or a cache, it is a switch, and this page says which way it points. The checklist at the end sums up what to do before a server goes live.
Found a vulnerability in the framework? Report it privately, as SECURITY.md describes, never in a public issue.
The environment decides, and fails closed
NODE_ENV is development, test or production; any other value stops the start. Two rules depend on it, and they are not
mirror images of each other:
- Development tools run only with
NODE_ENV=development. The error page with the code that threw, the devtools, theServer-Timingheader, the mail previews and Vite's dev server stay off everywhere else,testincluded. - Protections apply to
productionand to a server where nobody setNODE_ENV. JSON logs,migrateasking for--force, the warnings at start-up and the absence of lab pages hold there.testbelongs to the test runner alone: it turns every protection off, and development-only routes answer under it, so it never belongs on a server.
One check does not depend on NODE_ENV at all: an app whose routes do not all say who may call them does not start, in
development, in test and in production. The same holds for an open route that loads a record by any key. The
authorization page has the rule.
APP_ENV names the environment (staging, production, a name of your own) and changes neither rule: APP_ENV=local on a
server with NODE_ENV=production is protected, and its development routes answer 404. A staging server is
NODE_ENV=production APP_ENV=staging, with the production builds of the framework and of React, so a server error never reaches
its visitors with a message or a stack.
A forgotten variable therefore never shows your source code to a visitor. Set NODE_ENV in the server's real environment, and
never deploy a developer's .env: marmeon start refuses to run when development comes from a
.env, queue:work and schedule:work warn loudly, and the start line says development (APP_ENV=local, NODE_ENV from .env).
The configuration page explains where NODE_ENV comes from.
Code that runs in the browser and in server rendering checks for development positively, as development or test, never as
"not production". Without a value, an error in the browser shows only its short code, such as [marmeon:R2] users/Show, no
development warning appears, and an error page rendered on the server carries no exception message.
Development routes
The devtools at /_marmeon/devtools and the mail previews at /_marmeon/mail exist only with NODE_ENV=development. They sit
behind one host guard, devOnly() of @marmeon/core/dev: it answers localhost, 127.0.0.1, [::1] and the host of APP_URL,
and gives every other Host a 403 before the handler runs. Every answer is no-store and nosniff, carries no CORS header, and
is shared with no other origin, neither as a resource nor as a window.
The attack it stops is DNS rebinding. A page on evil.example points its own name at 127.0.0.1, reaches the developer's server
with Host: evil.example, and reads the answers as if they were its own: recorded requests, mails with reset links, source paths.
marmeon devputs Vite in front, and Vite refuses unknown hosts itself. It does not under HTTPS, withserver.httpsinvite.config.ts, and not withallowedHosts: true. Then the guard alone protects the devtools and the mail previews, while Vite's own paths, such as source modules, and the development error page have no host check. Use either setting only on a network you trust, and keepallowedHostsa list. The asset bundling page covers Vite's settings.- Vite's file serving has its own list of refused paths. With
marmeon dev, it coversstorage/,dist/,.marmeon/and database files (*.sqlite,*.sqlite3,*.db,*.db3and their companions) on top of Vite's own, so an app that listens beyond localhost, withHOST=0.0.0.0, does not hand out its database, private uploads or build output. Your ownserver.fs.denyentries are added. - Vite's
.envfiles andVITE_*variables are off: no variable reaches the public bundle by its name.marmeon({ viteEnv: true })turns them back on, and then everyVITE_*variable of the process is public. See environment variables. - A development route of your own takes the same guard. Outside
developmentandtestit answers 404 by itself, asked on every request: a route registered on a server by mistake stays shut. The routing page shows how. *.localhostnames pass Vite, since they are loopback by definition, but not the guard, unlessAPP_URLnames one.
Requests from other sites
Every request of the web group that may change something is checked for cross-site request forgery. The browser's
Sec-Fetch-Site: same-origin passes, and a request from another site is refused with 403. Without Fetch Metadata, the Origin
header decides. Only a client that sends neither needs the session's token, and without it gets 419.
- Guests get no session just for a token. A session draws its token only when something needs it, and signing in or out renews it. A guest who only reads leaves no cookie behind, unless the page keeps a session, such as one with an upload field.
- Browsers send Fetch Metadata to secure origins only. Over plain HTTP the check falls back to
Origin, then to the token. Serve production over HTTPS. - Trust other origins with
CSRF_TRUSTED_ORIGINS, and check webhooks by their signature withverifyWebhook(), which needs nocsrfExcept. - The
apigroup has no session and no CSRF check, since every request proves itself with its API token.
The CSRF protection page explains every stage.
Sessions and cookies
- Every cookie is
SecurewhenAPP_URLstarts withhttps://: the session cookie,XSRF-TOKEN, the remember-me cookie and your own.SESSION_SECURE_COOKIEoverrides it either way. A protected app whose cookies go withoutSecurewarns at start-up. The session page has the details. - The session and remember-me cookies carry the
__Host-prefix when they areSecure: a neighbouring subdomain cannot set them for your domain. Only the prefixed names are read. The session page has the details. - Cookies are encrypted with
APP_KEYin thewebgroup, all butXSRF-TOKEN, which the browser's JavaScript reads. The session cookie is alsoHttpOnly. - The store never sees a session id. A session is kept under the SHA-256 hash of its id, so a leaked file, row or Redis key is
no cookie.
SESSION_ENCRYPT=trueencrypts the data as well. The session page explains both. - Signing in or out renews the session: a new id and a new CSRF token, so an id handed out before signs nobody in.
- Signed-in answers are
Cache-Control: no-store, private, so Back after signing out shows nothing from the browser's cache. Signing out also sendsClear-Site-Data, and the other tabs of the browser follow by themselves. The authentication and client features pages explain them. - Requests that only read never write. Islands, live streams and the tabs' session checks write no session data and set no cookie. The request lifecycle page lists them.
A link that is a credential
A page whose URL grants a right (an invitation, a ticket, a one-time link, a confirmation to leave a list) must not stay in a shared
cache, a search index or another site's logs. Put credentialPage() on the routes that carry the token:
const tickets = Route.middleware(credentialPage()).middleware(throttle('tickets'));
tickets.authorize(everyone).bind('ticket', TicketRepository, { public: true }).get('/tickets/:ticket', ShowTicketController);Every answer of those routes then carries Cache-Control: no-store, private, X-Robots-Tag: noindex, nofollow and
Referrer-Policy: no-referrer: the page, the JSON of a partial reload, a redirect, and the errors the route itself answers with (the
binder's 404, abort(), the 403 of signed(), the 429 of throttle(), a 422, a 500 in production). Put the middleware in front of
throttle() and signed(), so their refusals carry the headers too. A middleware that answers before the route, such as the CSRF check
(419), the protocol gate (409) or, in development, the error page for a 5xx, does not. Cache-Control replaces any value the route set;
a Referrer-Policy of no-referrer or same-origin that a controller set stays.
publicbinding, one throttle, one 404. A binder with{ public: true }finds the row by the token's hash; a wrong token, a used link and a token of the wrong shape all answer the same 404. Throttle the route, so a token cannot be guessed by trying.no-referrer, because the token is in the path. The browser's default,strict-origin-when-cross-origin, keeps the path from other sites, but every request of your own origin from the page would send the token in itsReferer, and the next page would read it indocument.referrer, where analytics and proxy logs pick it up. The app stores only the token's hash, so it must not hold the token anywhere else.A form behind a token. Without a
Referer,back()has nowhere to go (it lands on/), and a browser without Fetch Metadata sendsOrigin: nullwith the post, which the CSRF check cannot match. So let the token route trade the token for the row's id in the session and redirect to a page without it. That page and its post usecredentialPage({ referrer: 'same-origin' }), and a failed validation returns to it with its errors andold()input. The trade has rules of its own:- Call
session.regenerate()before theput, so a session id planted by whoever sent the link carries nothing. - Show on the page what the invitation is for (the workspace, the event), so a visitor sent to an attacker's link can tell.
- Look the row up again on the page and on the post, in
authorizeof the request so it runs before the schema; a session that holds an id is no right by itself (the link may be used up or revoked since), and a visitor without one gets a 404. - After the use,
redeem()the row andsession.forget()the id.
A request class with a schema always returns with
back()on a failure. A form that must keep the token in its path validates in its controller instead, and redirects to its own URL withthis.redirect(…)and the input.- Call
The URL generation page shows how to make and look up the token. The code below puts the rules together.
A form behind a token, in code
An invitation into a workspace, from the link to the accepted membership. Only the first route has the token in its path. It trades the token for the invitation's id in the session, and every route after it is addressed without a token:
import { authenticate } from '@marmeon/auth';
import { throttle } from '@marmeon/cache';
import { abort, credentialPage, defineRoutes, describeAccess, everyone } from '@marmeon/http';
import { AcceptInvitationController } from './controllers/AcceptInvitationController.ts';
import { ContinueInvitationController } from './controllers/ContinueInvitationController.ts';
import { OpenInvitationController } from './controllers/OpenInvitationController.ts';
import { ShowInvitationController } from './controllers/ShowInvitationController.ts';
import { InvitationRepository } from './InvitationRepository.ts';
import { PendingInvitation } from './PendingInvitation.ts';
export default defineRoutes((Route) => {
// The trade. The binder finds the row by the token's hash, and answers 404 for any other value (see "A link that is used once").
Route.middleware(credentialPage())
.middleware(throttle('invitations'))
.authorize(everyone)
.bind('invitation', InvitationRepository, { public: true })
.get('/invitations/:invitation', OpenInvitationController);
// The page and its post. The check looks the row up again, once per request, and answers the same 404 without one.
const pending = Route.middleware(credentialPage({ referrer: 'same-origin' })).authorize(
describeAccess(async (_ctx, resolve) => {
if ((await resolve(PendingInvitation).find()) === undefined) abort(404);
return true;
}, 'pending invitation'),
);
pending.get('/invitation', ShowInvitationController).name('invitations.show');
pending.middleware(authenticate()).post('/invitation', AcceptInvitationController);
// Where "Sign in" on the invitation page leads: no token, so the session keeps nothing secret as the intended URL.
Route.middleware(authenticate()).get('/invitation/continue', ContinueInvitationController).name('invitations.continue');
});The trade gives the session a new id before it stores anything, so an id that whoever sent the link planted carries nothing. The old id stops working and the session keeps its data, so the flow adds only the invitation's id, which is no secret and no right:
import type { Row } from '@marmeon/database';
import { Controller, type HttpContext } from '@marmeon/http';
import { Session } from '@marmeon/session';
declare module '@marmeon/session' {
interface SessionData {
/** The invitation whose link this visitor opened: its id, never its token. */
invitation: number;
}
}
export class OpenInvitationController extends Controller {
readonly #session: Session;
constructor(session: Session) {
super();
this.#session = session;
}
handle(ctx: HttpContext<{}, { invitation: Row<'invitations'> }>) {
this.#session.regenerate();
this.#session.put('invitation', ctx.params.invitation.id);
return this.redirect().route('invitations.show');
}
}PendingInvitation is the holder of the looked-up row. It is scoped, so the check of the route and the controller share one
query per request (register it with container.scoped(PendingInvitation), as in
a lookup once per request):
import type { Row } from '@marmeon/database';
import { abort } from '@marmeon/http';
import { Session } from '@marmeon/session';
import { InvitationRepository } from './InvitationRepository.ts';
export class PendingInvitation {
readonly #session: Session;
readonly #invitations: InvitationRepository;
#row: Promise<Row<'invitations'> | undefined> | undefined;
constructor(session: Session, invitations: InvitationRepository) {
this.#session = session;
this.#invitations = invitations;
}
/** The open invitation the session names, or `undefined`: none named, or used up or revoked since the link was opened. */
find(): Promise<Row<'invitations'> | undefined> {
this.#row ??= this.#lookup();
return this.#row;
}
/** The same, or the 404 of a visitor who has no invitation. */
async require(): Promise<Row<'invitations'>> {
return (await this.find()) ?? abort(404);
}
async #lookup(): Promise<Row<'invitations'> | undefined> {
const id = this.#session.get('invitation');
return id === undefined ? undefined : this.#invitations.findOpen(id);
}
}The repository finds the row by the token's hash for the trade, as in a link that is used once, and by id for everything after it:
import { hashLinkToken } from '@marmeon/encryption';
import { Repository, secretEquals, type Row } from '@marmeon/database';
export class InvitationRepository extends Repository<'invitations'> {
static table = 'invitations' as const;
/** `/invitations/:invitation` → the open row, or `undefined` for a 404. */
override resolveRouteBinding(token: string): Promise<Row<'invitations'> | undefined> {
return this.query().selectAll().where((eb) => secretEquals(eb, 'token_hash', hashLinkToken(token))).where('used_at', 'is', null).executeTakeFirst();
}
/** An invitation that is not used up. A revoked one is a deleted row. */
findOpen(id: Row<'invitations'>['id']): Promise<Row<'invitations'> | undefined> {
return this.query().selectAll().where('id', '=', id).where('used_at', 'is', null).executeTakeFirst();
}
/** True for exactly one caller, however many arrive at once: the update decides, not an earlier read. */
async redeem(id: Row<'invitations'>['id']): Promise<boolean> {
const result = await this.db.updateTable('invitations').set({ used_at: new Date() }).where('id', '=', id).where('used_at', 'is', null).executeTakeFirst();
return Number(result.numUpdatedRows) === 1;
}
}The page says what the invitation is for. Its form posts to /invitation, with no token in the path, so back() and the CSRF
check work as on any page, and a failed validation returns to it with its errors:
import { Controller } from '@marmeon/http';
import { PendingInvitation } from '../PendingInvitation.ts';
import { WorkspaceRepository } from '../../workspaces/WorkspaceRepository.ts';
export class ShowInvitationController extends Controller {
readonly #pending: PendingInvitation;
readonly #workspaces: WorkspaceRepository;
constructor(pending: PendingInvitation, workspaces: WorkspaceRepository) {
super();
this.#pending = pending;
this.#workspaces = workspaces;
}
async handle() {
const invitation = await this.#pending.require();
const workspace = await this.#workspaces.findOrFail(invitation.workspace_id);
return this.view('invitations/Show', { workspace: workspace.name, role: invitation.role });
}
}The post redeems the row and writes the membership in one transaction. The role comes from the invitation's row, never from the request. Afterwards the session forgets the id:
import type { Authenticated } from '@marmeon/auth';
import { err, ok } from '@marmeon/core';
import { Connections } from '@marmeon/database';
import { abort, Controller, type HttpContext } from '@marmeon/http';
import { Session } from '@marmeon/session';
import { InvitationRepository } from '../InvitationRepository.ts';
import { PendingInvitation } from '../PendingInvitation.ts';
import { MembershipRepository } from '../../workspaces/MembershipRepository.ts';
export class AcceptInvitationController extends Controller {
readonly #connections: Connections;
readonly #pending: PendingInvitation;
readonly #invitations: InvitationRepository;
readonly #memberships: MembershipRepository;
readonly #session: Session;
constructor(connections: Connections, pending: PendingInvitation, invitations: InvitationRepository, memberships: MembershipRepository, session: Session) {
super();
this.#connections = connections;
this.#pending = pending;
this.#invitations = invitations;
this.#memberships = memberships;
this.#session = session;
}
async handle(ctx: HttpContext<Authenticated>) {
const invitation = await this.#pending.require();
const accepted = await this.#connections.transaction(async () => {
// Used up meanwhile: the lost redeem answers like a link that never existed.
if (!(await this.#invitations.redeem(invitation.id))) return err({ kind: 'used' });
const added = await this.#memberships.tryInsert({ workspace_id: invitation.workspace_id, user_id: ctx.user.id, role: invitation.role });
// Already a member: the err rolls the redeem back, so the invitation stays open.
return added.ok ? ok(invitation.workspace_id) : err({ kind: 'member' });
});
if (!accepted.ok) abort(404);
this.#session.forget('invitation');
return this.redirect().route('workspaces.show', { workspace: accepted.value });
}
}The sign-in link on the page points to /invitation/continue, which sends a guest to the sign-in and back
(sending a guest from an open page to sign in and back).
A sign-in keeps the session's data, so the invitation's id is still there afterwards. For a visitor who has no account yet, see
an invitation for someone without an account.
A public page that carries a token only sometimes
A page that is public for everyone and holds a token in its query only for some visitors (?invite=, ?g=) is no credential
without the parameter. Name the parameters, and the headers follow the request:
Route.middleware(credentialPage({ query: ['invite'] })).get('/events/:event', ShowEventController);A request whose query has invite (also ?invite= with no value) gets the headers above; any other answer stays as the route made
it. A cache keys on the whole URL (check that your CDN does not ignore the query string for this path), so the page without the parameter may be cached while ?invite=… never is. Names are matched
exactly, Invite is another parameter. Leave query out for a route whose path is the credential.
Two credentialPage() on one route, each for its own parameter, give the stricter Referrer-Policy to a URL that has both: with
?g= (no-referrer) and ?invite= (referrer: 'same-origin'), the answer is no-referrer, so neither token travels in a same-origin
Referer. same-origin sends the URL, token included, to your own origin, so choose it only as in "A form behind a token" above.
Keys
APP_KEY encrypts cookies, encrypted jobs and sealed sessions, and the keys that sign URLs, live channels and uploads are derived
from it. Anyone who has it can read and forge all of them. Generate it once per environment with marmeon key:generate, keep it
out of the repository and out of the image, and rotate it with APP_PREVIOUS_KEYS, so that old cookies and signed links stay valid
until they expire. The encryption page explains the key and its rotation. After a leak the procedure differs: do not keep the leaked key, see ending every session of every account.
Pages and scripts
- Content Security Policy.
contentSecurityPolicy()gives every document a policy with a fresh nonce: scripts only with that nonce, and the chunks they load, no plugins, no foreign<base>. Every new app turns it on. A nonce must never reach a shared cache: the app warns when a publicly cached page carries one. The Content Security Policy page explains the policy. - Styles without
'unsafe-inline'. The framework renders nostyleattribute, sostyleSrc: ["'self'"]blocks nothing of its own in a built app. Your ownstyleprops need classes then, and@marmeon/react/styles.cssis imported in the client entry. The styling page shows how. - Escaping. React escapes what pages render. HTML you write by hand goes through the
htmltemplate of@marmeon/core, as the responses page shows. Page data travels as JSON in an inert<script type="application/json">. The browser reads an island's or a deferred group's streamed data only from such a script with its ownid, so sanitised user HTML that guesses anidcannot replace it, and a deferred block only fills the props of its own group. - Security headers. A new app lists
securityHeaders()from@marmeon/http, which sendsnosniff, a strictReferrer-PolicyandX-Frame-Options: DENYon every response. Itshstsoption forStrict-Transport-Securityis off until you turn it on, once the site answers over HTTPS alone; no route can weakennosniffor HSTS. The Content Security Policy page lists them. - Behind a proxy,
X-Forwarded-*headers count only from the addresses inSERVER_TRUSTED_PROXIES. Otherwise any client could choose its own address, for rate limits and logs, and its own scheme.*trusts the direct peer only, and is safe only when nothing but your proxy can reach the app. The deployment page explains the values. - No compression of documents. A compressed page that holds a secret next to text an attacker controls leaks the secret byte by byte. The framework compresses assets at build time and never pages; leave pages uncompressed at the proxy too, as the deployment page says.
Strict-Transport-Security
The first visit to http://your-site is open to an attacker on the path, who can keep the browser on plain HTTP (SSL stripping).
Strict-Transport-Security tells a browser that has seen it to use HTTPS alone for the maxAge you give. It is off until you
turn it on, because browsers hold on to it: switch it on once the site answers over HTTPS only, with a short max-age first.
securityHeaders({ hsts: { maxAge: { days: 365 }, includeSubDomains: true } })maxAge: 0 withdraws it from the browsers that have seen it. The header is sent on HTTPS responses only; behind a proxy that
means SERVER_TRUSTED_PROXIES and its X-Forwarded-Proto. A proxy may set the header instead of the app.
marmeon check warns when it finds none, before you go live.
Accounts
- Passwords are hashed with Argon2id, within bounds that a planted hash cannot exceed. The hashing page explains the drivers and costs.
- Rate limits. The starter kit limits the sign-in per address and client together, the registration per client, reset mails per client and per address, and a signed-in user's password checks per sign-in, and per account for a sign-in that did not begin with a typed password: the confirmation, the password change and "sign out other devices". The password change and "sign out other devices" run one at a time per session. The rate limiting page covers limiters.
- A session ends with the account's session key, not with its password hash. Every new password, reset and "sign out other
devices" writes a new key, and a session keeps only a fingerprint of the account's id and that key. A rehash at sign-in (new
HASH_*costs) writes the hash alone and ends nothing, so raising the costs signs nobody out. A hash you write yourself, in an admin tool or a script, ends no session either: write a new key with it, or callAccountSessions.end(). The authentication page explains how. - A sign-in tells nothing. An unknown address and a wrong password get the same answer in the same time. The authentication page explains how.
- Validation never tells whether a record exists while a field is typed. The
uniqueandexistsrules and an asynccustom()do not run in a live validation unless the rule says.live(), which a rule that asks about accounts must never do. Without it, a free and a taken address get the same answer there, and only a submit tells, behind its rate limit. A schema of another library runs live only when its request sayslive: true, which a form that asks about accounts must never say either. The unique index stays the truth:failOnDuplicate()turns its conflict into a 422. The validation page explains why. - Mail goes out encrypted or not at all. SMTP uses TLS from the first byte, or requires STARTTLS, so a server without it, or
someone who strips the offer, never sees the credentials or a reset link.
MAIL_REQUIRE_TLS=falseturns the requirement off, for a local relay only. The mail page has the settings. - Policies decide what a user may do, on every request: the session's user on a page, the token's user on a route behind
authenticate('api'). Authorize an API route with the token's abilities and a policy. An ability only says what kind of action a token may do, never on whose record, so it alone leaves the records of every user open to whoever changes an id. The authorization page shows both on one route. - Every route says who may call it. The app does not start with a route that does not, and
abilities()is not that decision. The authorization page shows the check and its limits. - Open routes that change something have a limit.
marmeon checkwarns at aPOST,PUT,PATCHorDELETEroute that anyone may call, that is not behind a sign-in and that nothrottle()limits: a contact form or an invitation to accept is free spam, brute force and cost (mails, jobs) otherwise. The check page says what it finds, and what it cannot.
Private registration
The registration of the starter kit never tells whether an address has an account. This is the default:
- Every registration gets the same answer in the same time. The owner of a known address gets a mail instead of a second account.
- Registering signs nobody in. The auth module's pages ask for a confirmed address, so whoever registered with somebody else's
address sees only a notice, and the owner takes the account over with a password reset. Your own routes need
verified()for the same: the email verification page explains it. - A change of address waits until the link sent to the new address is opened, with the same answer for a free and a taken address.
Open registration
AUTH_PRIVATE_REGISTRATION=false turns all of this off. The registration and the change of address then say "taken", a new account
is signed in at once, and a new address takes effect at once. From then on only the registration's rate limit stands between the
form and a list of who has an account. Outside development and tests the app logs a warning about it at every start. Turn it off
only when the accounts of your app are public anyway. The starter kit page shows the switch.
An unconfirmed account is then a working account. Whoever registers with somebody else's address uses it at once: the module's
ConfirmedAddress lets every signed-in user through, which is why the kit puts verified() on the routes that add a factor or create a token; your own routes need it too. When
the owner later takes the account over with a password reset, its sessions and remember-me tokens end. An API token created in the
meantime ends with them too, because the address was not confirmed (see below); an API token of a confirmed address ends only with
AUTH_REVOKE_TOKENS_ON_PASSWORD_CHANGE=true.
The routes that add an authenticator app or a passkey sit behind verified() in every registration mode, so an account whose address
nobody confirmed cannot attach a second factor of its own. And the password reset of such an account (email_verified_at and first_verified_at are null: the address was never confirmed)
removes its passkeys, its authenticator, its recovery codes and every API token, whatever AUTH_REVOKE_TOKENS_ON_PASSWORD_CHANGE says, and with @marmeon/oauth the provider accounts linked to it
(whenever email_verified_at is null or missing; see Linking and unlinking):
the owner proved the mailbox with the link, and nothing the first registrant attached stays. The reset leaves the address unconfirmed;
the owner confirms it with the link of the notice page. An account that was confirmed once and then changed to an address not confirmed
yet keeps its factors in a reset, but loses its API tokens: whoever confirmed the earlier address may have created them and then
changed the address to one they do not own. An account with a confirmed address keeps its factors in a reset, and its API tokens
unless AUTH_REVOKE_TOKENS_ON_PASSWORD_CHANGE=true.
Accounts nobody confirmed
auth:prune-unverified deletes accounts whose address was never confirmed, AUTH_UNVERIFIED_DAYS days after the sign-up, 7 by
default. An account confirmed once is never deleted. The command runs only when your app turns its line on in
modules/auth/schedule.ts, because deleting accounts is your app's decision. Once it runs, whoever registered with somebody
else's address stops holding it, and nothing of an unfinished sign-up stays: the account, its tokens and what other modules keep
go, and its sessions end. With open registration, such an account was signed in and may have used the app before it goes. Without
the line, these accounts stay: decide it for your app. The email verification page
explains the rules.
Secret columns and raw SQL
Which columns are secret comes from the migrations (how the app knows its schema), so the guard covers what the blueprint made and nothing else:
- A table that raw SQL, a view or another tool made has no secret columns, soft deletes or timestamps, and
selectAll()on it isselect *. Create what holds secrets withschema.create()and mark the column.secret(). - Raw SQL, in a query or in a migration, is not checked:
sql`select * from users`returns the hash. - A connection with
managed: falseknows no secret column at all. - A process that runs older code against a newer database selects only the columns it knows, so a column a newer migration marks
secret is not in its
selectAll()(migrating a running app).
Tables and exports
A table of @marmeon/table is one definition the server enforces on every request. These are the attacks of hand-written tables,
and what stops each:
- Hidden columns stay hidden. A column the policy hides is not selected: not in the SQL, so not in the props, the devtools' query log, a cursor or an export. The props are picked by name besides.
- No sort oracle. Sorting, filtering or searching by a column the user cannot see is a 400, as is any sort, filter or page size
the definition does not name, such as
?sort=passwordor?per_page=10000. An order by a secret would tell its values without showing them. Nothing from the URL reachesORDER BYorWHEREthat the definition did not name. - No bulk IDOR. A bulk action acts on the keys sent, within the base query, and only on rows the policy allows. Another
tenant's key or a made-up one is left out as missing, and a row the policy refuses is skipped. "All matching" sends the filter,
never keys, and the server refuses more rows than the action's
maxwith 422. Put the tenant into the base query: every endpoint starts from it. The endpoints take the middleware of the page's route registrar, not the page controller'sauthorize, so a table that needs one declares it. - No CSV injection. Exported text cells that start with
=,+,-,@, a tab or a line break get a'in front, and every field is quoted. An export has its ownauthorizeand a row limit, 10 000 by default, beyond which it answers 422 before the first byte. Rate-limit it as well: it reads the whole filtered table. A download is not recorded by itself: addexportCsv().onExport(Recorder)and itshandle()runs before the first byte of every export that was allowed, and a recorder that throws stops the download (exports). - Keys are parsed by their declared type before any query, so text never reaches an integer column.
The cursors of cursorPaginate() and of cursor tables are encrypted with the app key: a hidden sort column's value never shows in
a URL, and a changed or made-up cursor is a 400. The tables and
pagination pages explain both.
Live updates
Live props send hints, never data. A tab that gets a hint reloads through the page's route, its middleware and its policies, so a
hint can never show what the user may not see. A subscription is signed for its session, and another channel or another session's
token answers 403. Limits keep one user from exhausting a process: at most 16 streams per session
(LIVE_MAX_STREAMS_PER_SESSION, beyond it 429 and a warning in the log), 1000 per process (LIVE_MAX_STREAMS, beyond it 503) and
20 channels per stream. The limit per session counts by session, not by address; a flood of fresh sessions meets the limit per
process, so limit connections at the proxy as well. The real-time updates page explains them. A stream checks its
sign-in whenever it opens, and ending an account's sign-ins (a new password, AccountSessions, an ended sign-in) closes its open
streams at once; a stream also closes after LIVE_MAX_STREAM_SECONDS (15 minutes) and is checked again.
Requests your server sends
An address that a user or an editor enters, a webhook URL or an avatar, decides where your server connects. Send it with
HttpClient of @marmeon/fetch and not with a bare fetch(): the client refuses loopback, private and link-local addresses (the
cloud metadata address included), for a name too, checks every redirect and limits time and size. No environment allows a private
range by itself; FETCH_ALLOWED_ADDRESSES lists the ranges you reach on purpose. The check that counts runs when the request is
sent, not when the form is validated. The HTTP client page explains it.
A chat webhook is such an address and a credential as well: whoever has it can post to the channel. @marmeon/chat-notifications
accepts only the hosts and paths of the provider's driver, over https, and never logs an address. A queued message travels
encrypted, and the content a message carries is shown as plain text, so a user's data cannot ping a channel or inject a link. Keep a
recipient's own webhook address in a column marked .secret(), which selectAll() leaves out and a query reads with
secret(), and take only addresses that chat.check() accepts. See chat notifications.
Logs and recordings
The log masks the values of keys that look like secrets, such as password, token, cookie or authorization, in nested
objects too, and the names packages add to the app's Redactor, such as the session cookie's. A URL in the context, and the
message and stack of an error under any key, are masked as text. Every other string, the message included, is written as it is,
so never put a secret into one. The logging page lists the rules, and
the app's Redactor for text you must log.
The devtools' recordings, the development error page and traces go further: the same Redactor also masks every string there.
The devtools exist in development only and refuse other hosts. The logging page
explains what each shows.
Traces
With @marmeon/otel, a request from outside starts a trace of its own, and an incoming traceparent header is only a link to the
caller's span. A client cannot put its requests into a trace it chose, nor switch their recording on or off with the sampled flag,
and its baggage is dropped. MARMEON_OTEL_TRUST_TRACEPARENT=true continues the caller's trace: set it only behind an edge that sets or
strips the header, such as a gateway, an ingress or a mesh. SERVER_TRUSTED_PROXIES is no reason, since a proxy usually passes the
client's header on unchanged. The observability page covers tracing.
Your checklist
NODE_ENV=production, or another protected value, in the server's environment, and no developer's.envon the server.APP_URL=https://…, and a freshAPP_KEYper environment, kept in the server's secrets.contentSecurityPolicy()inbootstrap/app.ts, which a new app has. New inline scripts takectx.nonce(). With astyleSrc, classes instead ofstyleprops, and@marmeon/react/styles.cssimported in the client entry.- The lifetimes of a sign-in:
AUTH_SESSION_MAX_HOURSas long as you accept a stolen session to work (24 hours by default),AUTH_REMEMBER_DAYSfor "Keep me signed in" (a convenience at AAL1; 30 at most, 0 turns it off), andSESSION_LIFETIME_MINUTES=60where AAL2 is needed, which holds only behindtwoFactor(). How long a sign-in lasts lists them all. - The
sign_instable (marmeon make:sign-ins-tablefor an app without the starter kit), andauth:prune-tokensscheduled (sign-ins). The starter kit does both. - A
UserProviderthat writes its hash and session key withcredentialWriter()(the starter kit's does), and stores of your own that extend the abstract classes and never aDatabase…store (what your app implements). A provider that writes the statements itself tests that a staleexpectedand a staleexpectedSessionKeyreturnfalse. - After an incident,
AccountSessionsends every session and remember-me cookie of an account (ending every session of a user). After a leak,marmeon auth:end-all-sessions --forceends every session of every account (ending every session of every account). - Your own controllers for sign-in, password reset, address change and passkey sign-in call the services of
@marmeon/authand keep none of their checks themselves:Auth.attempt(),checkPassword(),PasswordBroker,EmailChange,Passkeys. The limits inside them come with them. Theauth.*limiters sit on the starter kit's routes; put the matchingthrottle('auth.…')on your own route (what the package decides). The registration is the app's: its answer for a taken address, its mail limits and its pruning of unconfirmed accounts are the starter kit's code, or yours. - A request to an address from a user or an editor goes through
HttpClient, not a barefetch()(requests your server sends). - No
sql.raw()orsql.lit()with a value from a request:marmeon checkreports each one that is not a literal (raw SQL). - No
dangerouslySetInnerHTMLorinnerHTMLwith a value from a request: show it as text.marmeon checkreports each one that is not a literal (HTML from code). verified()afterauthenticate()on every route of your own that signed-in users reach.- Every route of your own has a decision that you chose: a policy for a record,
everyoneonly when anyone the middleware lets through may call it.marmeon route:listshows theACCESSof each route. marmeon devover HTTPS or withallowedHosts: trueonly on a trusted network. Staging private, since it shows server errors.- Whether unconfirmed accounts go: the
auth:prune-unverifiedline inmodules/auth/schedule.ts, andAUTH_UNVERIFIED_DAYSas you want it, 7 by default. WithAUTH_PRIVATE_REGISTRATION=false, tell your users that an unconfirmed account goes, and setAUTH_REVOKE_TOKENS_ON_PASSWORD_CHANGE=true. abilities()on every API route that acts: without it, every token of a user acts with all of the user's rights.MARMEON_OTEL_TRUST_TRACEPARENTonly behind an edge that owns the header, andMARMEON_OTEL_RECORD_QUERY_VALUESonly when your URLs carry no personal data.- HSTS once the site answers over HTTPS only: the
hstsoption ofsecurityHeaders(), or the proxy.marmeon check --only=boot,hstswith the production environment tells you whether the app sends it. SERVER_TRUSTED_PROXIESset to exactly your proxy, or*for the direct peer when nothing else can reach the app. The proxy setsX-Forwarded-*itself and does not compress pages.SESSION_ENCRYPT=truewhen the session store is shared.- Tables: the tenant in the base query,
endpoints()attached to the page's route, anauthorizefor exports, athrottleon the table's routes. - Update the framework's packages together and read UPGRADING.md. Security fixes go to the latest minor version (and, from 1.0 on, to the previous major for 12 months), as the releases page explains.