Skip to content

fix: aggregate result types respect column-level SELECT permission - #653

Open
philipsorensen wants to merge 1 commit into
supabase:masterfrom
philipsorensen:fix/aggregate-respect-column-select-permission
Open

philipsorensen wants to merge 1 commit into
supabase:masterfrom
philipsorensen:fix/aggregate-respect-column-select-permission

Conversation

@philipsorensen

Copy link
Copy Markdown

What

AggregateNumericType::fields() (src/graphql.rs) builds the *AggregateResult object types (Sum/Avg/Min/Max) by iterating every aggregatable column, but — unlike every sibling builder — it does not filter on column.permissions.is_selectable.

The other field/type builders all filter on the relevant permission flag:

  • FilterEntityType::fields()is_selectable
  • OrderByEntityType::fields()is_selectable
  • the Node column builder → is_selectable
  • InsertInputType / UpdateSetInputis_insertable / is_updatable

Because the aggregate builder skipped this check, a role with table-level SELECT but a column-level REVOKE SELECT on a specific column still saw that column's name and type under <Table>{Sum,Avg,Min,Max}AggregateResult during introspection, even though the column is otherwise omitted everywhere else in the schema for that role.

Change

Add the col.permissions.is_selectable guard to the aggregate column loop, matching the sibling builders. A non-selectable column is now omitted from the aggregate result types too.

Test

Adds permissions_aggregate_column, which enables aggregates on a table, revokes SELECT on one column from a role, and introspects AccountSumAggregateResult / AccountMaxAggregateResult as that role — the revoked column no longer appears, while aggregating a permitted column still works. Full suite (./bin/installcheck, pg17) passes: 123/123.

The `*AggregateResult` object types (Sum/Avg/Min/Max) built by
`AggregateNumericType::fields()` listed every aggregatable column on a
table without filtering by `column.permissions.is_selectable`, unlike
every sibling builder — `FilterEntityType`, `OrderByEntityType`, the
Node column builder, `InsertInputType`, `UpdateSetInput` all filter on
the relevant permission flag.

As a result, a role with table-level SELECT but a column-level
`REVOKE SELECT` on a specific column still saw that column's name and
type exposed under `<Table>{Sum,Avg,Min,Max}AggregateResult` during
introspection. This aligns the aggregate builder with the rest of the
schema so a non-selectable column is omitted there too.

Adds `permissions_aggregate_column` regression test covering the
introspection of the aggregate result types under a column-level revoke.

Signed-off-by: Philip Sørensen <git@ppsa.dk>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant