Security
This page covers how masks keeps tenants apart, limits managers and attackers, tells actors about changes, and hardens the requests apps send.
Two related subjects live on other pages:
- How masks encrypts secrets at rest: self-hosting.
- How to block a device before it can try a password: sessions and devices.
Tenant isolation
Section titled “Tenant isolation”masks keeps each tenant’s data apart in four ways:
- The app limits every query to the current tenant.
- Postgres row-level security filters every row by tenant, so a query the app forgets to limit still sees one tenant’s rows.
- Each tenant signs tokens with its own keys. A token from one tenant fails verification in every other.
- Each tenant’s encrypted columns use a key made from the primary key and the tenant’s ID. A value moved into another tenant fails to decrypt.
Some database roles get around row-level security:
- A
SUPERUSERorBYPASSRLSrole skips every policy, with no error. - The role that owns a table can switch its policy off with one
ALTER TABLE.
So masks checks its database role the first time it enters a tenant:
- It refuses to run as a role that holds either privilege.
- Outside development and test, it also refuses a role that owns a table that row-level security protects. Engine mode skips this check.
- It refuses a connection pooler in transaction mode, which drops the tenant between one statement and the next. See connection poolers.
This is why the server migrates as one role and serves as another. See database roles.
Entering a tenant
Section titled “Entering a tenant”masks enters a tenant before it runs any request or job.
-
A request enters the tenant its hostname names. A hostname with no tenant gets a 404 (Not Found) response.
-
A job enters the tenant it was enqueued in. A job enqueued outside a tenant raises an error. A job that works across every tenant must declare it:
class CleanupJob < ApplicationJobacross_tenants!end
Other code that works across tenants uses Tenancy.switch(tenant) { ... }. Outside a tenant, a query
on a tenant’s table returns no rows.
Manage roles
Section titled “Manage roles”Each manager holds one or more of four scopes.
| Scope | Can |
|---|---|
masks:manage:read |
Read everything /manage shows, and download activity. Change nothing. |
masks:manage:support |
Read. Help actors: add, invite, and approve them, change their profiles, sign them out, suspend and restore them, reset passwords and second factors, and block their devices. Revoke their sessions, consents, and tokens. Change organization members. |
masks:manage:security |
Read. Change signing keys, clients, SAML applications, providers, sign-in policies, sending services, event streams, organizations, groups, namespaces, and domain claims. Issue provisioning tokens for one organization. |
masks:manage |
Everything. This includes tenant settings and branding, risky networks, email templates, LDAP, serving a custom domain, the key rotation schedule, deleting actors, and granting any scope. |
How masks checks a role:
- A token for
/managecarries the scopes the actor holds and/manageasked for. - On every request, masks uses only the roles that both the token and the actor still hold.
- Every mutation in the manage API needs one role. A mutation that names none
needs
masks:manage. - For a manager below
masks:manage, a line at the top of each page in/managesays what they can change.
Taking a role away takes effect on the actor’s next request. When they hold no manage role at all, masks refuses their token.
Limits on the narrower roles
Section titled “Limits on the narrower roles”A role below masks:manage has these limits:
-
It cannot change another manager. This includes a session, token, consent, connection, or device that belongs to a manager. So support cannot change a manager’s email address and then reset their password.
-
It cannot take over anyone’s account. Three actions need both
masks:manage:supportandmasks:manage:security, ormasks:manage:- changing an actor’s email address
- generating their backup codes
- receiving a password reset link when masks cannot email the actor
Support can still send a reset link to the actor’s own email address. It can also reset the actor’s second factors.
-
It cannot give out manage access. It cannot give an actor or a client any manage scope or
masks:scim. It cannot issue a provisioning token for every account. Either one would reach managers through SCIM. -
It cannot change a client that can carry a manage scope or
masks:scim. So it cannot point/manageat another address. -
It cannot connect
/managein a new browser. It can open/managein a new browser once an owner has connected it.
Rate limits
Section titled “Rate limits”A rate limit counts attempts over a period of time. Once the count reaches the limit, masks refuses more. An API answers with the HTTP status 429 (Too Many Requests). A page in the browser shows a message.
Every limit is a named budget with a default. An operator sets one with its environment variable or
under limits: in MASKS_CONFIG. Each time a budget runs out, masks records one limit.reached
event for that budget, address, and window, so a flood shows up in the activity as one line. See
rate limits for every budget and its default.
These limits are fixed:
| Endpoint | Limit |
|---|---|
| Token, pushed request, device authorization, and SAML sign-in and logout | 60 per IP address each minute |
| Introspection and revocation | 120 per IP address each minute |
| SCIM and received security events | 600 per IP address each minute |
Enrollment, forward authentication, and /metrics |
30 per IP address each minute |
| Enrollment tokens | 60 per app each hour |
| Organization invitations | 30 per account each minute |
| Account download | 5 per account each hour |
Risky sign-ins
Section titled “Risky sign-ins”masks can give each sign-in a risk score from 0 to 100. It does this when a sign-in policy sets a score to act on. The score is worked out right after the first factor.
| Signal | Adds |
|---|---|
| A device the account has not signed in from in 90 days, or no device at all. A trusted device does not count. | 30 |
| A network the account has not signed in from in 90 days. For IPv4, a network is the addresses that share the first three numbers (a /24). For IPv6, it is a /48. | 25 |
| An address in one of the tenant’s Risky networks | 50 |
| Three or more refused attempts on the account in the last hour. Ten or more adds 40 instead. | 20 |
| No sign-in for six months | 10 |
| A password found in a known breach | 40 |
An account with no sign-in in the last 90 days has nothing to compare, so the device and the network add nothing.
To act on the score, use Risk in a sign-in policy:
- Ask for a second factor at a score of asks for a second factor from that score up. An account without one is asked to add one, as in step-up.
- Refuse at stops the sign-in from that score up, and asks for the first factor again. It must be higher than the score that asks for a second factor.
Any score above zero is recorded as sign_in.risky, with the signals, and the actor gets a security
email.
A manager holding masks:manage lists the tenant’s risky networks under Settings, then
Policies, then Who may sign in.
Breached passwords
Section titled “Breached passwords”Refuse passwords found in known breaches checks passwords against the Pwned Passwords range API. It checks each new password an actor chooses, at signup, from an invitation, at a reset, or on the account page. It also checks each password used to sign in.
The password never leaves the server:
- masks takes the password’s SHA-1 hash, a fixed-length code computed from the password.
- It sends only the first five characters of the hash.
- It compares the rest of the hash itself.
What masks does with the result:
- A new password that is breached is refused.
- A breached password used to sign in adds to the risk score.
- If the service does not answer within three seconds, or answers with an error, masks allows the password.
Security emails
Section titled “Security emails”masks emails an actor when something changes on their account.
| Group | Sent when |
|---|---|
| Password | The password is changed or reset. |
| Factors | A passkey, an authenticator app, or email or SMS codes are added or removed. Backup codes are generated, or one is spent. The actor asks for help, or a manager resets their second factors. |
| Sessions | A new device signs in. A sign-in gets a risk score above zero. A session is signed out. A device is blocked. |
| Apps and connected accounts | An app is allowed in. A connected account is connected or removed. A device sign-in is approved. |
| Account | The phone number is changed or removed. A manager changes the actor’s scopes. The actor downloads their account. |
| Organizations | Someone else changes the actor’s role in an organization, or removes them. Someone archives an organization the actor is signed in to an app for. See what members are told. |
- masks reports a new sign-in once per device.
- Emails go only to a confirmed address. An account with no confirmed address gets none, and the account page says so.
- An actor can turn an email off under Emails we send you on the account page. A changed password, a reset password, and a risky sign-in are always sent. Changing which emails arrive asks for a sign-in within the last 15 minutes, and the change is recorded in the account’s activity as Notifications changed.
- When the email address changes, masks also warns the previous address. This warning goes out even if the old address was not confirmed or the actor turned the group off.
- Each email names the device and the IP address the change came from, in the actor’s time zone.
- An email about an approved app, such as one sent while someone signs in to it, is headed by that app’s logo and name. Every other email is headed by the tenant. An app nobody approved never heads an email, so a self-registered app cannot use the tenant’s mail to pass as someone else.
To preview every email masks sends, open Settings, then Messages, then Templates in
/manage. Each preview uses sample actors and the tenant’s own name and links.
Editing an email template
Section titled “Editing an email template”A manager holding masks:manage can edit these emails on the same page:
- invitation
- organization invitation
- password reset
- email confirmation
- confirmation code
- approval request, sent to managers
- request for help, sent to managers
- approval
They can also add Closing lines on every email.
- The Subject (up to 150 characters) and the Opening text (up to 2,000 characters) replace the ones masks writes. Leave either blank to keep masks’ own.
- Both are plain text. Markup shows as written, and no link can be added. A blank line starts a new paragraph.
{{tenant}},{{name}},{{nickname}},{{organization}},{{role}}, and{{code}}are placeholders. The page lists which ones each email offers. A placeholder an email does not offer is refused.- masks still adds the button or the code, how long it lasts, and the lines that tell an actor what to do if it was not them. A password reset that a manager started still names the manager.
- A template applies in every language the tenant serves.
- masks records each change as
mail_template.updated.
Keeping and exporting activity
Section titled “Keeping and exporting activity”masks keeps each event for 180 days by default. A manager holding masks:manage changes this under
Settings, then General, then Activity, from 30 days to seven years. Older events are
deleted each night, so a shorter period takes effect the next night.
To download a copy:
- Open Settings, then Activity.
- Choose a range of up to 366 days under Export.
- Choose Download.
About the file:
- It has one event per line, as JSON, in the same shape that event streams send.
- It follows the filter on the page.
- Any manage role may download it. masks records each download as
events.exported. - The link lasts ten minutes. It works only in a browser signed in as the manager who asked for it.
- A range with more than 250,000 events is refused.
For a copy that keeps up to date on its own, use an event stream.
Calls to other servers
Section titled “Calls to other servers”masks calls addresses that apps and managers supply. A bad address could make masks call a server on a private network, so masks checks each one. The calls are:
- a client’s keys, sector identifier, logo, metadata document, back-channel logout, SAML single logout, and shared signals endpoint
- a resource’s protected resource metadata
- every provider’s endpoints and SAML metadata
- each mail and SMS service
- each event stream’s endpoint
- the Pwned Passwords API
For each call, masks:
- looks up the hostname, and refuses it if any of its addresses is private, loopback, link-local, or reserved
- connects to the address it checked, for every call except mail
- stops at a time limit and a size limit
In development and test, masks allows http and private addresses.
Some apps and providers live on a private network, such as a tailnet (a private network across your
devices) or an identity provider inside the office. List their address ranges in
MASKS_OUTBOUND_ALLOWED.
Rotating signing keys
Section titled “Rotating signing keys”masks publishes a new key before it signs anything with it. Clients that cache the keys then have the new key before they see a token it signed. See signing keys for the states a key moves through.
Managers holding masks:manage:security or masks:manage rotate keys under Settings, then
General, then Signing keys.
| Action | Does | The outgoing key |
|---|---|---|
| Stage | Publishes a new key ahead of time. One at a time. | Keeps signing. |
| Activate | Makes the staged key the signing key. | Verifies for 24 hours. |
| Rotate now | Makes a key and signs with it at once. Use it when caches cannot wait. | Verifies for 24 hours. |
| Discard | Removes a staged key, which has signed nothing. | Keeps signing. |
SAML applications must read masks’ metadata again after a key is staged, and before it is activated.
Rotating on a schedule
Section titled “Rotating on a schedule”A new tenant rotates its keys every 90 days. A manager holding masks:manage changes Rotation
to every 30, 180, or 365 days, or to By hand. A tenant set up before masks-server 0.13 is still
By hand, and the health panel says so until a manager picks a schedule. A daily job then:
- Stages the next key a day before the active key reaches that age.
- Activates a key once it has been staged for a day.
With a schedule set, a key staged by hand is also activated a day after it is staged. The job records each step in the activity.
Where a sign-in error goes
Section titled “Where a sign-in error goes”A bad /authorize link ends with an error. Where masks sends that error depends on who registered
the client.
- An approved client hears the error at its
redirect_uri, witherror,error_description,state, andiss, as OAuth describes. - A self-registered client’s errors show on a page on masks. The person stays on masks and reads
what went wrong. Nothing is sent to the client’s
redirect_uri.
This covers errors masks finds in the request, such as a scope the client does not hold, an
unsupported response_type, or a request object that fails a rule, and sign-ins masks refuses, such
as a suspended account, a group the person is not in, or a consent the person declined.
Two answers go back to the redirect_uri whoever registered the client, because OpenID Connect
requires them: interaction_required for a prompt=none request that needs the person, and a
redirect_uri on masks’ own origin.
Registration is open by default, so anyone can register a client with a redirect_uri of their own.
Without this rule, a link that starts at masks could bounce a person to any site with one bad
parameter.
Pushed requests
Section titled “Pushed requests”A normal authorization request puts every parameter in the address bar. There, browser history, logs, and later pages can read it.
A pushed request (RFC 9126) sends the parameters
from the client’s server straight to /par. Only a reference goes in the URL. Discovery advertises
pushed_authorization_request_endpoint.
-
Post the parameters to
/par. Authenticate the same way as at/token. Includeclient_idin the body, even with Basic auth. A public client sends itsclient_idand no secret.Terminal window curl -u "$CLIENT_ID:$CLIENT_SECRET" https://demo.auth.example.com/par \-d client_id="$CLIENT_ID" \-d response_type=code \-d redirect_uri=https://app.example.com/cb \-d scope="openid profile" \-d code_challenge="$CHALLENGE" \-d code_challenge_method=S256 \-d state="$STATE"{"request_uri": "urn:ietf:params:oauth:request_uri:8mZ1...","expires_in": 90} -
Redirect to
/authorizewith only the client ID and the reference:https://demo.auth.example.com/authorize?client_id=...&request_uri=urn%3Aietf%3Aparams%3Aoauth%3Arequest_uri%3A8mZ1...
The reference lasts 90 seconds, works once, and works only for the client that pushed it. Following
it twice, late, or with another client_id returns invalid_request_uri.
Requiring pushed requests
Section titled “Requiring pushed requests”mutation { updateClient(clientId: "...", requirePushedAuthorizationRequests: true) { client { clientId } }}After this, masks refuses a plain /authorize link for that client with invalid_request. A
self-registered client can ask for the same setting when it registers.
Signed requests
Section titled “Signed requests”A client with jwks or a jwks_uri can send the whole request as a signed JWT, a JSON token with a
signature. This is called a request object (RFC 9101),
and it holds the parameters as claims:
{ "iss": "$CLIENT_ID", "aud": "https://demo.auth.example.com", "client_id": "$CLIENT_ID", "exp": 1789000300, "nbf": 1789000000, "jti": "5c1f...", "response_type": "code", "redirect_uri": "https://app.example.com/cb", "scope": "openid profile", "code_challenge": "$CHALLENGE", "code_challenge_method": "S256", "state": "$STATE"}Send it as request, next to client_id, to /authorize or /par.
| Claim or property | Rule |
|---|---|
typ |
oauth-authz-req+jwt, application/oauth-authz-req+jwt, jwt, or none. |
| Signature | RSA, RSA-PSS, or ECDSA, with a registered key. none and shared secrets are refused. |
iss |
The client. |
aud |
This issuer. |
client_id |
The same as the client_id next to it. |
exp |
Required. At most an hour away. |
nbf |
Optional. Not in the future, and at most an hour ago. |
jti |
Optional. Used up on first use. |
- A pushed request or a request object is the whole request. masks ignores anything else in the
/authorizequery. - masks refuses a request object with
invalid_request_objectif it fails a rule, or if it holds its ownrequestorrequest_uri. requireSignedRequestObjectonupdateClientrequires signing, in the same way thatrequirePushedAuthorizationRequestsrequires pushing.- masks accepts only a
request_uriit issued from/par. It never fetches one from a client URL. - A key set read from a
jwks_uriis kept for five minutes. A key id masks has not seen makes it read the set again, at most once in those five minutes, so a stranger cannot make masks fetch an app’s keys over and over.
Binding a token with DPoP
Section titled “Binding a token with DPoP”A bearer token works for anyone who holds it. DPoP (RFC 9449) binds a token to a key the client keeps. A copied token is then useless without the key. masks binds a token for any client that asks.
-
The client generates a key pair and keeps it.
-
For each request, it signs a proof. A proof is a JWT typed
dpop+jwtthat names the method and URL, with the public key in its header. -
It sends the proof in the
DPoPheader:POST /token HTTP/1.1DPoP: eyJ0eXAiOiJkcG9wK2p3dCIsImFsZyI6IkVTMjU2Iiwiandr... -
masks returns a bound token:
{ "access_token": "...", "token_type": "DPoP", "expires_in": 3600 }
The token’s cnf claim holds jkt, the key’s SHA-256 thumbprint
(RFC 7638). A thumbprint is a short hash that identifies
the key.
To use the token, the client:
- sends it with the
DPoPscheme - sends a new proof every time
- includes
ath, the token’s hash, in each proof sent with a token
GET /userinfo HTTP/1.1Authorization: DPoP eyJhbGciOiJSUzI1NiIs...DPoP: eyJ0eXAiOiJkcG9wK2p3dCIs...What masks refuses
Section titled “What masks refuses”- a bound token sent as
Bearer - a proof whose
htmorhtunames another request - a proof with no
ath, or the wrong one - a proof older than 90 seconds, or more than 30 seconds in the future
- a proof with no
jti, or one already seen - a proof that holds a private key, a symmetric key, or
alg: none - any algorithm except
ES256,ES384,ES512,PS256,PS384,PS512, andRS256
A refused proof returns:
- at a resource,
401withWWW-Authenticate: DPoP error="invalid_dpop_proof"and the acceptedalgs - at
/token,400 invalid_dpop_proof
At a resource, a bound token with a valid proof made by another key returns 401 with
error="invalid_token".
masks sends no nonce.
Binding earlier
Section titled “Binding earlier”-
Authorization code.
dpop_jkton/authorizebinds the code to the key, so an intercepted code cannot be redeemed:GET /authorize?...&dpop_jkt=NzbLsXh8uDCcd-6MNwXF4W_7noWXFZAfHkxZsRGC9Xs -
Refresh token. A bound grant’s refresh token is bound too. masks refuses a proof that does not match before it uses up the refresh token.
Requiring a bound token
Section titled “Requiring a bound token”masks refuses a token without a proof to a client with dpop_bound_access_tokens set.
- A client sets it when it registers.
- A manager sets it with
dpopBoundAccessTokensonupdateClient.
{ "client_name": "...", "dpop_bound_access_tokens": true }Rich authorization requests
Section titled “Rich authorization requests”A scope says what kind of thing an app may do. authorization_details
(RFC 9396) says exactly what. For example, one payment of
123.50 euros to one payee.
Declaring a type
Section titled “Declaring a type”An approved client that serves these requests declares each type it accepts. It does this under
Authorization details on its Endpoints tab in /manage, in Types it accepts.
A declaration has:
- a label for the consent screen
- a schema
- optionally,
remember
{ "payment_initiation": { "label": "Send a payment", "remember": 2592000, "schema": { "type": "object", "required": ["instructedAmount"], "properties": { "instructedAmount": { "type": "object", "required": ["currency", "amount"], "properties": { "currency": { "type": "string", "enum": ["EUR", "USD"] }, "amount": { "type": "string", "maxLength": 20 } } }, "creditorName": { "type": "string", "maxLength": 140 } } } }}- A schema can use
type,properties,required,additionalProperties,items,enum,maxLength,maxItems,minimum,maximum,title, anddescription. - A field the schema does not list is refused, unless
additionalPropertiesistrue. rememberis a number of seconds, up to 400 days. Without it, the consent screen asks about the type every time.- Discovery lists every declared type in
authorization_details_types_supported.
Asking
Section titled “Asking”The app that asks:
- Registers the types it uses in
authorization_details_types, shown as Types it may ask for. - Sends the details as a JSON array to
/authorizeor/par, or in a signed request object.
GET /authorize?response_type=code&client_id=…&scope=openid &authorization_details=[{"type":"payment_initiation","instructedAmount":{"currency":"EUR","amount":"123.50"},"creditorName":"Merchant A"}]masks refuses these with invalid_authorization_details:
- a type nobody declared
- a type the app did not register
- an entry its schema does not allow
- more than ten entries
- more than 8 kilobytes
client_credentials does not accept them.
Consent
Section titled “Consent”The consent screen lists each entry with its label and fields.
- It asks about every entry, even when the actor allowed the app before.
- It skips an entry only when the actor allowed it before and its type sets
remember. masks keeps that allowed entry on the actor’s consent for that long. - If any entry in a request is not kept, the screen asks about all of them.
- An app that skips consent still asks about entries that are not kept.
The actor sees what is kept, and until when, under Apps you have let in on their account page. A
manager sees it on the actor’s and the app’s consents in /manage.
masks forgets a kept entry when the app is revoked, or when the client’s consent lifetime ends.
Tokens
Section titled “Tokens”- The granted details are in the token response, the access token’s
authorization_detailsclaim, and introspection. - At the token endpoint, the app can send
authorization_detailsto narrow an access token to some of the granted entries. - A refresh token keeps every granted entry.
- A token exchange passes them on or narrows them.
- Nothing can add an entry that was not granted.