Skip to content

fix(id-pg): validate allowlist names at construction, refuse unsafe projection columns (#14502) - #14541

Merged
developing-today-fleet[bot] merged 1 commit into
mainfrom
queue/iw199-14502-allowlist-validate
Nov 24, 2026
Merged

developing-today-fleet[bot] merged 1 commit into
mainfrom
queue/iw199-14502-allowlist-validate

Conversation

@dezren39

@dezren39 dezren39 commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Closes #14502. Follow-up to #14391 (PR #14497, merged 2026-11-24T18:35:16Z as dac3cb57; this branch is rebased onto that merge).

What

PR #14497 refused reserved or non-identifier filter/order columns at translate time, but the projection path was unchecked: resolve_projection expanded select against the declared columns and joined the names raw into the select value, and CollectionAllowlist accepted any string as a declared column name — a declared a,b, x(y), or or landed raw in the request.

Change

  • allowlist.rs: CollectionAllowlist::validate() -> Result<(), String> — relation must be a plain identifier; every declared column must satisfy is_usable_field_name (plain identifier, not a reserved PostgREST parameter name); every unique_key entry must be a declared column. The doc comment states which names are rejected and why. Registration (id: impl: Postgres HTTP adapter registration and owner config (from #5805) #13758) calls this when an allowlist is built.
  • translate.rs: Translator::try_new — a Result-returning constructor that validates every collection at construction, so a bad config never reaches a request. (Translator::new stays infallible for already-validated sets; translate-time refusals below apply regardless.)
  • translate.rs defense in depth: resolve_projection refuses with field_unsupported when a declared column fails is_usable_field_name — in the star/empty expansion (via expand_declared) and in an explicit select list — so no select parameter is emitted. Step 8 also refuses a unique-key column that is not a usable field name, since effective_ordering renders it raw into order and the keyset or group. All refusals are the same field_unsupported shape as an undeclared column, so refusal bodies stay byte-identical for withheld and unknown columns.

Tests

cargo test -p id-pg in pkgs/id (laptop worktree; code CI runs on main only): 19 unit + 2 property + 15 refusal-table, all pass; cargo fmt clean. (cargo clippy -p id-pg fails on this host before reaching the crate — E0514, serde built by an incompatible rustc, the same environment failure PR #14497's body records; it reproduces with a fresh target dir and is not a code finding.) New tests:

  • validate() refuses declared a,b, refuses declared or, refuses a non-identifier relation, refuses an undeclared unique-key entry, accepts a plain collection.
  • A select * read against a collection declaring x(y) is refused as field_unsupported; same for an explicit select x(y).
  • try_new accepts a valid allowlist and refuses an unvalidated one.
  • Pre-existing withheld_and_unknown_columns_produce_identical_bodies still passes.

Queue record: task 23612 (repo-health-code-pilot), lane ITEM-WORK-199.

{
  "direct_parent": null,
  "links": [],
  "lineage": {
    "design": null,
    "roadmap_item": null,
    "priority": null
  },
  "pm_meta": 1,
  "provenance": {
    "queue_id": null,
    "scheduled_start": null,
    "picked_up_at": null,
    "work_started_at": null,
    "created_at": "2026-11-24T18:37:31Z",
    "session_id": null,
    "lane": null,
    "host": "amd",
    "worktree": "/home/user/wt-lane-iw199-14502",
    "model": null,
    "lane_start_issues": [],
    "workspace_ref": {
      "kind": "worktree",
      "id": "/home/user/wt-lane-iw199-14502",
      "repo": "developing-today/code",
      "branch": "queue/iw199-14502-allowlist-validate",
      "sha": "a332cb3338b90d981cdb26ea92107c1b680b8320"
    },
    "auth_subject": "oc-code-02",
    "stamped_by": "fleet 0.1.0 (native)"
  }
}

Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…rojection columns (#14502)

Follow-up to #14391 (PR #14497). The filter/order path refused
reserved or non-identifier columns at translate time, but the
projection path was unchecked: resolve_projection joined declared
column names raw into the select value, and CollectionAllowlist
accepted any string as a declared column name.

- allowlist.rs: CollectionAllowlist::validate() refuses a relation
  that is not a plain identifier, a declared column that is not a
  usable field name (plain identifier, not a reserved PostgREST
  parameter name), and a unique_key entry that is not a declared
  column. Registration (#13758) calls it when an allowlist is built.
- translate.rs: Translator::try_new, a Result-returning constructor
  that validates every collection at construction.
- translate.rs: defense in depth at translate time — resolve_projection
  refuses (field_unsupported) when a declared column fails
  is_usable_field_name, in both the star expansion and an explicit
  select list; step 8 also refuses a unique-key column that is not a
  usable field name, since effective_ordering renders it raw into
  the order parameter and the keyset or group.

Tests: cargo test -p id-pg green (19 unit + 2 property + 15
refusal-table), including new validate() tests (a,b refused, or
refused, plain accepted), star and explicit projection refusal for a
declared x(y), try_new accept/refuse, and the pre-existing
withheld_and_unknown_columns_produce_identical_bodies.
@coderabbitai

coderabbitai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 25 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 33bf2a4b-a209-4341-9395-c36c499334d6
Commits

Reviewing files that changed from the base of the PR and between 152a81a and a332cb3.

Files selected for processing: 2

  • pkgs/id/crates/id-pg/src/allowlist.rs
  • pkgs/id/crates/id-pg/src/translate.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@developing-today-fleet
developing-today-fleet Bot merged commit 9a7c7d6 into main Nov 24, 2026
2 checks passed
@developing-today-fleet
developing-today-fleet Bot deleted the queue/iw199-14502-allowlist-validate branch November 24, 2026 18:38
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.

id-pg: validate allowlist names at construction and refuse unsafe projection columns (follow-up to #14391)

1 participant