Skip to content

Development & Engineering

Query Scoping

Free

Scope every read and write of personal rows by the session user, in the query itself.

Difficulty intermediate
Version v1.1

Purpose

Stop updates that forget the WHERE user clause.

Procedure

--- name: query-scoping description: Scope every read and write of personal rows by the session user, in the query itself. ---

Query Scoping

Purpose

Stop updates that forget the WHERE user clause.

Procedure

Personal tables include a user id column. Every statement that reads or mutates them includes that column in the WHERE (or the INSERT values), using the session id.

Do not fetch a row by id and then check the owner in application code if a single statement can do both. A check after the fact races and is easy to skip on the next path.

Updates and deletes name the owner even if you "just looked it up". Example shape: delete where skill_id = $skill and user_id = $session.

Public tables (published skills) do not take a user id filter. Do not "scope" them by a client-supplied tenant.

Never build SQL by concatenating user strings. Bind parameters.

Select only the columns the client needs. For premium or private content, do not select the column at all when the caller is not allowed to see it. Hiding it in the UI is not enough.

After writing the query, state the unauthorized case in one sentence: what a signed-out or other user receives.

Example requests

1. Scope a delete

Request: Apply Query Scoping to unsaving a skill. Expected: The delete filters by both the skill and the session user.

Dependencies

None. Work in the repository that is already open. Do not add packages unless the procedure names one.

Compatibility

This document follows the Agent Skills layout (a folder named query-scoping containing SKILL.md). Claude Code, Cursor, Codex, and Gemini CLI can load that file from the paths in the Skilling installation guide. GitHub Copilot does not load SKILL.md. Use the Copilot instructions copy, and narrow applyTo before you commit it.

Example prompts

Scope a delete

Apply Query Scoping to unsaving a skill.

Expected: The delete filters by both the skill and the session user.

Choose the agent

This skill is installed for one agent at a time. Pick the section you are using.

Related

  • Session Review

    Check that a feature uses the server session and never a user id sent from the browser.

  • Relational Schema

    Add tables with keys, constraints, and indexes that match the queries you will actually run.

  • Schema Contracts

    Validate input at the server boundary and return a stable error shape.

Reviews

No reviews yet.

    Sign in to review.

    Report a problem

    Inaccurate steps, an unsafe instruction, or a licensing concern.

    Sign in to report.