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

オープン
#397 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

  • #398 @fujiabao89 による — マージされずにクローズ

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
38/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
静か
技術スタック
go, mysql

調査の方向性

まず mysql/parser の lexer API、特に Lexer.NextToken()、Tokenize()、非公開の spliceGaps、および issue で説明されている token 定義を調査します。4 つの SQL 例を再現し、提案されているアプローチを maintainer と確認します。完了とは、本物の実行可能コメントを通常のコメント、文字列、無効なバージョンから区別できる、文書化された安定した公開シグナルが存在することを意味します。

索引モデルが issue の本文から書いたものです。

説明

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
主要言語
Go
スター
20
フォーク
8
平均マージ
6時間 39分
マージ済み PR(30日)
390

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

bytebase/omni のほかの issue

bytebase/omni の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。