TrayPage Docs

Security notes

What to take care of when self-hosting. Why the viewer host is separate, how to limit who can sign up, and signing in with your company IdP (OIDC).

When you self-host, you are responsible for the security configuration. Pay particular attention to keeping the viewer host separate and to limiting who can sign up. If people sign in through your company IdP, check that setup as well.

Keep the viewer host separate

Page content in TrayPage is arbitrary HTML written by users and AI agents, and it can include scripts. If that HTML were served from the same host (origin) as the app, scripts in a page could reach the app's cookies and sessions.

So TrayPage shows page content from a viewer host that is separate from the app, inside a sandboxed iframe with restricted permissions. In every setup, prepare two host names (domains).

SettingExample
APP_ORIGINhttps://traypage.example.com
VIEWER_ORIGINhttps://view.traypage.example.com

What to follow:

  • Use different host names for the two. If possible, use a separate domain, which also keeps the viewer out of the app's cookie scope.
  • The viewer host only returns shared page content and the health check response (/health). If you see the app's UI on the viewer host, the configuration is wrong.
  • On Cloudflare, set workers_dev to false once you have custom domains. If the workers.dev URL remains, it can be used to bypass the separation of the viewer host.
  • While no viewer host is configured (for example right after the first Cloudflare deploy), page content is served from the same host as the app. Configure it before you actually start using TrayPage.

Limit who can sign up

By default, anyone who can receive an emailed sign-in link can create an account (and, if Google sign-in or your company IdP is enabled, anyone with such an account). If you put TrayPage on the public internet, limit who can sign up with the settings below so strangers cannot create accounts and organizations.

SettingExampleMeaning
SIGNUP_MODEinvite_onlyopen (default) or invite_only
SIGNUP_ALLOWED_EMAIL_DOMAINSexample.comEmail domains allowed to sign up (comma-separated)
SIGNUP_ALLOWED_EMAILSadmin@example.comEmail addresses allowed to sign up (comma-separated)

Who can create an account with each combination:

SIGNUP_MODEAllowlist (domains / addresses)Who can create an account
opennoneAnyone (default)
opensetOnly email addresses that match the allowlist
invite_onlyset or noneOnly email addresses that match the allowlist, and email addresses invited to an organization or a page (the invitation must be unexpired and unused)

To start invite-only:

  1. Start with SIGNUP_MODE=invite_only and your first administrator's address in SIGNUP_ALLOWED_EMAILS.
  2. The administrator signs in, creates a team organization, and invites members.
  3. Invited people create their accounts with the invited email address, from the invitation email's link or the sign-in screen.

There is no "let the first person through" rule, because on a public server a stranger could be that first person. When you use invite_only, always put your first administrator in SIGNUP_ALLOWED_EMAILS.

With invite_only, anyone who has an account can create their own organization and invite other people, and the people they invite can create accounts. People invited to a page by someone who can share it can also create an account with the invited email address, just like an organization invitation. If only the server administrator should decide who can register, do not use invite_only. Keep open and restrict sign-up with the allowlist (domains or addresses).

How it behaves:

  • People who already have an account can always sign in, whatever the settings. Tightening the settings later does not delete existing accounts.
  • No sign-in email is sent to addresses that are not allowed.
  • The screen and the response are the same whether or not an email is sent. Deciding whether to send and delivering the email happen after the response, so the response time is also hard to tell apart. Anyone who can receive mail at the address, however, can tell whether an email arrived.
  • For the same reason, a failed delivery shows no error on the screen. If someone reports that sign-in emails do not arrive, check the server log for magic_link_delivery_failed (with the default settings, where anyone can sign up, the screen still shows an error as before).
  • While sign-up is limited, the sign-up screen and the shared-page sign-in show a short note saying so. They do not show which domains or addresses are allowed.
  • If someone signs in with Google or your company IdP using an address that is not allowed, no account is created and the sign-in screen shows "This email address can't be used to create an account. Contact your administrator." An address that Google or the IdP has not marked as verified cannot sign up either.
  • Email addresses are compared in lowercase. While sign-up is limited, the sign-in email is also sent to that form of the address. Addresses with + (name+tag@example.com) are treated as separate addresses.
  • Domains must match exactly (example.com does not include sub.example.com). Internationalized domain names cannot be used in the allowlist (write domains with ASCII characters only).

