Feature request: Public API for MySQL executable comment (/*!...*/) recognition

Aperta
#397 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #398 di @fujiabao89 — chiusa senza merge

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
38/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
go, mysql

Direzione di ricerca

Inizia esaminando le API del lexer di mysql/parser, in particolare Lexer.NextToken(), Tokenize(), la funzione non esportata spliceGaps e le definizioni dei token descritte nell’issue. Riproduci i quattro esempi SQL e rivedi gli approcci proposti con i maintainer. Il lavoro è completato quando esiste un segnale pubblico, stabile e documentato che distingua i commenti realmente eseguibili dai commenti ordinari, dalle stringhe e dalle versioni non valide.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Background

WebDB P0-04 SQL safety policy requires dialect-AST-based classification for all SQL before execution (see ADR-007). MySQL executable comments (/*!NNNNN ... */) are a documented MySQL extension that can hide DDL/DML statements inside what appears to be a comment. String prefix or regex scanning is not an acceptable security boundary.

Current limitation (verified against v0.0.0-20260728103305-d2f82de1b468)

  • No exported ECM token type constant — all token type constants in mysql/parser are unexported (tok*/kw*)
  • spliceGaps field in lexer is unexported — ECM boundary information is inaccessible to API consumers
  • Lexer.NextToken() / Tokenize() produce normal keyword/literal tokens for ECM content — no way to distinguish ECM-originated tokens from regular SQL tokens
  • 0/12 true ECM positive cases recognized via public API in our Spike harness

Required API capability

A stable, public, documented mechanism to answer: "Does this SQL contain executable comments?"

The API must distinguish:

  1. Genuine MySQL executable comments (/*!NNNNN ... */)
  2. Ordinary block comments (/* ... */)
  3. /*!...*/ inside string literals (SELECT '/*!50000 harmless*/' AS str)
  4. Invalid or unknown version formats

Suggested implementations (non-exhaustive):

  • Export ECM token type constant and ensure Lexer.NextToken() emits it
  • Export spliceGaps as a public API
  • Add parser AST node/flag marking ECM-originated nodes

Regex, string prefix, or raw text scanning are NOT acceptable as SQL security boundaries.

Minimal reproduction

Using mysql/parser from v0.0.0-20260728103305-d2f82de1b468:

package main

import (
    "fmt"
    myparser "github.com/bytebase/omni/mysql/parser"
)

func main() {
    sqls := []string{
        "/*!50000 DROP TABLE t*/ SELECT 1",   // ECM with DDL
        "/*!99999 SELECT 1*/",                 // ECM with SELECT
        "SELECT /*!80100 42*/ FROM dual",      // ECM with expression
        "SELECT '/*!50000 harmless*/' AS str", // string literal
    }
    for _, sql := range sqls {
        lex := myparser.NewLexer(sql)
        fmt.Printf("SQL: %s\n", sql)
        for {
            tok := lex.NextToken()
            if tok.Type == 0 { break }
            // Is this token from an executable comment?
            // Currently no public API to determine this.
            fmt.Printf("  Token{Type=%d, Str=%q, Loc=%d, End=%d}\n",
                tok.Type, tok.Str, tok.Loc, tok.End)
        }
        fmt.Println()
    }
}

All ECM content tokens appear identical to normal SQL tokens.

Request

  • Confirm whether the maintainers consider this in scope
  • If accepted: commit to API stability and version compatibility guarantees for the exported ECM signal
  • We are prepared to submit a minimal PR if the approach is approved
  • The Spike evidence (0/12 ECM recognition via public API) is fully reproducible with the fixed version above
Lingua principale
Go
Stelle
20
Fork
8
Merge medio
6h 39m
PR unite (30g)
390

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di bytebase/omni

Tutte le issue di bytebase/omni

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.