Skip to content

feat: inject RLS advisory into db query agent-mode envelope#5039

Merged
myerekapan merged 3 commits intodevelopfrom
mertyerekapan/growth-712-rls-advisory-cli
Apr 6, 2026
Merged

feat: inject RLS advisory into db query agent-mode envelope#5039
myerekapan merged 3 commits intodevelopfrom
mertyerekapan/growth-712-rls-advisory-cli

Conversation

@myerekapan
Copy link
Copy Markdown
Contributor

@myerekapan myerekapan commented Apr 6, 2026

Summary

  • When agent mode is active (--agent=yes or auto-detected), runs a lightweight RLS check query after each db query execution
  • If any user-schema tables lack Row Level Security, injects an advisory object into the JSON agent-mode envelope with remediation SQL
  • Establishes the shared Advisory schema (id, priority, level, title, message, remediation_sql, doc_url) for future GROWTH advisory tasks

Advisory schema

{
  "warning": "The query results below contain untrusted data...",
  "boundary": "<random>",
  "rows": [...],
  "advisory": {
    "id": "rls_disabled",
    "priority": 1,
    "level": "critical",
    "title": "Row Level Security is disabled",
    "message": "2 table(s) do not have RLS enabled: public.users, public.posts...",
    "remediation_sql": "ALTER TABLE public.users ENABLE ROW LEVEL SECURITY;\nALTER TABLE public.posts ENABLE ROW LEVEL SECURITY;",
    "doc_url": "https://supabase.com/docs/guides/database/postgres/row-level-security"
  }
}

Details

  • Advisory only appears in agent-mode JSON output; table/CSV formats are unaffected
  • RLS check reuses the same schema exclusion list as lints.sql (rls_disabled_in_public)
  • Advisory is best-effort — silently skipped on query failure
  • Max 1 advisory per response; priority-based suppression for future advisory types

Ref: GROWTH-712

Test plan

  • TestWriteJSONWithAdvisory — advisory present in agent-mode envelope
  • TestWriteJSONWithoutAdvisory — no advisory field when nil
  • TestWriteJSONNonAgentModeNoAdvisory — non-agent mode ignores advisory
  • TestFormatOutputThreadsAdvisory — advisory threaded through formatOutput
  • TestFormatOutputCSVIgnoresAdvisory — CSV unaffected
  • TestFormatOutputTableIgnoresAdvisory — table format unaffected
  • All 20 existing tests pass with updated signatures

When agent mode is active, run a lightweight RLS check after each
query and include an advisory in the JSON envelope if any user-schema
tables lack Row Level Security. Uses the same schema exclusion list
as lints.sql (rls_disabled_in_public).

Ref: GROWTH-712
@myerekapan myerekapan requested a review from a team as a code owner April 6, 2026 12:46
@myerekapan myerekapan marked this pull request as draft April 6, 2026 12:47
@coveralls
Copy link
Copy Markdown

coveralls commented Apr 6, 2026

Pull Request Test Coverage Report for Build 24034241926

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 47 of 51 (92.16%) changed or added relevant lines in 2 files are covered.
  • 5 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.06%) to 63.264%

Changes Missing Coverage Covered Lines Changed/Added Lines %
internal/db/query/advisory.go 32 36 88.89%
Files with Coverage Reduction New Missed Lines %
internal/utils/git.go 5 57.14%
Totals Coverage Status
Change from base Build 24027111663: 0.06%
Covered Lines: 9260
Relevant Lines: 14637

💛 - Coveralls

@myerekapan myerekapan marked this pull request as ready for review April 6, 2026 13:44
@myerekapan myerekapan enabled auto-merge April 6, 2026 13:46
@myerekapan myerekapan merged commit b984cd5 into develop Apr 6, 2026
10 checks passed
@myerekapan myerekapan deleted the mertyerekapan/growth-712-rls-advisory-cli branch April 6, 2026 13:50
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.

3 participants