Skip to content

fix(security): bound set-returning function lists; authenticate before APQ registration; isolate root field errors - #134

Merged
archlemon merged 1 commit into
mainfrom
fix/audit-4
Nov 24, 2026
Merged

archlemon merged 1 commit into
mainfrom
fix/audit-4

Conversation

@archlemon

Copy link
Copy Markdown
Member

Closes #130, closes #131, closes #132

Set-returning function lists (#130)

  • Lists returned by set-returning functions compile with LIMIT limits.max_page_size. This covers SETOF root functions and computed columns, for row, composite and scalar results. The LIMIT sits on the function scan, before the relation laterals run.
  • The cost estimator prices these lists at max_page_size rows instead of 10. A nested connection below one now costs what it costs through a connection. For example, { manyUsers { id email postsByAuthorId { totalCount nodes { id title body } } } } was estimated at 4041 and is now 40401.
  • Breaking: such a list holds at most max_page_size items. This is documented in docs/configuration.md, docs/upgrading.md and CHANGELOG.md.

APQ (#132)

  • applyPersisted no longer registers anything itself. It marks the request, and registerPersisted registers the document after the request authenticated (HTTP, after the role check) and after Executor.CheckDocument passed: parse, document limits and validation, through the document cache. Over WebSocket, registration happens after Prepare succeeds.
  • The store is an LRU bounded by bytes: new persisted_queries.max_bytes (8 MiB) and persisted_queries.max_entry_bytes (64 KiB). It replaces the FIFO of 1024 entries of any size.
  • Probe under a 2G cgroup (jwt, no anonymous role, 400 unauthenticated 500 KB registrations): RSS 340 MB before, 27 MB after.

Root field errors under transactions (#131)

  • When a query field's statement fails in the pipelined batch and later fields were skipped, the query runs again through partialTx with a savepoint per root field. This applies to a database error other than a serialization failure, when the context is still live. The other fields keep their values, and there is no pg:25P02, no pathless internal error and no ERROR log.
  • If the failing field was the last statement, its error is reported as is and nothing reruns.
  • 25P02 stays only for skips after a non-field failure (a lost connection, an expired request) and for exhausted serialization retries. This is documented in docs/errors.md.

Small items

  • server.request_timeout must be >= 1s; 0 used to disable it silently.
  • An EWKT filter operand or near: reference whose SRID differs from the column's typmod SRID now fails at compile time with invalid_argument, instead of pg:XX000 invalid geometry (or an empty result). GeoJSON is still reprojected.
  • /schema.graphql now needs the same credentials as /graphql (shared authenticate helper). Without valid credentials and with no anonymous role, it answers 401, the same as __schema.

Tests

  • Unit tests: SETOF cost (limits_test.go), LIMIT on every SETOF shape and SRID rejection (srid_test.go), batch rerun and its exclusions (querytx_test.go), APQ auth, validation and byte bound (apq_test.go), SDL auth (routes_test.go), config validation.
  • E2E on PostGIS 18 with pgvector, each reproducing its issue's repro: setof_e2e_test.go, TestTxQueryFieldErrorUnderRoleSwitching, apq_e2e_test.go (APQ and /schema.graphql), srid_e2e_test.go. Updated expectations in TestTxQueryFieldErrors.
  • Goldens regenerated and reviewed: every change is a LIMIT 100 on a set-returning function.
  • go test -race ./..., go vet, golangci-lint, act lint-test, FuzzFilter and FuzzSpatial (10s each).

…e APQ registration; isolate root field errors

- Lists returned by set-returning functions (SETOF root functions and
  computed columns, rows, composites and scalars) compile with LIMIT
  limits.max_page_size, and the cost estimate prices them at that many
  rows instead of 10, so max_cost bounds the work below them.
- APQ documents are registered only after the request authenticated and
  the document parsed, passed the document limits and validated. The
  store is an LRU bounded by persisted_queries.max_bytes (8 MiB) and
  persisted_queries.max_entry_bytes (64 KiB) instead of 1024 entries of
  any size.
- When a query field's statement fails in a transactional batch (role
  switching, claims, transactions.per_request) and later fields were
  skipped, the query runs again with a savepoint per root field. The
  other fields keep their values; no pg:25P02 field errors, pathless
  internal error or ERROR log for a client error.
- server.request_timeout must be at least 1s; 0 disabled it silently.
- An EWKT filter operand or near: reference in another SRID than the
  column's typmod SRID is invalid_argument instead of pg:XX000.
- /schema.graphql requires the credentials /graphql requires.

BREAKING CHANGE: set-returning function lists hold at most
limits.max_page_size items; server.request_timeout below 1s is rejected;
/schema.graphql answers 401 without credentials unless roles.anonymous
is set; mismatched EWKT SRIDs are invalid_argument.
@archlemon
archlemon merged commit 383eec7 into main Nov 24, 2026
4 checks passed
@archlemon
archlemon deleted the fix/audit-4 branch November 24, 2026 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant