← Back to Pull requests

fix(engine): refuse MIN and MAX in the disclosure gate (P57) #282

Closed
unknown closed this pull request without merging on Nov 22, 2026 18:43 UTC
View on GitHub
unknown unknown commented on Nov 21, 2026 12:59 UTC
Author

What and why

Closes #279 (P57; the "Dominance rule" step in docs/PROJECT_SCOPE.md). Proposes ADR 0015 (number reserved on #279) and implements its MIN/MAX decision. The SUM/AVG part is #281 (P58). ADR 0015 is Proposed: @AxolDad's acceptance is needed before this merges.

MIN and MAX over a cohort of k or more still returned one row's value. On the bypass fixture, SELECT COUNT() AS n, MAX(salary) AS hi FROM people returned 9001, the one ceo's salary. WHERE salary < 9001 gave the next salary, an id range said whose each one was, and MAX(id) returned p15 verbatim.

ADR 0015 answers each question in #279:

  • MIN/MAX: removed from PERMITTED_AGGREGATES and refused wherever they appear (select list, HAVING, ORDER BY), in research and ZK mode. The tie rule and top/bottom-coding are recorded as alternatives.

  • SUM/AVG: the p% rule on absolute contributions, with p = 10 by default (configurable in P58). AVG takes SUM's decision, since SUM = AVG × n.

  • Unit of contribution: one row. Negative values count by absolute value, non-finite values make the cell sensitive, and SUM/AVG(DISTINCT) are refused (P58).

  • Suppression: the dominated cell becomes null and the row is still released. suppressed_rows keeps counting only rows the cohort threshold withholds. Derived columns read the masked value, and count_arithmetic stays refused under ADR 0011.

  • Own-data ZK queries: same gate, same p*.

  • Mechanism: hidden auxiliary aggregates are added to the one Aggregate, and a projection directly above it does the masking, so HAVING, ORDER BY … LIMIT and derived columns never read a dominated total. This differs from #281's sketch, which carries the auxiliary values to egress. #281 should follow the ADR once it is accepted.
  • How it was tested

    policy.rs: PERMITTED_AGGREGATES is now count, sum and avg.

    New bypass cases, all Rejected:

  • Research: min_max, max_total, max_text, min_text_per_group, max_distinct, max_renamed_below, max_in_subquery, max_in_cte; the walk ADR 0002 left open (max_walk, min_walk); id ranges (max_id_range, max_id_from); max_in_having, min_in_order_by.

  • ZK: max_salary, max_id, min_walk, max_in_having.
  • Existing bypass cases, changed deliberately:

  • Cases that released rows with MIN/MAX now use SUM or AVG, with the same expected outcome and purpose:

  • - sum_avg_min_max → sum_avg (Rows(2)): the baseline for the aggregates that stay. MIN/MAX moved to min_max.
    - group_by_id, both suites (Rows(0)): grouping by a unique key still releases nothing.
    - having_value (Rows(0)): a HAVING that selects the small cohorts. HAVING MAX has its own refused case.
    - min_rare_first / max_rare_first → rare_first_by_value / rare_first_by_count (Rows(0)): ORDER BY … LIMIT cannot bring a suppressed cohort forward.
    - ZK rare_cohort_suppressed (Rows(0)).
  • One expected outcome changed: ZK group_by_id_per_column goes from Rows(0) to Rejected. It released MAX(dept) per id, and nothing permitted returns text.

  • Some cases were already refused but would now stop at the aggregate allowlist, which runs first, and no longer reach the check they were written for. They now use SUM or AVG:

  • - filter_on_value (FILTER on a value aggregate) and computed_below (a computed column below the aggregate).
    - Positional subsets (ADR 0002): limit_below_min → limit_below_sum, limit_below_cte, offset_below_max → offset_below_sum, plain_limit_below; ZK limit_below_max → limit_below_sum, offset_below_min → offset_below_avg.
    - Error probes (ADR 0011): having_div, outer_div, outer_cast, order_by_div, outer_negate_min_literal. AVG(salary) exceeds 9000 for the ceo group only and 9500 for none, as MAX did.
  • Left as they are, because they are still refused and either an earlier check refuses them or another case covers their check: case_in_max, computed_label_below, max_n, window_over_aggregate (both suites), having_subquery, cross_join, aggregate_over_aggregate (both suites), inner_group_by_id, qualified_n, two_n_columns, and ZK grouping_sets, missing_n_by_id, spoofed_n, max_of_id, computed_below, scalar_subquery_filter.
  • Mutation check: with min and max put back in the allowlist, exactly the new cases and group_by_id_per_column fail (max_total returns 9001, max_text returns p15, max_walk returns 7002), and every rewritten case still passes.

    API: query_api.rs uses SUM instead of MAX in its unique-key and missing-n checks and adds MAX to the refused queries (422). research_api.rs sends MAX through the research endpoint (422).

    No new audit event: a MIN/MAX refusal is a plan refusal and takes the existing engine.query path.

    Docs: docs/THREAT_MODEL.md gets a new A1 row, a rewritten "Extreme values" residual and a new "Rows, not people" residual. docs/ARCHITECTURE.md, the docs/PROJECT_SCOPE.md row and CHANGELOG.md (Security) are updated too.

    Checklist

  • scripts/check.sh passes locally

  • Every new refusal has a negative test

  • Every new security decision emits a SECURITY_AUDIT_EVENT covered by audit_coverage.rs

  • Fails closed on missing configuration, key material, or attestation

  • No new cryptographic primitives; suites stay behind their type aliases

  • Synthetic or public data only (docs/DATA_POLICY.md)

  • Docs and CHANGELOG.md updated for user-visible changes

  • Architectural decision recorded in docs/adr/ if one was made
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: abendrothj Review duration: 1784m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #282"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%