# API keys, origins and security
Source: https://sovaria.in/docs/settings-api-and-security

Your endpoints, the anon and service role keys and when to rotate them, which websites may call the API from a browser, per-IP rate limiting and the request limits of your plan.

Two pages under **API & auth** decide who can reach your project at all: **API & origins** (endpoints, keys, secrets, allowed browser origins) and **Security** (traffic protection and plan limits). Who can do *what* once they’re in is decided by your [rules](https://sovaria.in/docs/security-and-policies).

(Diagram: Which key goes where)

## API keys

| Key | Where it goes | What it can do |
|---|---|---|
| Anon (public) | Your app, website, the config file, Git. | Whatever your rules allow visitors and signed-in users. |
| Service role | Servers and functions only, kept in secrets. | Everything, bypassing row rules. Never ship it in an app or a browser. |
| Custom keys | A partner integration or a single job. | What its role allows within your rules: **viewer** only reads, **editor** and **admin** read and write. Row-level security treats it as `anon`. |

**Rotate** issues a new key at once and the old one stops working, so ship the new key first when you can. Every reveal and rotation is in the audit log. Details in [API keys](https://sovaria.in/docs/api-keys).

CLI:
```bash
sov keys list
sov keys create --name "nightly-export" --role viewer --expires 90d
sov keys revoke <key-id>
```

## Allowed origins (CORS)

Browsers may call the API only from the origins listed, for example `https://app.example.com`. `https://*.example.com` allows every subdomain. A wildcard over shared hosting (`*.vercel.app`, `*.github.io`, `*.netlify.app`, `*.sovaria.app`, `*.co.uk` …) is refused: anyone can publish a site there, so list your own site's exact origin instead. Changes reach the gateway within 30 seconds. Mobile apps, servers and the CLI aren’t affected by CORS. More in [Allowed origins (CORS) for browser apps](https://sovaria.in/docs/allowed-origins).

## Security

**Per-IP rate limiting** caps how many requests one IP address can send each minute. Turn it off only when all traffic reaches you through your own backend — then every request comes from a few IPs and would be throttled. The plan limits below always apply; past them requests get `429` with a `Retry-After` header.

**Per-resource limits** (paid plans): on top of the project-wide limit, set a separate limit for one table, document collection or function under **Authentication › Rate limiting**. Each rule is a resource (`table:orders`, `collection:posts`, `fn:sendEmail`), a requests-per-minute number, and a scope — whole project, per signed-in user, or per IP. Over the limit, that resource answers `429 RESOURCE_RATE_LIMIT_EXCEEDED` with `Retry-After`; other resources are unaffected. How many rules you can add depends on your plan (`net.resource_rate_limit_rules`).

|  | Free | Pro | Ultra | Team | Enterprise |
|---|---|---|---|---|---|
| Data API requests per minute (per project) | 600 | 6,000 | 15,000 | 60,000 | 250,000 |
| Data API burst requests per 10 seconds (per project) | 150 | 1,500 | 4,000 | 15,000 | 60,000 |
| App requests per client IP per minute (default when you set none) | 600 | 3,000 | 10,000 | 20,000 | 100,000 |
| Your own rate limits per table, collection and function | — | ✓ | ✓ | ✓ | ✓ |
| How many per-resource rate-limit rules you can set | — | 10 | 50 | 200 | 1,000 |

## Built-in protections

- **Injection firewall** — SQL, NoSQL and script injection patterns are blocked at the gateway on every request.
- **Login lockout** — accounts are locked for a while after repeated failed sign-in or MFA attempts.
- **Signed webhooks** — webhooks with a secret are signed with HMAC-SHA256 so receivers can verify them.
- **Encrypted secrets** — project secrets, SMTP passwords and keys are encrypted at rest and never returned in full.

These are always on. Sign-in protections you choose (CAPTCHA, MFA, leaked passwords) are in [Authentication settings reference](https://sovaria.in/docs/auth-settings); proving requests come from your real app is [App attestation](https://sovaria.in/docs/mobile-attestation).
