Introducing a new way to review your PRs.

Read the announcement

raroque / vibe-security-skill

Agent skill that audits vibe-coded apps for common security vulnerabilities introduced by AI coding assistants

View on GitHub

15 documents · Updated Oct 30, 2026

docs / data-access-security

Data access security

Data access security ensures that each user, service, and public interface can read or change only the data allowed by its role and the resource's ownership. It joins identity checks with resource checks, safe input handling, and data-store rules so that a missed check in one layer does not expose protected information.

Access control model

Authorization decides what an already identified actor may do. A sound review follows the request from its public entry point to the resource check and then to the data store.

The related authentication security page covers how the system establishes identity. This page focuses on the next question: whether that identity has the required permission for the specific action and resource.

This diagram shows the main access decision from request to protected data.

flowchart LR
    R[Request] --> I[Verify identity]
    I --> P[Check role or service permission]
    P --> O[Check resource ownership or scope]
    O --> V[Validate input and fields]
    V --> D[Apply data-store policy]
    D --> A[Return only permitted data]

Identity and permission checks

Every public handler must check both who is calling and what that caller may do. A login check alone is not enough because any authenticated user may still be barred from another user's record or from an administrative action; checks must also exist in server actions, route handlers, and data-access functions rather than only in edge middleware.

References: vibe-security/…/authentication.md• L20-29 vibe-security/…/authentication.md• L31-65

Resource ownership and scope

Authorization must bind the requested resource to the caller's allowed scope. For user data, that normally means matching the resource owner; for services, it means limiting access to the records and actions required by the service role. A check for a valid session without this resource test can expose or change another user's data.

References: vibe-security/…/authentication.md• L42-61 vibe-security/…/database-security.md• L21-53 vibe-security/…/database-security.md• L147-151

Request and query boundaries

Data access is safest when untrusted input becomes a small, known request before it reaches a query or update. The boundary must control both the meaning of the query and the fields that the caller can change.

Input validation and field selection

Runtime validation is required at API handlers, server actions, webhooks, form submissions, and URL boundaries because compile-time types do not inspect hostile requests. After validation, select allowed fields instead of passing a whole request object into a data update; this prevents hidden fields such as administrative flags or account credits from becoming caller-controlled.

References: vibe-security/…/data-access.md• L45-79

Query construction

Queries must treat user input as values rather than executable query text. Parameterized queries and safe ORM methods preserve that boundary, while raw unsafe query methods and unvalidated filter objects can turn input into SQL or ORM operators that return data outside the intended scope.

References: vibe-security/…/data-access.md• L3-43

Response data scope

The same least-privilege rule applies to data returned to a client. Select only the fields needed by the client and keep server-only data access code out of client components so that private fields do not cross the server boundary by accident.

References: vibe-security/…/authentication.md• L67-84

Data-store access policies

Application checks must be backed by rules at the data store when the store is directly reachable by clients or by more than one service. These rules provide a second boundary and must cover every exposed table, document path, object path, and callable function.

Row and document policies

Row-level security and document rules must express ownership or an approved role, not only the fact that a caller is logged in. Write rules also need to preserve ownership and restrict mutable fields; otherwise a caller can move a record into another user's scope or promote itself through a field update.

References: vibe-security/…/database-security.md• L5-68 vibe-security/…/database-security.md• L91-140

Access policy review must include related tables, junction data, audit records, subcollections, and file storage. A protected parent record does not automatically protect each related path, so every exposed resource needs a matching scope rule for reads, writes, and deletes.

References: vibe-security/…/database-security.md• L66-88 vibe-security/…/database-security.md• L121-144

Privileged service operations

Privileged functions and internal service operations can bypass normal user rules, so their public exposure and input checks require special review. Keep privileged operations internal where possible, limit their schema and inputs, and make their caller scope explicit before they access protected data.

References: vibe-security/…/database-security.md• L70-75 vibe-security/…/database-security.md• L147-151

Review focus

A data-access review traces each sensitive operation across the identity layer, application boundary, query, and data-store policy. The reviewer should confirm that the same access scope survives every step and that the response contains no fields or records outside that scope.

Use the identity and data protection page for the broader relationship between identity, credentials, and sensitive data. Use database security for database-specific exposure, query, and permission guidance.

Change checklist

When these files or sections are changed, remember to consider these:

  • Recheck every public route or server action when its resource lookup changes. A new lookup path must carry the caller's ownership or role scope.
  • Recheck data-store policies for related tables, subcollections, storage paths, and new service functions. Protection on a parent resource does not cover each related resource.
  • Recheck writable field lists when a schema gains an administrative, billing, ownership, or other sensitive field.
  • Recheck response shapes when database records gain private fields or when data crosses into a client component.
  • Recheck service roles and privileged functions when a data operation moves from a user path to an internal path or becomes publicly callable.

Important failure modes

TriggerConsequenceGuard
The handler checks only that the caller is logged in.One user can read or change another user's resource.Check ownership or the permitted resource scope in the data operation.
A request body or filter object reaches an update or query without runtime validation.Attackers can set protected fields or widen a query to return unintended records.Validate at the boundary and map only allowed fields and filters.
A related table, subcollection, or storage path has no matching policy.Data that appears protected through the main record is exposed through a secondary path.Review and scope every exposed resource independently.
A write policy checks the old owner but not the new record state.A caller can reassign ownership or write data into another user's scope.Enforce the post-write owner with a write condition such as WITH CHECK.
A privileged function is public or accepts unchecked input.An unauthenticated caller can bypass normal data-store rules or use the function outside its intended scope.Keep privileged functions internal and validate inputs and caller scope inside them.

Key files

FileWhy to read it
vibe-security/…/authentication.mdDefines the identity, authorization, public-handler, and client-boundary checks that start a data-access review.
vibe-security/…/data-access.mdDefines the input, query, ORM, and field-selection boundaries that protect data operations.
vibe-security/…/database-security.mdDefines store-level ownership rules for rows, documents, related resources, storage, and privileged functions.