Skip to content

fix(security+ci+env): Auditoria 2026-06-02 — Passos 4/5/6 concluídos#627

Merged
adm01-debug merged 1 commit into
mainfrom
fix/audit-remaining-items
Jun 3, 2026
Merged

fix(security+ci+env): Auditoria 2026-06-02 — Passos 4/5/6 concluídos#627
adm01-debug merged 1 commit into
mainfrom
fix/audit-remaining-items

Conversation

@adm01-debug
Copy link
Copy Markdown
Owner

@adm01-debug adm01-debug commented Jun 3, 2026

Resumo

Implementa os 3 itens urgentes da Auditoria QA 2026-06-02 que restavam pendentes após os PRs #619#626.


PASSO 4 — 🔐 Security: RLS ai_description_queue

Problema (RISCO-1 da auditoria):
Policy ai_queue_service_all com USING(true) permite que qualquer usuário autenticado leia, insira, atualize e delete filas de IA — IDOR crítico.

Fix (supabase/migrations/20260602130000):

  • DROP POLICY "ai_queue_service_all"
  • 4 policies de mínimo privilégio criadas:
    • SELECT: auth.uid() = requested_by OR is_admin_or_above()
    • INSERT: WITH CHECK (auth.uid() = requested_by)
    • UPDATE/DELETE: apenas is_admin_or_above()

PASSO 5 — ⚙️ CI: Quality Gate corrigido

Problema:
Workflow quality-gate.yml tinha mojibake (VITE_SUPA@¡SE_URL em vez de VITE_SUPABASE_URL) + arquivo armazenado como base64 puro (GitHub Actions não conseguia parsear).

Fix (.github/workflows/quality-gate.yml):

  • YAML puro, encodings corretos
  • 5 gates funcionais:
    • Gate 1: TypeScript zero regressions (check-tsc-baseline.mjs)
    • Gate 2: ESLint zero regressions (lint:baseline)
    • Gate 3: Build check (npm run build)
    • Gate 4: Vitest unit tests (test:ci-core)
    • Gate 5 (novo): Supabase Type Drift Detection — detecta quando types.ts diverge do schema real

PASSO 6 — 🔧 Env: .env.example corrigido

Problema:
.env.example declarava VITE_SUPABASE_PUBLISHABLE_KEY mas CI e código-padrão usam VITE_SUPABASE_ANON_KEY (nome oficial Supabase). Novos devs configuravam var errada e não conectavam.

Fix:

  • VITE_SUPABASE_ANON_KEY como variável primária
  • VITE_SUPABASE_PUBLISHABLE_KEY mantido como alias comentado (compatibilidade com código legado que faz fallback)

Checklist


Summary by cubic

Endurece o RLS da tabela ai_description_queue para eliminar o risco de IDOR, restaura o quality gate do CI com 5 checagens, e corrige o .env.example para usar VITE_SUPABASE_ANON_KEY. Conclui os passos 4/5/6 da Auditoria QA 2026-06-02.

  • Bug Fixes

    • Security (RLS): remove ai_queue_service_all e cria 4 policies de mínimo privilégio — SELECT (dono ou admin), INSERT (dono), UPDATE/DELETE (apenas admin).
    • CI: reescreve quality-gate.yml em YAML válido com 5 gates (TypeScript baseline, ESLint baseline, build, Vitest, Supabase types drift).
    • Env: .env.example passa a usar VITE_SUPABASE_ANON_KEY; mantém VITE_SUPABASE_PUBLISHABLE_KEY como alias comentado.
  • Migration

    • DB: sem ação manual; migration aplica as novas policies.
    • Dev: preferir VITE_SUPABASE_ANON_KEY no .env (alias legado opcional).
    • CI opcional: adicionar SUPABASE_ACCESS_TOKEN para habilitar o gate de type drift em PRs.

Written for commit efbc4a1. Summary will update on new commits.

Review in cubic

…rreto, RLS ai_description_queue

PASSO 4 — Security fix:
- supabase/migrations/20260602130000: substitui policy USING(true) em
  ai_description_queue por 4 policies granulares (mínimo privilégio)
  - SELECT: owner OR is_admin_or_above()
  - INSERT: WITH CHECK auth.uid() = requested_by
  - UPDATE/DELETE: somente is_admin_or_above()
  Elimina risco de IDOR identificado na Auditoria 2026-06-02 (RISCO-1)

