# Beplan API security: tokens and disclosure

How to keep tokens and app secrets safe, what to do when one leaks, and how to report a vulnerability.

## Tokens

- A token acts as its person. Keep it on a server, in a secret store or an environment variable. Never in a repository, a web page's code, a mobile app, a log or an address (Beplan refuses tokens in the query string anyway).
- Give each script or tool its own personal token, with only the scopes and organizations it needs, and an expiry. [`all`](https://beplan.io/docs/oauth/scopes/#scope-all) (**Everything my role allows**) is convenient and also the most damaging if it leaks.
- Prefer read scopes where you only read: reads and writes are separate scopes.
- Revoking is immediate. In your Beplan settings, revoke a token under **Developers** or an app or assistant under **Integrations**, or remove everything at once from **Developers**. Signing out or changing your password does not revoke tokens.

## Apps

- **Client secret**: on a server only, never in a browser or a mobile app. A native or browser app is a public client: no secret, PKCE only. If the secret may have leaked, make a new one on the app's page: the old one stops at once, and tokens already issued keep working.
- **PKCE** with `S256` on every authorization, a fresh `code_verifier` each time, and a random `state` checked on return. Check `iss` in the authorization response too.
- **Redirect addresses** are matched exactly: register the precise callbacks you use, over `https`. Loopback and custom-scheme addresses are for native apps only.
- **Refresh tokens** are the connection: store them encrypted, per person, and replace them at every refresh. One reused after the 30-second grace period ends the connection, which is what protects your users if one is stolen.
- **Ask for little.** Each scope is shown to the person on the consent screen; sensitive ones are flagged and can be switched off by an organization. Marking a scope required means people can't connect without it.
- **Webhook secret**: verify every delivery's signature, against the raw body, in constant time, and reject old timestamps ([webhooks](https://beplan.io/docs/guides/webhooks/#verify-every-delivery)). Rotate it from the app's page if it leaks.
- **Third-party text is data.** Comments, messages and emails your app reads were written by people outside the organization. Never let them drive what your app or an assistant does.

## If a token or secret leaks

1. Revoke it now: the token under **Developers** in the person's account, a client secret or webhook secret by making a new one on the app's page.
2. Look at what it did: an organization's admins see every integration's activity in the organization's Integrations settings.
3. Tell help@beplan.io if Beplan data may have been reached, with the request ids you have.

## Reporting a vulnerability

Write to help@beplan.io (also in [security.txt](https://beplan.io/.well-known/security.txt)). Include what you found, how to reproduce it, and the request ids involved.

---
HTML version: https://beplan.io/docs/security/