If a setting is wrong:

  • An unset, empty, or whitespace-only SIGNUP_MODE means open. Any other value that is neither open nor invite_only (a typo such as opne) is treated as strictly as possible: existing users can sign in, and only email addresses that match the allowlist can sign up (invitations do not let anyone sign up).
  • Invalid allowlist entries (such as *.example.com or something that is not an address) are ignored. If a value is set but has no valid entries, such as just ,, the allowlist still counts as set. No address matches an invalid entry (sign-up never falls back to letting anyone in).
  • In both cases a signup_policy_invalid log line is written (Docker: at startup; Cloudflare: when the sign-in screen is opened or a sign-in is attempted). On Docker, the signup_policy log line at startup also shows the current setting (mode, restricted for whether sign-up is limited, and the number of allowlist entries).

If you use TrayPage only inside your organization, you can also restrict who can reach it:

  • Docker / VPS: limit traffic to the server to your organization with a firewall or VPN
  • Cloudflare: limit access to the app domain with something like Cloudflare Access

If you share pages with people outside your organization, though, the viewer host and the shared page URLs must be reachable from outside. Be careful about what you restrict.

Sign in with your company IdP (OIDC)

People can sign in with an OpenID Connect (OIDC) IdP such as Okta, Google Workspace, or Keycloak. Once configured, a "Sign in with (IdP name)" button appears first on the sign-in screen and on the sign-in for shared pages. You can configure one IdP.

If you are locked out (the IdP is down, a setting is wrong, and so on), remove LOGIN_METHODS and restart (redeploy on Cloudflare). People can then sign in with an email link into their existing account with the same address.

Steps:

  1. In your IdP, create a client for TrayPage (a web application that uses a client secret). Register this redirect URI (callback URL):

    <APP_ORIGIN>/api/auth/oauth2/callback/oidc

    TrayPage requests the scopes openid, email, and profile. By default it sends the client secret in the Authorization header (client authentication method client_secret_basic). If the client is registered with client_secret_post in your IdP, set OIDC_CLIENT_AUTH_METHOD=client_secret_post.

  2. Set the following values and restart the app (redeploy on Cloudflare).

    SettingExampleMeaning
    OIDC_ISSUERhttps://example.okta.comThe IdP issuer. Write it exactly as the issuer in the IdP's discovery document (/.well-known/openid-configuration), including any trailing /. The discovery URL cannot be used
    OIDC_CLIENT_ID0oa1b2c3d4The ID of the client from step 1
    OIDC_CLIENT_SECRET(secret)The secret of the client from step 1. On Cloudflare run npx wrangler secret put OIDC_CLIENT_SECRET; with Docker put it in .env
    OIDC_DISPLAY_NAMEOktaThe name on the button. Defaults to SSO
  3. Check that the button appears on the sign-in screen and that you can sign in with it.

If any of the three values (OIDC_ISSUER, OIDC_CLIENT_ID, OIDC_CLIENT_SECRET) is missing, or the issuer is not https (http is allowed only for localhost), IdP sign-in stays off and the log shows oidc_config_invalid. If the issuer differs from the issuer in the IdP's discovery document, sign-in cannot start and the log shows oidc_sign_in_failed.

What happens on sign-in:

  • TrayPage looks up the account by the email address the IdP returns, and creates one for people who do not have an account yet. The signup restriction applies.
  • If an account with the same email address already exists (created with an email link or Google), it is linked only when the IdP says the address is verified (email_verified is true). This is the same rule as Google sign-in.
  • If the IdP does not say the address is verified, no account is created and no existing account is linked. This stops anyone from creating or taking over an account under someone else's address. The sign-in screen shows a short reason (it does not reveal whether an account exists).
  • On later sign-ins too, TrayPage checks that the verified email address the IdP returns now matches the email address of the TrayPage account. People whose address changed in the IdP (for example, they left the company and lost the company address) cannot sign in. The sign-in screen says that the address at the sign-in provider does not match this account, and the server log shows oidc_sign_in_failed with the reason and the TrayPage user ID (userId), without the address.
  • TrayPage checks the signature, issuer, audience (client ID), expiry, and nonce of the ID token from the IdP before using it. It also checks the IdP configuration (discovery) before sending people to the IdP and before sending the client secret. TrayPage uses the IdP's access token only to fetch user information (UserInfo) and does not store it; it does not store ID tokens or refresh tokens either. If a check fails, the sign-in screen shows "Authentication failed" and the server log shows oidc_sign_in_failed with the reason.
  • After sign-in, people return to where they started (for example, a shared page). Only URLs of this app are accepted as the destination.
  • TrayPage remembers an IdP account by the pair of the IdP (issuer) and the user's ID in the IdP (sub). If you switch to another IdP, its accounts are treated as different from those of the previous IdP. If the email address is the same, the account is linked to the existing one by the rule above.
  • If the IdP reassigns an email address to another person (another ID in the IdP), and the TrayPage account with that address is already linked to a different ID of this IdP, the new owner is not linked. The sign-in screen shows the same message as above, and the log shows the reason and the user ID. This keeps the new owner out of the previous owner's data. However, if the previous owner has never signed in with this IdP (they only used email links), the new owner is linked as a first link. If your IdP reuses addresses, remove the person from your TrayPage organizations before assigning their address to someone else.

To let a user whose address changed in the IdP keep using their account (administrator task):

  1. Find the user by the userId in the oidc_sign_in_failed log.
  2. In the database, update that user's email (in the user table) to the new address from the IdP, in lowercase. Do not delete the row in the account table: if you do, the next sign-in creates a new, separate user and the original data cannot be reached.
  3. If the domain of the address changed, also update the allowed domains in the organization settings.

IdPs that do not send the verification status:

Some IdPs do not send email_verified. By default, such users cannot create an account. With OIDC_ASSUME_EMAIL_VERIFIED=1, addresses without email_verified are treated as verified. An address counts as verified only when email_verified is the boolean true or the string "true". Use it only if you can guarantee that the IdP confirms each user actually owns the address it returns. With an IdP that does not, a user claiming someone else's address would be linked to that address's existing account. When the IdP sends false or any other value (null, "false", and so on), the address is never treated as verified.

Microsoft Entra ID does not send email_verified, and Microsoft states that the value of the email claim in ID tokens isn't guaranteed to be correct and must not be used for authorization (ID token claims reference). Do not use OIDC_ASSUME_EMAIL_VERIFIED with Entra ID. TrayPage currently has no way to treat an Entra ID user's address as verified, so Entra ID users cannot create an account.

Setup per IdP

Whether TrayPage has been tested against a real IdP depends on the IdP.

IdPOIDC_ISSUER exampleTested
Google (Google Workspace)https://accounts.google.comTested (November 2026, with an OAuth client in Google Cloud)
Keycloakhttps://idp.example.com/realms/<realm>Tested (November 2026, Keycloak 26.4)
Oktahttps://example.okta.com or https://example.okta.com/oauth2/defaultNot tested
Microsoft Entra IDhttps://login.microsoftonline.com/<tenant ID>/v2.0Not tested. As described above, accounts cannot be created for now

The tests covered sign-in (creating a new account, and linking to an existing account with the same email address), signing in again after signing out, LOGIN_METHODS=oidc, the signup restriction, and the rejections listed under "What happens on sign-in" (unverified email address, email address changed in the IdP, email address reassigned to another person). An untested IdP that follows the OIDC standard should work with the same steps, but check its documentation for the names of its settings.

Google

Create an OAuth client for sign-in in Google Cloud.

  1. In the Google Cloud console, select the project to use and open "Google Auth Platform".

  2. Under "Audience", check the user type. With "Internal", only users of your Google Workspace can sign in.

  3. Under "Clients" → "Create client", choose "Web application" as the application type. Add <APP_ORIGIN>/api/auth/oauth2/callback/oidc to "Authorized redirect URIs" (for example, https://tray.example.com/api/auth/oauth2/callback/oidc). "Authorized JavaScript origins" is not needed.

  4. After you create the client, its client ID and client secret are shown. Copy the secret now: it cannot be shown again after you close this dialog.

  5. Set the following values and restart the app (redeploy on Cloudflare).

    OIDC_ISSUER=https://accounts.google.com
    OIDC_CLIENT_ID=<client ID from step 4>
    OIDC_CLIENT_SECRET=<client secret from step 4>
    OIDC_DISPLAY_NAME=Google

    Do not add a trailing / to OIDC_ISSUER (the issuer in Google's discovery document has none). You do not need to set OIDC_CLIENT_AUTH_METHOD.

Google sends the verification status of the email address (email_verified), so OIDC_ASSUME_EMAIL_VERIFIED is not needed. On the first sign-in, Google asks the user to allow TrayPage to receive their email address and profile.

This is separate from Google sign-in (GOOGLE_CLIENT_ID). If you turn on both, the sign-in screen shows two buttons. Signing in with the same Google account through either one leads to the same TrayPage account. The OIDC one checks on every sign-in that the email address has not changed, and does not store Google's tokens. If you need only one, turn the other off with LOGIN_METHODS.

Keycloak

Create a client for TrayPage in the Keycloak admin console.

  1. Select the realm to use. Under "Clients" → "Create client", choose "OpenID Connect" as the "Client type" and pick a "Client ID" (for example, traypage).

  2. Under "Capability config", turn on "Client authentication" and "Standard flow". Other flows (such as "Direct access grants") are not needed.

  3. Under "Login settings", register <APP_ORIGIN>/api/auth/oauth2/callback/oidc in "Valid redirect URIs".

  4. On the "Credentials" tab of the client, check that "Client Authenticator" is "Client Id and Secret", and copy the "Client Secret".

  5. Set the following values and restart the app (redeploy on Cloudflare).

    OIDC_ISSUER=https://idp.example.com/realms/<realm>
    OIDC_CLIENT_ID=traypage
    OIDC_CLIENT_SECRET=<Client Secret from step 4>
    OIDC_DISPLAY_NAME=Keycloak

Notes:

  • OIDC_ISSUER has the form https://<Keycloak host>/realms/<realm>. Open https://<Keycloak host>/realms/<realm>/.well-known/openid-configuration and write it exactly as the issuer value there. If the Keycloak hostname is not configured, the issuer depends on the URL used to reach Keycloak. Make sure people's browsers and the TrayPage server reach Keycloak at the same URL.
  • Users whose "Email verified" is off cannot sign in (the sign-in screen says the email address is not verified at the sign-in provider).
  • Keycloak's "Client Id and Secret" accepts both sending the client secret in the Authorization header (the default) and in the request body (OIDC_CLIENT_AUTH_METHOD=client_secret_post).
  • Right after you replace the realm's signing key, a sign-in may fail once with "Authentication failed". TrayPage waits 30 seconds between fetches of the IdP's keys. Wait about 30 seconds and sign in again.
  • For local testing, a Keycloak on localhost can use http, as in http://localhost:8080/realms/<realm>. A Keycloak on any other host must use https.

Okta and Microsoft Entra ID

These two have not been tested with real tenants.

  • Okta: create an app (OIDC, Web Application) and register the redirect URI under "Sign-in redirect URIs". Write OIDC_ISSUER exactly as the issuer in the discovery document of the authorization server you use.
  • Microsoft Entra ID: as described above, accounts cannot be created for now.

Turn off sign-in methods you do not use:

To let people sign in only through your IdP, set LOGIN_METHODS=oidc. Methods you turn off (email link, Google sign-in) are hidden on the screen and also refused by the server.

  • If none of the methods in LOGIN_METHODS can be used (the IdP secret is missing, the issuer is mistyped, a name in LOGIN_METHODS is mistyped, and so on), TrayPage does not turn on another method instead. Nobody can sign in. The Docker version stops at startup with an error; on Cloudflare the sign-in screen says that no sign-in method is set up, and the log shows login_methods_invalid. Fix the settings or remove LOGIN_METHODS.
  • The Docker version logs the enabled methods as login_methods at startup.
  • Changing LOGIN_METHODS does not end existing sessions, issued API tokens, or AI agent (MCP) connections. To make everyone sign in again, change BETTER_AUTH_SECRET to a new value and restart (everyone is signed out). API tokens and AI agent connections remain even after changing BETTER_AUTH_SECRET. To stop those too, follow Revoke all tokens and connections.
  • There is no password sign-in on the screen (there is no way to set a password).

Sharing with your company domain:

With an IdP configured, the organization setting "Require Google sign-in" means "only people who have signed in with Google or the IdP". People from an allowed domain can see pages shared with the domain if they have signed in with Google or the IdP currently configured. People who have only signed in with an email link cannot. If you remove the IdP or switch to another one, sign-ins with the previous IdP no longer count. To require going through the IdP on every sign-in, use LOGIN_METHODS=oidc.

Revoke all tokens and connections

Users can revoke their own API tokens under MCP / API access in project settings or API tokens in account settings, and their AI agent (MCP) and CLI connections under Connected agents in account settings (MCP § Revoke connections and tokens). Admins cannot revoke other people's tokens or connections from the screens.

To revoke every API token and AI agent connection on the instance at once, for example when a secret may have leaked, run the following SQL on the TrayPage database. Users then issue tokens and connect their agents again. This cannot be undone, so take a backup first.

BEGIN;
-- API tokens (records when they were revoked)
UPDATE api_tokens SET revoked_at = now() WHERE revoked_at IS NULL;
-- AI agent and CLI connections (access tokens, refresh tokens, consents, and the allowed organization and projects)
DELETE FROM oauth_access_token;
DELETE FROM oauth_consent;
DELETE FROM oauth_organization_bindings;
-- Unused authorization codes and in-progress consents (other rows, such as sign-in links, stay)
DELETE FROM verification WHERE value LIKE '%"clientId":%' AND value LIKE '%"userId":%';
COMMIT;

On the Docker version, stop the app, run the SQL, and start the app again.

docker compose stop app
docker compose exec -T postgres psql -U traypage -d traypage <<'SQL'
-- the SQL above
SQL
docker compose start app

Where the app cannot be stopped, such as on Cloudflare (Workers), run the SQL while it is running. A token issued by a request that was in progress has no allowed organization (oauth_organization_bindings), so it cannot be used. To clean up such rows and any remaining authorization codes, run the same SQL again after the authorization codes expire (10 minutes).

To also end signed-in sessions, change BETTER_AUTH_SECRET and restart as well.

If query caching is enabled on Cloudflare Hyperdrive, a revoked token can keep working while the cache lasts (about a minute by default). Turn caching off as the guide describes (Cloudflare).

Other things to check

  • Make BETTER_AUTH_SECRET and VIEWER_TICKET_SECRET long, unguessable, and different from each other. Do not commit them to a repository (use secrets on Cloudflare, and .env on Docker, which should not be under version control).
  • Keep backups of .env and any secrets in a safe place.
  • In production, remove the mail catcher (Mailpit) by removing mailpit from COMPOSE_PROFILES.
  • Update regularly (Docker / VPS, Cloudflare).