Skip to content

fix(security): escape org_id parameter in admin stats SQL queries#1730

Closed
artylobos wants to merge 1 commit intoCap-go:mainfrom
artylobos:fix/admin-stats-sql-escape
Closed

fix(security): escape org_id parameter in admin stats SQL queries#1730
artylobos wants to merge 1 commit intoCap-go:mainfrom
artylobos:fix/admin-stats-sql-escape

Conversation

@artylobos
Copy link
Contributor

@artylobos artylobos commented Mar 1, 2026

Summary

Two locations in cloudflare.ts were interpolating org_id directly into SQL queries without using escapeSqlString().

Affected Functions

  • getAdminPlatformOverview() (line 1452)
  • getAdminMauTrend() (line 1634)

Security Impact

While these are admin-only endpoints, defense-in-depth requires consistent escaping of all user-controllable parameters. A malicious admin or compromised admin session could potentially exploit this.

Changes

  • Use escapeSqlString(org_id) for consistent SQL injection prevention

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced security in admin analytics queries by implementing proper string escaping for organization identifiers.

Two locations in cloudflare.ts were interpolating org_id directly into
SQL queries without using escapeSqlString(), allowing potential SQL
injection in getAdminPlatformOverview and getAdminMauTrend functions.

These are admin-only endpoints but defense-in-depth requires consistent
escaping of all user-controllable parameters.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4f047bc and 96767bd.

📒 Files selected for processing (1)
  • supabase/functions/_backend/utils/cloudflare.ts

📝 Walkthrough

Walkthrough

The pull request adds SQL string escaping to two admin analytics queries in the Cloudflare utilities module. The org_id parameter in getAdminPlatformOverview and getAdminMauTrend functions is now wrapped with escapeSqlString to prevent SQL injection vulnerabilities through secure parameterization.

Changes

Cohort / File(s) Summary
SQL Injection Prevention
supabase/functions/_backend/utils/cloudflare.ts
Added escapeSqlString wrapper around org_id values in two admin analytics queries (getAdminPlatformOverview and getAdminMauTrend) to safely escape SQL string interpolation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested labels

🙋 Bounty claim

Poem

🐰 A rabbit hops through SQL land,
Escaping strings with careful hand,
No injections shall pass this way,
Security wins the day! 🛡️

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: escaping org_id parameters in admin stats SQL queries for security purposes.
Description check ✅ Passed The description covers the Summary, Affected Functions, and Security Impact sections well, but omits the Test plan, Screenshots, and Checklist sections required by the template.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 1, 2026

@riderx
Copy link
Member

riderx commented Mar 3, 2026

do not make security fix on PR use proper security disclosure

@riderx riderx closed this Mar 3, 2026
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