Skip to content

fix(security)!: count-only limit=0, CSV newline fidelity, reserved ~ names everywhere - #104

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 #100, closes #101, closes #102

  • Count-only limit=0. The root selection is compiled (so it is validated) and then discarded; the look-ahead row that decides has_next projects nothing and runs no embed, spread or computed column. Cost stays 1, which now matches what runs. Also covers SETOF <table> RPCs. Goldens: limit_zero updated, limit_zero_rpc and limit_zero_params added (parameter renumbering after the discarded selection).
  • CSV. encoding/csv is replaced by a small RFC 4180 writer: CR/LF inside values are quoted and kept byte for byte, records end in CRLF, formula escaping unchanged.
  • Reserved ~ names. One queryField helper is used by every query-string resolver (casts, JSON paths, aggregates, every order= form, distinct=, on_conflict=); columns= rejects them too. select=* and JSON bodies still reach such a column.
  • Small items. Vary: Accept on 401/403 from auth; preflight Vary: Origin was already set by pdbcore and is now pinned by tests; server.request_timeout must be >= 1s (breaking, docs/upgrading.md row).
  • Contract "over-hides an RPC". Not a bug: in the audit run the function was created after the contract server booted without watch mode. A regression test pins that a contract keeps one-row, set and array-of-rows functions over a table it shows; docs/contracts.md notes that contracts are built once at boot without watch mode.

Tests: unit + e2e (test/e2e_hardening_test.go, each fails on main and passes here), go test -race ./..., full e2e on PG 18, FuzzFilter/FuzzParse 10s, golangci-lint, act lint-test.

…names everywhere

A root limit=0 was costed at 1 but still projected its look-ahead row,
running every embed, spread and computed column under it. The selection
is now compiled for validation and discarded: the look-ahead row reads
only the root, so the statement does what the estimate prices.

CSV records are written by a small RFC 4180 writer: CR and LF inside a
value are quoted and copied byte for byte (encoding/csv with UseCRLF
dropped a bare CR and rewrote LF as CRLF), records still end in CRLF and
formula escaping is unchanged.

Every query-string resolver now treats ~-prefixed names only through the
reserved namespace: casts, JSON paths and aggregates in select=, JSON-path,
distance and related order= terms, distinct=, on_conflict= and columns=
answer like the plain forms. select=* and JSON bodies still reach such a
column.

401/403 answers from authentication carry Vary: Accept; preflight
responses already vary on Origin and are now covered by tests.
server.request_timeout must be at least 1s. A contract keeps functions
returning arrays of rows of a table it shows (regression test; the
reported 404 came from a function created after the server booted).

BREAKING CHANGE: server.request_timeout below 1s (including 0, which
disabled the timeout) is a configuration error, and a column named ~x
can no longer be named by casts, JSON paths, aggregates, distinct=,
on_conflict= or columns=.
@archlemon
archlemon merged commit 8da22b1 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