Skip to content

fix(edge): migrate inline CORS to buildPublicCorsHeaders helper (#126…#133

Closed
adm01-debug wants to merge 2 commits into
mainfrom
chore/pr126-cherry-pick
Closed

fix(edge): migrate inline CORS to buildPublicCorsHeaders helper (#126…#133
adm01-debug wants to merge 2 commits into
mainfrom
chore/pr126-cherry-pick

Conversation

@adm01-debug
Copy link
Copy Markdown
Owner

@adm01-debug adm01-debug commented May 23, 2026

… B-2)

Both edge functions declared corsHeaders inline (without x-request-id), violating the project's CORS gate (check:edge-cors + check:no-inline-cors).

Migration:

  • simulation-orchestrator: corsHeaders inline → buildPublicCorsHeaders()
  • sync-external-db: corsHeaders inline → buildPublicCorsHeaders()

This restores observability: x-request-id can now be cross-referenced between browser logs and Sentry/server logs across preflight.

Substitutes PR #126 B-2 (audit finding). Other items of #126:

Helper used (verified existing in main):

  • supabase/functions/_shared/cors.ts:204 exports buildPublicCorsHeaders()

📋 Descrição

🎯 Tipo de mudança

  • 🚀 feat — nova funcionalidade
  • 🐛 fix — correção de bug
  • ♻️ refactor — refatoração (sem mudança de comportamento)
  • 🔧 chore — manutenção, deps, config
  • 📚 docs — documentação
  • ⚡ perf — performance
  • 🔒 security — segurança
  • 🚨 hotfix — correção urgente em produção
  • 💥 breaking change — quebra compatibilidade

🔗 Issues relacionadas

Closes #
Refs #

🌐 Sistemas afetados

  • Bitrix24 (CRM, SPAs, BizProc)
  • Supabase (DB, Edge Functions, RLS, migrations)
  • n8n (workflows)
  • Evolution API / WhatsApp
  • Bling (NFe, OAuth)
  • Cloudflare (Workers, Images, Tunnels)
  • Frontend (UI, dashboards)
  • CI / GitHub Actions
  • Outro: ____

🧪 Como testar

✅ Checklist pré-merge

Qualidade

  • Código segue style guide (ESLint passa)
  • npx tsc --noEmit passa sem erros
  • Testes passam (npm run test)
  • Adicionei testes para novas funcionalidades quando aplicável
  • CodeRabbit revisou o PR (ou justificativa para skip)

Segurança

  • Sem secrets, tokens ou credenciais hardcoded
  • Variáveis de ambiente novas documentadas
  • Sem console.log com payloads sensíveis (usar logger.*)
  • RLS revisado se houve mudança em tabelas
  • Edge functions: input validado com Zod

Documentação

  • Atualizei docs (README / CHANGELOG / docs/) se necessário
  • Memória atualizada (mem://) se a mudança afetar arquitetura/regras
  • Migrations com backup em _backup_*_YYYYMMDD se destrutivas

UI

  • Componentes usam tokens semânticos (sem cores hardcoded)
  • Screenshots / vídeo anexados (se mudança visual)

📸 Screenshots (se UI)

🔄 Plano de rollback

⚠️ Notas para o reviewer


Summary by cubic

Migrated inline CORS in two edge functions to buildPublicCorsHeaders() to meet the CORS gate and include x-request-id. Added a forensic audit doc to track open issues and confirm critical fixes.

  • Bug Fixes
    • simulation-orchestrator and sync-external-db now use buildPublicCorsHeaders(); inline headers removed.
    • Preflight exposes x-request-id; passes check:edge-cors and check:no-inline-cors.
    • Added docs/AUDITORIA_BUGS_2026-05-23.md reconciling prior audits and listing open bugs and test gaps.

Written for commit af8cedb. Summary will update on new commits. Review in cubic

…B-2)

Both edge functions declared corsHeaders inline (without x-request-id),
violating the project's CORS gate (check:edge-cors + check:no-inline-cors).

Migration:
- simulation-orchestrator: corsHeaders inline → buildPublicCorsHeaders()
- sync-external-db: corsHeaders inline → buildPublicCorsHeaders()

This restores observability: x-request-id can now be cross-referenced
between browser logs and Sentry/server logs across preflight.

Substitutes PR #126 B-2 (audit finding). Other items of #126:
- B-1 validateUrlFormat: ✅ already merged via #124
- B-3 toast leaks: rejected (baseline 176→179 would be regression)
- useGlobalShortcuts hooks fix: ✅ already merged via #124
- T-FIX-3 GH Actions bump: ✅ already merged via #124
- AdminStandardRules PascalCase: ✅ already merged via #124

Helper used (verified existing in main):
- supabase/functions/_shared/cors.ts:204 exports buildPublicCorsHeaders()
Copilot AI review requested due to automatic review settings May 23, 2026 11:58
@vercel
Copy link
Copy Markdown

vercel Bot commented May 23, 2026

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

Project Deployment Actions Updated (UTC)
we-dream-big Ready Ready Preview, Comment May 23, 2026 12:03pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 23, 2026

Warning

Review limit reached

@adm01-debug, we couldn't start this review because you've used your available PR reviews for now.

Your plan currently allows 2 reviews/hour. Refill in 27 minutes and 14 seconds.

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

⌛ How to resolve this issue?

After more review capacity refills, 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 have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a6e7f4c9-7ff2-4769-a239-6577c519c66e

📥 Commits

Reviewing files that changed from the base of the PR and between 4c6bce2 and af8cedb.

📒 Files selected for processing (3)
  • docs/AUDITORIA_BUGS_2026-05-23.md
  • supabase/functions/simulation-orchestrator/index.ts
  • supabase/functions/sync-external-db/index.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/pr126-cherry-pick

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

@supabase
Copy link
Copy Markdown

supabase Bot commented May 23, 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 ↗︎.

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

This PR fixes the edge CORS compliance issue by migrating two Supabase Edge Functions away from inline corsHeaders objects to the shared _shared/cors.ts helper, restoring the expected x-request-id behavior and satisfying the repository’s edge CORS gates.

Changes:

  • Replaced inline corsHeaders in sync-external-db with buildPublicCorsHeaders().
  • Replaced inline corsHeaders in simulation-orchestrator with buildPublicCorsHeaders().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
supabase/functions/sync-external-db/index.ts Removes inline CORS header object and uses shared buildPublicCorsHeaders() helper.
supabase/functions/simulation-orchestrator/index.ts Removes inline CORS header object and uses shared buildPublicCorsHeaders() helper.

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

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

Re-trigger cubic

Adds AUDITORIA_BUGS_2026-05-23.md (922 lines) reconciling findings
from 4 prior audits against current code state. Different focus from
AUDITORIA-EXAUSTIVA-2026-05-23.md (#124, which is a 20-step plan) —
this one is a P0/P1 forensic inventory with 7-pass analysis.

Key findings documented:
- 13 critical security issues from prior audits: 13/13 CLOSED
- 9 currently-open bugs identified (B-1 through B-9)
- 103 it.skip in P0/E2E tests (test coverage gap)
- 1333 TS + 473 ESLint + 73 toast.error leaks in baselines
- 0 npm audit vulnerabilities

Resolution status of B-1 through B-3 in companion PRs:
- B-1 (validateUrlFormat): ✅ already fixed in #124
- B-2 (CORS inline simulation-orchestrator + sync-external-db):
  ✅ fixed in companion commit fa4ccc7 of this branch
- B-3 through B-9: documented for follow-up

Substitutes PR #126 docs delivery.
@vercel vercel Bot requested a deployment to Preview May 23, 2026 12:03 Abandoned
@adm01-debug adm01-debug deleted the chore/pr126-cherry-pick branch May 23, 2026 12:12
adm01-debug added a commit that referenced this pull request May 23, 2026
* fix(edge): migrate inline CORS to buildPublicCorsHeaders helper (#126 B-2)

Both edge functions declared corsHeaders inline (without x-request-id),
violating the project's CORS gate (check:edge-cors + check:no-inline-cors).

Migration:
- simulation-orchestrator: corsHeaders inline → buildPublicCorsHeaders()
- sync-external-db: corsHeaders inline → buildPublicCorsHeaders()

This restores observability: x-request-id can now be cross-referenced
between browser logs and Sentry/server logs across preflight.

Substitutes PR #126 B-2 finding. Other items of #126:
- B-1 validateUrlFormat: ✅ already merged via #124
- B-3 toast leaks: rejected (baseline 176→179 would be regression)
- useGlobalShortcuts hooks fix: ✅ already merged via #124
- T-FIX-3 GH Actions bump: ✅ already merged via #124
- AdminStandardRules PascalCase: ✅ already merged via #124

Helper used (verified existing in main):
- supabase/functions/_shared/cors.ts:204 exports buildPublicCorsHeaders()

* docs(audit): forensic bug audit reconciling 4 prior audits (#126)

Adds AUDITORIA_BUGS_2026-05-23.md reconciling findings from 4 prior
audits (2026-04-29, 05-07, 05-12, 05-13) against the current code state.

Different focus from AUDITORIA-EXAUSTIVA-2026-05-23.md (#124, which is a
20-step plan) — this one is a P0/P1 forensic inventory with 7-pass
analysis.

Key findings documented:
- 13 critical security issues from prior audits: 13/13 CLOSED
- 9 currently-open bugs identified (B-1 through B-9)
- 103 it.skip in P0/E2E tests (test coverage gap)
- 1333 TS + 473 ESLint + 73 toast.error leaks in baselines
- 0 npm audit vulnerabilities

Resolution status of B-1 through B-3:
- B-1 (validateUrlFormat): ✅ already fixed in #124
- B-2 (CORS inline simulation-orchestrator + sync-external-db):
  ✅ fixed in companion commit 507692b of this branch
- B-3 through B-9: documented for follow-up

Substitutes PR #126 docs delivery.

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Update docs/AUDITORIA_BUGS_2026-05-23.md

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
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