PASSO 5 — CI fix:
- .github/workflows/quality-gate.yml: arquivo armazenado como YAML puro
  (a versão anterior em main tinha encodings incorretos com mojibake em
  VITE_SUPABASE_URL → VITE_SUPA@¡SE_URL). 5 gates agora limpos:
  Gate1=TSC, Gate2=ESLint, Gate3=Build, Gate4=Vitest, Gate5=SupabaseDrift

PASSO 6 — Env fix:
- .env.example: primary var agora é VITE_SUPABASE_ANON_KEY (padrão
  Supabase oficial), PUBLISHABLE_KEY mantida como alias comentado para
  compatibilidade. Evita que novos devs criem .env com nome errado.

Auditoria 2026-06-02 — Ações imediatas: CONCLUÍDO (4/4 passos urgentes)
Copilot AI review requested due to automatic review settings June 3, 2026 00:38
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
we-dream-big Building Building Preview Jun 3, 2026 12:38am

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@adm01-debug adm01-debug merged commit 7e66382 into main Jun 3, 2026
19 of 35 checks passed
@supabase
Copy link
Copy Markdown

supabase Bot commented Jun 3, 2026

This pull request has been ignored for the connected project doufsxqlfjyuvxuezpln due to reaching the limit of concurrent preview branches.
Go to Project Integrations Settings ↗︎ if you wish to update this limit.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

Warning

Review limit reached

@adm01-debug, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 25 minutes and 10 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d08cecb2-9e96-4d28-bd9d-415971056007

📥 Commits

Reviewing files that changed from the base of the PR and between b30ccb0 and efbc4a1.

📒 Files selected for processing (3)
  • .env.example
  • .github/workflows/quality-gate.yml
  • supabase/migrations/20260602130000_fix_ai_description_queue_rls_policy.sql
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/audit-remaining-items

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Este PR conclui os passos 4/5/6 da Auditoria QA (2026-06-02), endurecendo o RLS da fila de IA para mitigar IDOR, restaurando o workflow de “quality gate” do CI em YAML válido e alinhando o .env.example com o nome canônico da anon key do Supabase.

Changes:

  • Security: substitui a policy permissiva da ai_description_queue por policies granulares (owner/admin).
  • CI: reescreve o quality-gate.yml para YAML válido e adiciona um check de drift dos types do Supabase.
  • Env: padroniza .env.example para VITE_SUPABASE_ANON_KEY mantendo alias legado comentado.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
supabase/migrations/20260602130000_fix_ai_description_queue_rls_policy.sql Remove policy permissiva e cria conjunto de policies RLS mais restritivas para a fila de IA.
.github/workflows/quality-gate.yml Corrige workflow quebrado (mojibake/base64) e adiciona gate de drift de types do Supabase.
.env.example Alinha variável de anon key com padrão Supabase e mantém alias legado documentado.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +19 to +26
-- SELECT: usuário vê apenas suas próprias filas, admins veem tudo
CREATE POLICY "ai_queue_read_own_or_admin"
ON ai_description_queue
FOR SELECT
USING (
auth.uid() = requested_by
OR is_admin_or_above(auth.uid())
);
Comment on lines +28 to +34
-- INSERT: usuário pode inserir somente como ele mesmo
CREATE POLICY "ai_queue_insert_own"
ON ai_description_queue
FOR INSERT
WITH CHECK (
auth.uid() = requested_by
);
Comment on lines +36 to +45
-- UPDATE: somente admins podem atualizar status de fila
CREATE POLICY "ai_queue_update_admin_only"
ON ai_description_queue
FOR UPDATE
USING (
is_admin_or_above(auth.uid())
)
WITH CHECK (
is_admin_or_above(auth.uid())
);
Comment on lines +47 to +53
-- DELETE: somente admins podem remover entradas de fila
CREATE POLICY "ai_queue_delete_admin_only"
ON ai_description_queue
FOR DELETE
USING (
is_admin_or_above(auth.uid())
);
Comment on lines +102 to +121
- name: Generate Supabase types
id: gen_types
run: |
npx supabase gen types typescript \
--project-id doufsxqlfjyuvxuezpln \
> /tmp/supabase-types-fresh.ts
env:
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
continue-on-error: true

- name: Check for type drift
if: steps.gen_types.outcome == 'success'
run: |
if ! diff -q src/integrations/supabase/types.ts /tmp/supabase-types-fresh.ts > /dev/null 2>&1; then
echo "::warning::Supabase types are out of sync with the database schema!"
echo "::warning::Run: npx supabase gen types typescript --project-id doufsxqlfjyuvxuezpln > src/integrations/supabase/types.ts"
diff src/integrations/supabase/types.ts /tmp/supabase-types-fresh.ts | head -50
else
echo "Types are in sync ✅"
fi
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.

2 participants