Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .agents/skills/writing-secure-code/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
name: writing-secure-code
description: "Guides security in code and docs that handle the project key, an end user's token or data, or that shape what reaches an error or a log - the transport, redirects, requests built from caller input, error text, log emissions, WithHTTPClient, WithLogger, AccessTokenProvider, GetClaims, sessions and SessionStore, shared caches and locks, plus examples, walkthroughs and test fixtures that show a key, token or password. Use alongside the skill that owns the change whenever it touches any of those, when adding a suppression such as #nosec, when fixing or reviewing a reported vulnerability or scanner finding and when answering a security review."
---

The following documents will be helpful:

| Document | For |
| -------- | --- |
| [`.github/README.md`](../../../.github/README.md#security) | The Security section: what the SDK promises its users. Check each promise a change touches against the code. |
| [`DEVELOPMENT.md`](../../../DEVELOPMENT.md#secure-design-and-coding) | The Secure Design and Coding section: where credentials travel, what a log emission and an error may hold, how caller input is treated, failing closed, credentials in examples and tests, suppressions and how a vulnerability is fixed and reported. Also the Concurrency rule on locks across I/O and the Commentary exception for security controls. |
| [`decisions.md`](../../../decisions.md) | The records "The project key travels only on the `apikey` header, never on `Authorization`", "The client presumes neither a deployment runtime context nor an API/Supabase key type", "The logging seam takes *slog.Logger, and only a failure no caller receives is logged above debug" and "Placeholder credentials in rendered examples name the real key type". |

Before changing code whose comment says what exposure it guards against, read that comment and keep the guard, or replace it with one that closes the same exposure.

Accepting a risk rather than closing it is a decision, so it should also trigger the `recording-decisions` skill.

Pinning and scanning what the repository executes is the `changing-build-and-continuous-integration` skill's territory.

Ephemeral local development artifacts, including scanner exports and write-ups of a vulnerability not yet fixed, stay out of the repository, or in the git-ignored `user.transient/` folder.

## Supabase Security Skills

Supabase's security team maintains shared, internal skills for security review and for threat modeling (at the time of writing this, they are not open source or otherwise public).

If they are available to you then use them: the review skills when writing or reviewing a change in the areas above, and threat modeling when a change adds a trust boundary, such as a new service, credential or persisted state.
18 changes: 18 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,22 @@ sudo apt-get install --no-install-recommends gcc libc6-dev

This avoids the heavier weight `build-essential` meta-package, as well as optional dependencies like man pages and extra tooling (what `--no-install-recommends` strips away).

## Secure Design and Coding

This SDK is built for backend applications that will often hold the Supabase project's secret key, a heavy responsibility. The README's [Security](.github/README.md#security) section lists what the SDK promises its users.

- **Credentials stay with the project.** The project key travels on the `apikey` header only, and only to the origin of the project URL. A redirect to any other origin is never followed, because the key would be sent there too. An end user's access token travels on `Authorization` only and is never derived from the project key.
- **Secrets stay out of the SDK's log emissions.** No emission, at any level, holds a credential, a token, a body, a query string or a header value. Text from a server can hold one, and so can an error's text, so log neither. Log a value that cannot hold one, such as a status code, a duration or one word from a fixed set. The exception is what the application's own code raised, such as a session listener's panic, which nothing else reports.
- **The SDK puts no secret into an error.** Its own text never holds the project key, a token or a header value, and it names a failed request's URL by scheme, host and path alone. A server's message and a wrapped cause keep their own text, which goes to the caller. Where a cause would quote a secret, prevent the cause, as the SDK does for a redirect whose `Location` header does not parse.
- **Never decide by an error's wording.** The text of an error, or of a server's message, can change in any release. Classify a failure by its type, by its status or error code or by the request's context.
- **Caller input is data.** Text from the caller, such as a table name or a filter value, never changes the structure of a request or how the SDK treats it. A table named `rpc` is still a table. A method that sends the caller's own syntax says so in its doc comment, as `RawLiteralCondition` does.
- **Fail closed.** A failure never widens what a call may do. An `AccessTokenProvider` that fails stops its call rather than letting it reach the service under the project key's own role.
- **A credential written here is public.** Examples, docs and tests hold only placeholders, fixtures and values for the local stack. None tells a reader to use one on a real project.
- **Examples and docs never overstate what a privileged action does.** Banning a user, for instance, leaves the access tokens already issued valid until they expire, and the example says so.
- **A suppression is a red flag.** Before suppressing a finding of gosec or another analyzer, find out why the tool fires and look for a design that needs no suppression. One that remains states what the tool assumes and why that is false at that site.
- **A security fix proves the defect first.** Its first commit adds a test that passes with the defect in place. The second fixes the defect and changes only what that test expects.
- **Report a vulnerability privately.** Use the organization's [security policy](https://github.com/supabase/.github/blob/main/SECURITY.md), never a public issue.

## Supply-chain pinning

Everything we execute from outside the repository is pinned to an immutable digest, and that applies to **both** GitHub Actions and our Go tooling - first-party included, with no exemption.
Expand Down Expand Up @@ -285,6 +301,7 @@ Concretely:
- The reasoning behind a design often belongs in [`decisions.md`](decisions.md), but check the advice at the top of that file for when to use it and when not to use
- Working procedures belong here in [`DEVELOPMENT.md`](DEVELOPMENT.md)
- A comment that argues for its own design has leaked
- A security control is the exception: its comment may say what exposure it closes and why a simpler design would not, so a maintainer does not remove it as clutter
- **Self-contained at the boundary.** Never document an identifier by pointing at its neighbors: no "mirrors the reference implementation", no "same pattern as package X", no "the Y job relies on this", nor any other note about what upstream or downstream code happens to do. When a collaborator's behavior constrains this interface, state the resulting obligation as this interface's own ("the path is not escaped here, so it must be escaped on query assembly") without touring the collaborator.
- **No provenance notes on received values.** A type whose values a caller receives rather than constructs states what a value is and guarantees, never which function returns it: no "instances come only from [X]". The producer's own signature and doc carry that fact, and unexported fields already enforce exclusive construction at compile time. Pointing a type the caller must build at its constructor states an obligation, not provenance ("the zero value is not usable, so build it with [New]"), and an error naming the operations that report it states the condition under which it arises ("reported by [X] when ...").
- **No language tutoring.** State what is returned or accepted, as types and sentinels. Do not teach `errors.Is` / `errors.As` mechanics, struct tag semantics or any other standard craft - the reader, human or AI, knows their tools.
Expand Down Expand Up @@ -338,6 +355,7 @@ Anything a reader can discover from the entry points themselves - signatures, fi

## Concurrency

- **Hold no lock that guards state across I/O.** Network requests and session-store writes run with it released. A call that waits for another call's result stops waiting when its own context ends.
- **Release every lock by `defer`.** Follow each `Lock` immediately with `defer Unlock`, giving a critical section that must end mid-function a function of its own, so a panic recovered further up the stack never leaves a lock held.

## Testing conventions
Expand Down
6 changes: 4 additions & 2 deletions decisions.md
Original file line number Diff line number Diff line change
Expand Up @@ -680,14 +680,16 @@ Issued tokens travel the same path a production consumer's do.
The sibling SDKs built opt-in trace machinery because their runtimes hold ambient global trace context and their HTTP layers lack a per-request context, so they must extract, filter by host and inject themselves; Go's context is explicit and the injected transport serves only this SDK's requests to the project URL, so the caller's transport choice already scopes propagation.
Vendor neutrality is a fixed constraint: no OpenTelemetry type may enter the public surface, and a forced OTel version would create diamond-dependency conflicts for teams already running it.

## The logging seam takes *slog.Logger and emits at debug only
## The logging seam takes *slog.Logger, and only a failure no caller receives is logged above debug

**What**:
`configuration.WithLogger` accepts a `*slog.Logger` rather than a `slog.Handler`, and no emission rises above `slog.LevelDebug`.
`configuration.WithLogger` accepts a `*slog.Logger` rather than a `slog.Handler`.
An emission rises above `slog.LevelDebug` only for a failure that reaches no caller, as a session listener's panic does.

**Why**:
The logger is the unit applications already hold, and a caller with only a handler recovers the other shape with one `slog.New` call.
Failures already reach callers as returned errors, so a louder emission would report the same failure twice.
A failure that reaches no caller has no other report.

## Placeholder credentials in rendered examples name the real key type

Expand Down
Loading