# postgres-ai-tenant-boundary-v2

> postgres-ai-tenant-boundary-v2: 7 Keryn rules for python, typescript, javascript, go, rust, generic (6 warning, 1 info).

Source: https://keryn.dev/rules/postgres-ai-tenant-boundary-v2/

7 rules · Keryn Software Licence · rules 0.8.0 · [all packs](https://keryn.dev/rules/)

**How to read a rule**

- **Severity**: How bad the finding is if it is real: `error` fails a default gate, `warning` and `info` do not.

- **Confidence**: **P0** exploitable as written; **P1** dangerous in context; **P2** a heuristic or a posture check: confirm by reading the code.

- **False-positive risk**: **low**: an exact API or flag, so hits are almost always real; **medium**: the pattern is legitimate in many programs, so check each hit; **high**: it finds a lead to confirm, so expect benign hits.

- **Edge**: The relationship the finding sits on. **reaches**: content or traffic gets to a thing; **calls**: one thing invokes another; **reads**: one thing reads from another; **writes**: one thing writes to another; **sends**: data leaves for another party; **grants**: authority is given or left unchecked; **depends_on**: something relies on a component it does not verify; **trusts**: one party believes another without evidence. The boundary it crosses, when there is one: **user->prompt** (untrusted input reaching a prompt); **model->code** (model output reaching code, a shell, a query or a page); **secret->outside** (a secret leaving the trusted side); **supply-chain** (code, models or prompts pulled in from outside).

- **Taxonomy chips**: References for readers who work in OWASP LLM 2025, OWASP Agentic, CWE or NIST AI RMF. They say where a rule belongs, not that a framework is satisfied.

## seceng.postgres.pgvector-query-without-tenant-filter

`warning` python, typescript, javascript, go, rust postgres

pgvector similarity query over AI/RAG data lacks a visible tenant, user, workspace, or organization predicate.

Confidence **P2**: a heuristic or a posture check: confirm by reading the code. False-positive risk **medium**: the pattern is legitimate in many programs, so check each hit.

Edge inspected: [grants](https://keryn.dev/docs/edges/edge-kinds/#grants) authority is given or left unchecked.

[CWE-639](https://keryn.dev/taxonomies/cwe/#cwe-639-authorization-bypass-through-user-controlled-key) [LLM08](https://keryn.dev/taxonomies/owasp-llm/#llm08-vector-and-embedding-weaknesses) [ASI03](https://keryn.dev/taxonomies/owasp-agentic/#asi03-identity-and-privilege-abuse) [ASI06](https://keryn.dev/taxonomies/owasp-agentic/#asi06-memory-and-context-poisoning)

Also reported under the older id `seceng.neon-vector-query-without-tenant`, `seceng.supabase.vector-similarity-query-without-tenant-predicate`.

## seceng.postgres-ai-table-without-rls

`warning` generic postgres

Postgres table containing AI chat, memory, prompt, document, embedding, or agent-run data is created without a nearby RLS enablement statement.

Confidence **P1**: dangerous in context. False-positive risk **high**: it finds a lead to confirm, so expect benign hits.

Edge inspected: [grants](https://keryn.dev/docs/edges/edge-kinds/#grants) authority is given or left unchecked.

[CWE-862](https://keryn.dev/taxonomies/cwe/#cwe-862-missing-authorization) [LLM02](https://keryn.dev/taxonomies/owasp-llm/#llm02-sensitive-information-disclosure) [LLM08](https://keryn.dev/taxonomies/owasp-llm/#llm08-vector-and-embedding-weaknesses) [ASI03](https://keryn.dev/taxonomies/owasp-agentic/#asi03-identity-and-privilege-abuse) [ASI06](https://keryn.dev/taxonomies/owasp-agentic/#asi06-memory-and-context-poisoning) [ASI02](https://keryn.dev/taxonomies/owasp-agentic/#asi02-tool-misuse-and-exploitation)

## seceng.postgres-security-definer-rag-function

`warning` generic postgres

SECURITY DEFINER function touches AI/RAG tables. Verify tenant scoping, search\_path, and caller authorization because this can bypass RLS.

Confidence **P1**: dangerous in context. False-positive risk **high**: it finds a lead to confirm, so expect benign hits.

Edge inspected: [reads](https://keryn.dev/docs/edges/edge-kinds/#reads) one thing reads from another.

[CWE-266](https://keryn.dev/rules/?cwe=CWE-266) [LLM08](https://keryn.dev/taxonomies/owasp-llm/#llm08-vector-and-embedding-weaknesses) [ASI03](https://keryn.dev/taxonomies/owasp-agentic/#asi03-identity-and-privilege-abuse) [ASI06](https://keryn.dev/taxonomies/owasp-agentic/#asi06-memory-and-context-poisoning)

## seceng.postgres-vector-rpc-missing-auth-uid

`warning` generic postgres

Vector search SQL function appears to lack auth.uid(), tenant\_id, user\_id, workspace\_id, or organization\_id checks.

Confidence **P2**: a heuristic or a posture check: confirm by reading the code. False-positive risk **medium**: the pattern is legitimate in many programs, so check each hit.

Edge inspected: [grants](https://keryn.dev/docs/edges/edge-kinds/#grants) authority is given or left unchecked.

[CWE-639](https://keryn.dev/taxonomies/cwe/#cwe-639-authorization-bypass-through-user-controlled-key) [LLM08](https://keryn.dev/taxonomies/owasp-llm/#llm08-vector-and-embedding-weaknesses) [ASI03](https://keryn.dev/taxonomies/owasp-agentic/#asi03-identity-and-privilege-abuse) [ASI06](https://keryn.dev/taxonomies/owasp-agentic/#asi06-memory-and-context-poisoning)

## seceng.postgres-ai-function-dynamic-sql

`warning` generic postgres

AI/RAG SQL function uses dynamic SQL. Dynamic SQL around vector or prompt data can create injection or authorization-bypass risk.

Confidence **P1**: dangerous in context. False-positive risk **high**: it finds a lead to confirm, so expect benign hits.

Edge inspected: [calls](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another; it crosses the [`model->code`](https://keryn.dev/docs/edges/trust-boundaries/#model-to-code) boundary (model output reaching code, a shell, a query or a page).

[CWE-89](https://keryn.dev/taxonomies/cwe/#cwe-89-sql-injection) [LLM08](https://keryn.dev/taxonomies/owasp-llm/#llm08-vector-and-embedding-weaknesses) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling) [ASI01](https://keryn.dev/taxonomies/owasp-agentic/#asi01-agent-goal-hijack) [ASI03](https://keryn.dev/taxonomies/owasp-agentic/#asi03-identity-and-privilege-abuse) [ASI06](https://keryn.dev/taxonomies/owasp-agentic/#asi06-memory-and-context-poisoning)

## seceng.postgres-prompt-or-secret-column-in-public-view

`warning` generic postgres

Database view appears to expose prompt, system instruction, tool, secret, or transcript columns.

Confidence **P1**: dangerous in context. False-positive risk **high**: it finds a lead to confirm, so expect benign hits.

Edge inspected: [writes](https://keryn.dev/docs/edges/edge-kinds/#writes) one thing writes to another.

[CWE-200](https://keryn.dev/taxonomies/cwe/#cwe-200-exposure-of-sensitive-information-to-an-unauthorized-actor) [LLM02](https://keryn.dev/taxonomies/owasp-llm/#llm02-sensitive-information-disclosure) [LLM07](https://keryn.dev/taxonomies/owasp-llm/#llm07-system-prompt-leakage) [ASI03](https://keryn.dev/taxonomies/owasp-agentic/#asi03-identity-and-privilege-abuse) [ASI02](https://keryn.dev/taxonomies/owasp-agentic/#asi02-tool-misuse-and-exploitation) [ASI10](https://keryn.dev/taxonomies/owasp-agentic/#asi10-rogue-agents)

## seceng.postgres-ai-audit-log-raw-prompt

`info` python, typescript, javascript postgres

SQL insert or table schema appears to store raw prompt/messages/completions in audit logs without a redaction hint.

Confidence **P1**: dangerous in context. False-positive risk **high**: it finds a lead to confirm, so expect benign hits.

Edge inspected: [writes](https://keryn.dev/docs/edges/edge-kinds/#writes) one thing writes to another.

[CWE-532](https://keryn.dev/taxonomies/cwe/#cwe-532-insertion-of-sensitive-information-into-log-file) [LLM02](https://keryn.dev/taxonomies/owasp-llm/#llm02-sensitive-information-disclosure)
