fix(cli): prevent SQL injection into platform Supabase via package.json name - #460
Open
0xcucumbersalad wants to merge 1 commit into
Open
fix(cli): prevent SQL injection into platform Supabase via package.json name#4600xcucumbersalad wants to merge 1 commit into
0xcucumbersalad wants to merge 1 commit into
Conversation
…on name provisionAnalytics() in migrate.ts read `name` from the migrated repo's package.json and interpolated it, unescaped, into a single-quoted SQL literal sent to the decocms Supabase Management API `/database/query` endpoint (raw SQL, no bound parameters) against the central `public.sites` table that tracks every site. A crafted name such as "name": "x'; UPDATE public.sites SET metadata=...::jsonb WHERE name='victim'; --" broke out of the literal and ran arbitrary SQL cross-tenant on the platform DB (runs whenever an operator migrates the repo with SUPABASE_ACCESS_TOKEN set). Fix (new migrate/sql-safety.ts): - isValidNpmPackageName() — reject any name that is not a valid npm package name before it can reach the query; provisioning is skipped for invalid names. The grammar forbids quotes, `;`, spaces, newlines. - escapeSqlLiteral() — SQL-standard quote doubling, applied to both the executed query and the printAnalyticsSQL manual-run output as defense-in-depth. Adds migrate/sql-safety.test.ts covering valid names, injection payloads, non-string input, and quote-escaping. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Aug 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
provisionAnalytics()inmigrate.tsreadnamefrom the migrated repo'spackage.jsonand interpolated it, unescaped, into a single-quoted SQL literal sent to the decocms Supabase Management API/database/queryendpoint:That endpoint runs raw SQL (no bound parameters), against the central
public.sitestable that holds a row for every site.Impact
SQL injection on the platform database, cross-tenant. A crafted
package.json:{ "name": "x'; UPDATE public.sites SET metadata = metadata || '{\"pwn\":1}'::jsonb WHERE name='victim-store'; --" }produces:
The
'closes the literal,;starts a new statement,--comments the tail — attacker's repo rewrites/reads another tenant's row. Runs whenever an operator migrates the repo withSUPABASE_ACCESS_TOKENset.Fix
New
migrate/sql-safety.ts:isValidNpmPackageName()— reject anynamethat isn't a valid npm package name before it can reach the query; provisioning is skipped for invalid names. The grammar forbids',;, spaces, newlines — everything needed for breakout.escapeSqlLiteral()— SQL-standard single-quote doubling, applied to both the executed query and theprintAnalyticsSQLmanual-run output, as defense-in-depth.Both applied in
provisionAnalytics(). A valid name path is byte-for-byte unchanged; only malicious/invalid names are blocked.Tests
New
migrate/sql-safety.test.ts(6 tests, passing): valid names accepted; injection payloads / uppercase / spaces / newlines / over-length / empty rejected; non-string input rejected; quote-doubling verified, including the full breakout string neutralized inside a single-quoted literal.Scope
Finding F4 from the source audit. Companion PRs: #459 (F5, git-clone command injection) and the F6 codegen-injection PR. Same class — untrusted input reaching a raw sink (SQL / shell / generated code) without escaping.
🤖 Generated with Claude Code
Summary by cubic
Fixes a SQL injection in the CLI migrator by validating and escaping the repo
package.jsonnamebefore using it in raw SQL against the platform Supabase. Prevents cross-tenant writes via crafted package names and makes the manual SQL output safe.isValidNpmPackageName()to reject invalid/malicious names; skip analytics provisioning when invalid.escapeSqlLiteral()and applied it to both the executed query andprintAnalyticsSQLoutput.sql-safety.test.tscovering valid names, injection payloads, non-string input, length, and quote-doubling.Written for commit aa34a6d. Summary will update on new commits.