Skip to content

[P1][security] SyncPreview USE ${targetDatabase} uses raw string concat — targetDatabase not escaped via escapeId #372

Closed

Description

@EVWorth

Context

Schema Compare & Sync generates USE database before applying the sync statements.

Problem

src/components/compare/SyncPreview.tsx:74 uses raw USE ${targetDatabase} interpolation — no escapeId call. Database names cannot legally contain backticks in MySQL, but the helper-name pattern matches userPrivileges.ts:62-64 (admin F16) and RoutineViewer (routine F1/F5). The escapeId helper at sync-sql-generator.ts:5-7 exists and is used in CREATE/DROP/ALTER statements in the same file — SyncPreview just doesn't use it. Refactor-prone: a future change that allows unusual names, or a database alias layer, would silently create SQLi.

Files

  • src/components/compare/SyncPreview.tsx:74

Repro (test-only)

Construct a SyncPreview with targetDatabase = "weird`name". The rendered SQL is USE weird\name` — invalid.

Expected

USE \weird``name`` and runs without error.

Proposed fix

Replace the raw interpolation with escapeId(targetDatabase) from sync-sql-generator.ts. Or extract to src/lib/sql-quote.ts exporting quoteDbName, quoteIdentifier, quoteLiteral and call at every IPC boundary (RoutineViewer F1/F5, Admin F16 all share this pattern). Scope: S.

Acceptance

A test with targetDatabase = "weird`name" produces USE \weird``name`` and runs without error.

Needs human verify

no (test-only)

Doc drift

no

Activity

  1. added
    audit
    severity/p1
    kind/security
    area/compare
    on Jul 31, 2026
  2. EVWorth commented on Sep 9, 2026

    @EVWorth
    OwnerAuthor

    Closed by removing the feature.

    Schema compare could not back the claim it made — foreign keys were absent from the snapshot entirely, DDL was compared after lowercasing and collapsing whitespace, and column order was ignored — while the sync half could leave a target half-migrated. A compare tool that is quietly wrong is worse than none, because people act on its answer.

    Fixing that properly is a real piece of work, most of it a genuine DDL comparison rather than string normalisation, and the feature is not part of how this project is used. Removed rather than carried: the history has it if someone wants it back.

    Removed in the PR closing this issue: SchemaCompare, SyncPreview, schema-diff, sync-sql-generator, their tests, the compare editor tab type, and the menu, title-bar and toolbar entry points.

  3. added a commit that references this issue on Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/compareauditkind/securityseverity/p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions