fix(rls): Onda 13 — audit_log_gravacao + seo_audit_log admin-only (B-3 ENCERRADA)#207
Conversation
…isor_or_above (Onda 13, B-3 ENCERRADA) Auditoria pre-prod (10/mai/2026) apontou 7 tabelas overly-permissive. Investigacao mostrou que 5 ja foram fechadas em ondas anteriores, sync_jobs foi removida, e notification_templates fechada na Onda 8. Restavam 2 audit logs reais: - audit_log_gravacao: log de mudancas em precos de gravacao, contem usuario/valor_antes/depois - seo_audit_log: historico de auditorias SEO Mudanca: SELECT restrito a is_supervisor_or_above. INSERT continua via triggers SECDEF. Pre-deploy: code_search zero matches em src/ e supabase/functions/ para ambas. APLICADA EM PROD via MCP apply_migration (ADR 0006). B-3 ENCERRADA. Ref: docs/AUDITORIA-PROFUNDA-PROMOGIFTS-PRE-PROD.md (B-3, secao 2.3)
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
Visão geralEsta migration SQL restringe o acesso de leitura nas tabelas de auditoria ( MudançasRestrição de acesso a logs de auditoria
Esforço estimado de revisão🎯 1 (Trivial) | ⏱️ ~3 minutos PRs possivelmente relacionadas
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
This PR records a Supabase RLS hardening migration that restricts two audit-log tables to supervisor-or-above access, closing the stated B-3 audit blocker without changing frontend or edge-function code.
Changes:
- Drops permissive authenticated SELECT policies on
audit_log_gravacaoandseo_audit_log. - Adds supervisor-or-above SELECT policies using
is_supervisor_or_above((SELECT auth.uid())). - Adds policy comments documenting the security rationale.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| -- ESTADO DA B-3 APOS ESTA MIGRATION: | ||
| -- Auditoria pre-prod listou 7 tabelas overly-permissive. Estado final: | ||
| -- - audit_log: ja correta (supervisor_or_above) — fechada antes | ||
| -- - analytics_events: ja correta (self ou coord) — fechada antes | ||
| -- - product_views: ja correta (admin ou seller_id) — fechada antes | ||
| -- - search_queries: ja correta (self ou coord) — fechada antes | ||
| -- - quote_templates: ja correta (por created_by) — fechada antes | ||
| -- - sync_jobs: tabela nao existe mais — N/A | ||
| -- - notification_templates: fechada em Onda 8 (PR #199) | ||
| -- - audit_log_gravacao (esta migration): supervisor_or_above | ||
| -- - seo_audit_log (esta migration): supervisor_or_above |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 014bb74641
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| -- APLICADA EM PROD via MCP apply_migration (ADR 0006). | ||
|
|
||
| -- ─── audit_log_gravacao ─── | ||
| DROP POLICY IF EXISTS audit_log_gravacao_read_authenticated ON public.audit_log_gravacao; |
There was a problem hiding this comment.
Guard the migration when audit log tables are absent
On Supabase Preview branches that replay supabase/migrations from scratch, this migration will fail before applying because audit_log_gravacao and seo_audit_log are not created anywhere earlier in supabase/migrations (repo-wide rg -i only finds this new file). DROP POLICY IF EXISTS ... ON public.audit_log_gravacao still requires the target relation to exist, so branches/environments without these production-only tables hit undefined_table; wrap these policy changes in table-existence guards as done in the recent migration fixes.
Useful? React with 👍 / 👎.
🎯 Objetivo
Fecha 2 audit logs reais que estavam legíveis por qualquer usuário authenticated, encerrando o bloqueador B-3 da auditoria pré-prod.
🔒 Mudança
audit_log_gravacaoaudit_log_gravacao_read_authenticatedcomUSING (true)audit_log_gravacao_select_supervisor_or_abovecomis_supervisor_or_above((SELECT auth.uid()))seo_audit_logauth_read_seo_audit_logcomUSING (true)seo_audit_log_select_supervisor_or_abovecomis_supervisor_or_above((SELECT auth.uid()))🚨 Por que importa
audit_log_gravacaoColunas:
id, tabela_origem, operacao, registro_id, codigo_tabela, campos_alterados, valor_antes, valor_depois, usuario, tsÉ o log de mudanças em
tabela_preco_gravacao_oficial— guarda:usuario)campos_alterados)valor_antes) e depois (valor_depois)Vendedor que conhecesse o nome da tabela podia ver histórico completo de mudanças de preço + identificar quem fez cada alteração. Sensível comercialmente.
seo_audit_logHistórico de auditorias SEO — info operacional interna. Vendedor não precisa ver.
✅ Pré-deploy: investigação completa
Conclusão: nenhum código de aplicação consulta essas tabelas. São acessadas apenas via Supabase Dashboard pelo admin. Mudança 100% transparente para clientes.
✅ Pós-deploy validado em PROD
Aplicada via MCP
apply_migrationem 14/mai/2026 22:09 UTC. ValidaçãoSELECT * FROM pg_policies:📊 Estado da B-3 após este PR
Auditoria pré-prod listou 7 tabelas com policies
USING(true). Investigação cruzada com banco real revelou:audit_logis_supervisor_or_aboveanalytics_eventsuser_id = self OR is_coord_or_aboveproduct_viewsis_admin OR seller_id = selfsearch_queriesuser_id = self OR is_coord_or_abovequote_templatesauth.uid() = created_bysync_jobsnotification_templatesis_supervisor_or_aboveaudit_log_gravacaois_supervisor_or_aboveseo_audit_logis_supervisor_or_aboveB-3 ENCERRADA. 🎉
🔍 Cenários adversos simulados
is_supervisor_or_aboveativa📁 Arquivos
supabase/migrations/20260514220543_onda13_rls_audit_logs_admin_only.sql(+61 linhas)📚 Ref
notification_templates)Summary by cubic
Restricts SELECT on
audit_log_gravacaoandseo_audit_logto supervisors or above, replacing openUSING (true)policies. Closes audit blocker B-3 with no app impact.audit_log_gravacao_select_supervisor_or_aboveandseo_audit_log_select_supervisor_or_aboveusingis_supervisor_or_above((SELECT auth.uid())).audit_log_gravacao_read_authenticatedandauth_read_seo_audit_log.Written for commit 014bb74. Summary will update on new commits.
Summary by CodeRabbit
Release Notes
Segurança
Documentação