8000 Field-level (column) permissions in the allowlist JSON (#3) by simon-inkie · Pull Request #4 · simon-inkie/inkie-pg-read · GitHub
[go: up one dir, main page]

Skip to content

Field-level (column) permissions in the allowlist JSON (#3) - #4

Merged
simon-inkie merged 5 commits into
mainfrom
3-column-level-allowlist
Oct 11, 2026
Merged

simon-inkie merged 5 commits into
mainfrom
3-column-level-allowlist

Conversation

@simon-inkie
@simon-inkie simon-inkie commented Oct 7, 2026 •
Copy link
Copy Markdown
Owner

Requested by Simon · project thread

Closes #3

Before: .pgr-agent.json could only allow whole tables.

After: an allow entry can be { "table": "memberships", "columns": ["id", "role"] }. Plain strings still allow every column. For an object entry, anything outside columns is refused before a connection is opened, with an error naming the column and the config file.

What it does

  • Config: string or { table, columns } entries, in both the per-agent and working-directory files.
  • Column guard (src/column-guard.ts): parses the query and resolves columns through aliases, joins, USING, CTEs, subqueries, LATERAL and set operations. Refuses unlisted columns, select *, m.*, unqualified columns, whole-row forms (to_jsonb(m), bare alias, cast), alias column lists, dynamic-SQL functions (including as FROM items), pg_stats* relations, and any query the parser cannot read while column rules are active.
  • Strict validation: unknown keys, wrong types, missing or empty columns, wildcards and duplicate tables fail at load time naming the file and path.
  • Table gate fix: it now also sees tables after a comma in FROM (from interviews, secret_table), using the parser's view of FROM items. This applies to the table gate generally.

How

Uses pgsql-ast-parser (pure TS, new dependency) for the AST. Where a reference cannot be proven to be a permitted column, it is refused. Decisions, review feedback and responses are in .specs/3-column-level-allowlist/SPEC.md.

Worth knowing

  • Behaviour change: configs with junk allow entries (for example 42) or malformed JSON used to be tolerated silently (default-deny). They now exit 1 with an error naming the file. Existing tests that asserted the old behaviour were updated.
  • Known limitation: the dynamic-SQL function list is a denylist (documented in the README).
  • Row-level filtering is out of scope.

bun run typecheck and bun test pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AYkdX5KFu9z9QH7uLgLSXG

claude added 2 commits October 7, 2026 15:38
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AYkdX5KFu9z9QH7uLgLSXG
Signed-off-by: Claude <noreply@anthropic.com>
Allow entries may be { table, columns }. A column guard parses the query
and refuses unlisted columns, select *, unqualified columns and whole-row
expressions on restricted tables before any connection is opened. Config
is validated strictly and fails loudly.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AYkdX5KFu9z9QH7uLgLSXG
Signed-off-by: Claude <noreply@anthropic.com>
@simon-inkie simon-inkie self-assigned this Oct 7, 2026
claude added 3 commits October 7, 2026 15:47
…ase (#3)

Address review: refuse every unparseable query while column rules are
active, refuse pg_stats and related relations, compare quoted identifiers
as written, document limits. Record review feedback in the spec.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AYkdX5KFu9z9QH7uLgLSXG
Signed-off-by: Claude <noreply@anthropic.com>
…gate (#3)

Address second review: visit FROM-clause calls through the dynamic-SQL
check, add AST-derived tables to the table gate, tidy docs. Record review
feedback in the spec.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AYkdX5KFu9z9QH7uLgLSXG
Signed-off-by: Claude <noreply@anthropic.com>
Address third review. Record feedback and a follow-up in the spec.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AYkdX5KFu9z9QH7uLgLSXG
Signed-off-by: Claude <noreply@anthropic.com>
@simon-inkie
Copy link
Copy Markdown
Owner Author

Review leg: Aggy (AI review agent).
Verdict: ready to merge.
Checked: delivers issue #3 with strict AST-level query validation using pgsql-ast-parser. Rejects unlisted columns, select *, whole-row expressions, unqualified columns under restricted tables, alias lists, dynamic SQL functions, and stats views. Closes comma-join table extraction in table-refs.ts. Config validation fails loudly on malformed entries. All 287 unit tests and TypeScript typecheck pass locally; GitHub CI passes. No security regressions in SQL or database guard boundaries. SPEC present and honest.
Not verified: live queries against a real PostgreSQL production instance.
Merge decision stays with the maintainer.

@simon-inkie
simon-inkie merged commit b709e87 into main Oct 11, 2026
1 check passed
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.

Field-level (column) permissions in the allowlist JSON

2 participants

0