Identity and data protection guidance
This guidance defines how an application protects identity, credentials, and sensitive data from the first request to the final data store. It treats each boundary as a security check: authenticate the caller, authorize the requested action, validate the data, and keep secrets out of places where users can see them.
Security boundaries
Boundary model
The application must not rely on one check or one layer to protect data. A request passes through several boundaries, and each boundary confirms only the part of the request that it owns.
The main relationship is:
flowchart LR
R[Incoming request] --> I[Identity check]
I --> A[Action and ownership check]
A --> V[Input and field check]
V --> D[Data access policy]
D --> O[Limited response]
S[Secrets] --> I
S --> D
An earlier check can improve speed or user experience, but it cannot replace a later check at the action or data boundary. This model applies to browser requests, API routes, server actions, background work, and direct data access.
References: vibe-security/…/authentication.md• L20-29 vibe-security/…/authentication.md• L63-65 vibe-security/…/data-access.md• L45-55 vibe-security/…/database-security.md• L147-151
Identity controls
Authentication and authorization
Authentication proves who the caller is. Authorization decides whether that identity may use the requested action or access the requested record. Both checks are required for every public entry point.
Use the authentication security guidance for the detailed rules. The key controls are:
- Verify token signatures and validate issuer, audience, and expiry.
- Reject unsigned or otherwise unexpected token algorithms.
- Repeat the check in the action, route, and data layer. Middleware alone is not a security boundary.
- Check resource ownership or role, not only that a user is signed in.
- Store session tokens in protected cookies rather than browser storage.
References: vibe-security/…/authentication.md• L3-18 vibe-security/…/authentication.md• L20-29 vibe-security/…/authentication.md• L31-65 vibe-security/…/authentication.md• L86-90
Identity data exposure
Identity data must be reduced before it crosses from trusted server code to client code. Return only the fields needed for the current view or action, and keep passwords, internal identifiers, role flags, and other private fields on the server.
This rule links identity protection to data protection. A valid user session does not make every field safe to disclose. Server-only data access boundaries help prevent private records from reaching client code by mistake.
References: vibe-security/…/authentication.md• L67-84
Data access controls
Request validation
External data is untrusted until the application checks its shape, type, size, and allowed values at the system boundary. This includes request bodies, route values, query strings, forms, and webhooks.
Use the data access security guidance to define the accepted input before it reaches business logic or a data store. Static type declarations do not provide this protection at run time.
References: vibe-security/…/data-access.md• L45-66
Query and field control
Data access must keep user input separate from query structure and must select the fields that a user may change. Parameterized queries or safe ORM calls prevent input from becoming query code, while explicit field selection prevents hidden fields from being changed through mass assignment.
These controls work with authorization. A safe query can still return another user's record, and a validated request can still change a protected field if ownership and allowed fields are not checked.
References: vibe-security/…/data-access.md• L3-43 vibe-security/…/data-access.md• L68-79
Database controls
Record ownership
The database must enforce which identities can read or change each record. Application checks remain useful, but database policies provide a second boundary for direct API access, missed call paths, and future code changes.
Use the database security guidance for store-specific rules. Policies must cover every exposed table and must constrain reads, updates, deletes, and inserts to the correct owner or role. An authenticated identity by itself is not enough.
References: vibe-security/…/database-security.md• L5-18 vibe-security/…/database-security.md• L21-53 vibe-security/…/database-security.md• L66-75 vibe-security/…/database-security.md• L147-151
Sensitive fields and files
User-editable data must not include fields that control privilege, credit, billing, or other trusted state unless the data store protects those fields separately. Related tables and file storage need their own access rules because protection on a main record does not automatically protect linked data.
The same principle applies to uploaded files. Access rules must bind a file to its owner and limit what the system accepts, such as file type and size.
References: vibe-security/…/database-security.md• L55-68 vibe-security/…/database-security.md• L77-88 vibe-security/…/database-security.md• L109-145
Secret controls
Secret storage and use
Secrets include passwords, private keys, signing keys, database connection strings, and third-party secret keys. They must stay in server-controlled secret storage and must never be hardcoded or sent to a client bundle.
Use the secrets and environment security guidance to separate public configuration from private credentials. Client-visible environment variables are public by design. A public key may be safe to expose, but a service key or signing secret is not.
References: vibe-security/…/secrets-and-env.md• L3-10 vibe-security/…/secrets-and-env.md• L12-35
Secret lifecycle
Secret protection continues after source review. Environment files and sample files must avoid real credentials, and a secret that enters version history must be treated as exposed even after the file is removed. Rotate it before treating the source change as complete.
References: vibe-security/…/secrets-and-env.md• L10 vibe-security/…/secrets-and-env.md• L37-47
Change checklist
When these files or sections are changed, remember to consider these:
- When a new route, server action, webhook, or background entry point is added, apply identity and ownership checks at that entry point and at its data access boundary.
- When a record or storage path changes, update the matching ownership policy and any related table or file policy.
- When a user-facing identity object changes, review the server-to-client field set for newly exposed private or trusted fields.
- When an environment variable changes, verify that its client visibility matches the value's risk and rotate any credential that entered source history.
- When a database function or privileged service path changes, review whether it bypasses normal row or field rules.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Middleware is the only identity check | A request can reach protected work without a reliable authorization decision | Verify identity and ownership again in each public action, route, and data access path |
| A policy checks only that the caller is logged in | One user can read or change another user's records | Bind each operation to record ownership or an approved role |
| An update accepts the full request object | A user can set admin, credit, billing, or ownership fields | Validate input and allow only named editable fields |
| A related table or storage bucket lacks its own policy | Linked records or files become visible across users | Give every exposed table, subcollection, and storage path an explicit rule |
| A secret uses a client-visible prefix or enters Git history | Anyone who receives the bundle or repository can use the credential | Keep private values server-side and rotate exposed credentials |
Key files
| File | Why to read it |
|---|---|
| vibe-security/…/authentication.md | Defines token checks, public request boundaries, session storage, and client data limits. |
| vibe-security/…/data-access.md | Defines input validation, query safety, and allowed-field control. |
| vibe-security/…/database-security.md | Defines ownership rules for records, fields, functions, and files across common data stores. |
| vibe-security/…/secrets-and-env.md | Defines secret storage, client visibility, source control risks, and detection checks. |