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

未关闭
#397 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

  • #398 来自 @fujiabao89 —— 已关闭,未合并

评估

难度
5/5
预计耗时
一周以上
新手友好度
38/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
冷清
技术栈
go, mysql

调研方向

首先检查 mysql/parser 的 lexer API,尤其是 Lexer.NextToken()、Tokenize()、未导出的 spliceGaps,以及 issue 中描述的 token 定义。复现四个 SQL 示例,并与维护者一起审查提议的方案。完成的标准是:有一个经过文档说明的稳定公共信号,可以区分真正可执行的注释、普通注释、字符串和无效版本。

由索引模型根据 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 分钟
30 天内合并 PR
390

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

bytebase/omni 的其他 Issue

查看 bytebase/omni 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。