Skip to content

FEAT-011 — Cross-query privacy: row budgets, paging detection and differencing checks #220

Done

Description

@jmmana

Parent epic: #214
Priority: P2

Problem

Each query is judged on its own. rules/aggregate_only.py already notes that k-anonymity does not stop differencing attacks, and docs/THREAT_MODEL.md lists "inference through allowed data" as out of scope.

  • SELECT SUM(salary) FROM employees, then the same query with WHERE id <> 42: the difference is one person's salary.
  • An agent can copy a whole allowed table 100 rows at a time.

Proposal

These checks need state and database access, so they run in the MCP server and proxy modes, not in a bare Guard.check(). They reuse the per-session state that tainted sessions already keep.

session_limits:
  row_budget:
    customers: 2000          # rows returned per session
  window: 1h
  detect_paging: true        # OFFSET or key-range enumeration of one table
aggregate_only:
  employees: {min_group: 10, min_difference: 10}
  • Row budgets per table, per session and window.
  • Paging detection: a sequence of queries that walks one table by OFFSET or key ranges.
  • Differencing check for aggregate_only: before answering, count the rows in the symmetric difference between the new query's row set and each earlier one on the same table in this session. If it is below min_difference, refuse.

Security impact

New stable violation codes (row_budget_exceeded, paging_detected, differencing). The threat model says plainly what is still not covered: combinations of many queries, and sessions split across identities.

Acceptance criteria

  • Row budgets and detection of supported offset, single-column and composite keyset pagination, with engine tests on PostgreSQL and SQLite.
  • The salary example above is refused, and a legitimate pair of aggregates over large groups is allowed (tests).
  • Corpus cases for each new code; docs/THREAT_MODEL.md updated (EN / ES).
  • A short write-up with the attack, the defense and its limits.

Files

  • src/sqlguardllm/session_limits.py (new) · rules/aggregate_only.py · mcp_server.py · proxy.py · docs/THREAT_MODEL.md

Size

L

PR #256 merged after ten successful workflows. It adds opt-in MCP row budgets with an SQLite integration test and tests for atomic accounting, session isolation and window reset. PostgreSQL, policy-file configuration, proxy support, paging and aggregate comparison remain open.

PR #258 merged after ten successful workflows. It adds the operator JSON configuration and a PostgreSQL integration test for row-budget isolation. Policy schema integration, proxy support, paging and aggregate comparison remain open.

PR #262 merged after ten successful workflows. It applies the configured budget to mapped proxy tools with countable structured rows, and refuses to deliver uncountable or over-budget protected results.

PR #265 merged after ten successful workflows, including Engines. It adds an opt-in restriction for nonzero and computed offsets in MCP and the proxy. Keyset paging and aggregate differencing remain open.

PR #277 merged after all ten PR workflows passed. The optional keyset_columns mapping restricts limited single-table reads with a literal range predicate on the configured leading sort column, before MCP execution or proxy forwarding. SQLite and PostgreSQL tests verified the refusal. Other pagination patterns, sequence tracking and aggregate differencing remain open.

PR #280 merged after all ten PR workflows passed. fixed_aggregate_sources optionally restricts configured, budgeted sources to supported aggregates over the full policy-selected cohort. SQLite and PostgreSQL tests verify acceptance of a whole-cohort aggregate and refusal of a caller-selected subset. Comparing the rows matched by successive aggregates and tracking pagination sequences remain open.

PR #286 merged after ten successful PR workflows. keyset_page_limit optionally caps detected requests per trusted session, source and window before execution or proxy forwarding. It counts retries without recording cursor values. SQLite and PostgreSQL verify allowed and refused requests. Comparing successive aggregate cohorts and detecting other pagination shapes remain open.

PR #289 merged after ten successful PR workflows, including Engines. A composite keyset cursor now uses the same trusted-session allowance when its columns match the leading sort columns and its bounds are literals. Verified SQLite, PostgreSQL and refusal before upstream forwarding in the proxy. The bilingual threat model describes which cursor shapes the rule covers. Comparison of successive aggregate cohorts is still open.

PR #305 merged after ten successful PR workflows. Keyset accounting now resolves sort aliases and positions that refer to directly projected columns. Verified SQLite and PostgreSQL. Comparing successive aggregate cohorts remains open.

PR #331 verifies filtered aggregate comparison in SQLite and PostgreSQL. PR #332 applies the comparison in stdio proxy mode using the configured read-only database. PR #333 adds the six stateful corpus scenarios and bilingual threat-model coverage. All eight PR workflows passed before merge for #333, and 377 targeted tests passed locally.

Activity

  1. added
    type:feature
    area:security
    area:rls
    size:l
    lang:python
    p2
    on Dec 1, 2026
  2. jmmana commented on Dec 3, 2026

    @jmmana
    OwnerAuthor

    Delivered in #326 for the MCP server (cohorts key, same-snapshot membership, differencing/cohort_unavailable). The proxy refuses cohort config at startup instead of silently skipping it; limits are documented in DESIGN and THREAT_MODEL.

  3. reopened this on Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:rlsarea:securitylang:pythonp2size:ltype:feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions