Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: bump omni to the strict doris/starrocks parsers (BYT-10084/10085)
rebelice36cd0c8baa2d
diff --git a/backend/plugin/parser/doris/query.go b/backend/plugin/parser/doris/query.goindex b0c5a0c5a6..2cc0a94565 100644--- a/backend/plugin/parser/doris/query.go+++ b/backend/plugin/parser/doris/query.go@@ -63,6 +63,10 @@ func isReadOnlyAST(node ast.Node) bool {switch n := node.(type) {case *ast.SelectStmt, *ast.SetOpStmt:return true+ case *ast.GroupedQuery:+ // A repeated trailing clause group or a parenthesized WITH group —+ // (SELECT 1 LIMIT 1) LIMIT 2 — wraps a query; classify by the query.+ return isReadOnlyAST(n.Query)case *ast.ShowStmt:// Reject bare `SHOW` (Type is empty when the parser took the stub path// without seeing a recognised variant keyword).diff --git a/backend/plugin/parser/doris/query_span_fail_closed_test.go b/backend/plugin/parser/doris/query_span_fail_closed_test.gonew file mode 100644index 0000000000..5b48d54659--- /dev/null+++ b/backend/plugin/parser/doris/query_span_fail_closed_test.go@@ -0,0 +1,35 @@+package doris++import (+ "context"+ "testing"++ "github.com/stretchr/testify/require"++ "github.com/bytebase/bytebase/backend/plugin/parser/base"+)++// TestQuerySpanFailClosed pins the BYT-10085 contract at the bytebase layer:+// a statement the parser cannot fully consume must FAIL the span extraction,+// not return an empty span. Before strict parsing, "SELECT a FROM secret+// xx yy" silently truncated to "SELECT a FROM secret" upstream and variants+// with a junked FROM clause could yield zero AccessTables — masking and+// table-level ACL checks then saw nothing to protect.+func TestQuerySpanFailClosed(t *testing.T) {+ a := require.New(t)+ q := newQuerySpanExtractor("db1", base.GetQuerySpanContext{}, false)++ _, err := q.getQuerySpan(context.Background(), "SELECT a FROM secret xx yy zz")+ a.Error(err, "trailing junk must fail the span, not truncate silently")++ // The newly accepted paren/grouped shapes still extract their reads.+ span, err := q.getQuerySpan(context.Background(), "(SELECT a FROM secret) LIMIT 1")+ a.NoError(err)+ a.True(span.SourceColumns[base.ColumnResource{Database: "db1", Table: "secret"}],+ "paren query must report its table read")++ span, err = q.getQuerySpan(context.Background(), "(SELECT a FROM secret ORDER BY 1) ORDER BY 1")+ a.NoError(err)+ a.True(span.SourceColumns[base.ColumnResource{Database: "db1", Table: "secret"}],+ "grouped query must report its table read")+}diff --git a/backend/plugin/parser/doris/query_test.go b/backend/plugin/parser/doris/query_test.goindex 950bd75da2..e5735eeff0 100644--- a/backend/plugin/parser/doris/query_test.go+++ b/backend/plugin/parser/doris/query_test.go@@ -171,6 +171,31 @@ func TestValidateQuery(t *testing.T) {valid: true,description: "CONVERT and BINARY forms are read-only",},+ {+ statement: "(SELECT 1) LIMIT 1",+ valid: true,+ description: "Parenthesized query with trailing LIMIT is read-only",+ },+ {+ statement: "(SELECT 1 LIMIT 1) LIMIT 2",+ valid: true,+ description: "GroupedQuery wrapper (repeated clause groups) is read-only",+ },+ {+ statement: "SELECT 1 LIMIT 5 ORDER BY 1",+ valid: true,+ description: "Engine-lenient clause order wraps in GroupedQuery, still read-only",+ },+ {+ statement: "(WITH c AS (SELECT 1) SELECT * FROM c)",+ valid: true,+ description: "Parenthesized WITH group (CTE scope boundary) is read-only",+ },+ {+ statement: "SELECT 1 UNION (SELECT 2) LIMIT 5",+ valid: true,+ description: "Set operation with parenthesized operand and trailing LIMIT is read-only",+ },}for _, tc := range tests {@@ -229,6 +254,13 @@ func TestValidateQuery(t *testing.T) {statement: "EXPLAIN DROP TABLE t",description: "EXPLAIN over DDL must be rejected",},+ {+ // Strict parsing (BYT-10085): a valid prefix followed by junk no+ // longer silently truncates — it is a syntax error. Before the+ // fix this parsed as `SELECT a FROM t` and ran.+ statement: "SELECT a FROM t xx yy zz",+ description: "Trailing junk after a valid prefix must be rejected",+ },}for _, tc := range rejectCases {t.Run(tc.description, func(t *testing.T) {diff --git a/backend/plugin/parser/doris/query_type.go b/backend/plugin/parser/doris/query_type.goindex d7af361bae..4495086671 100644--- a/backend/plugin/parser/doris/query_type.go+++ b/backend/plugin/parser/doris/query_type.go@@ -77,6 +77,10 @@ func astQueryType(node ast.Node) (analysis.QueryType, bool) {switch n := node.(type) {case *ast.SelectStmt, *ast.SetOpStmt:return analysis.QueryTypeSelect, true+ case *ast.GroupedQuery:+ // A repeated trailing clause group or a parenthesized WITH group+ // wraps a query; classify by the wrapped query.+ return astQueryType(n.Query)case *ast.ShowStmt,*ast.ShowRoutineLoadStmt, *ast.ShowRoutineLoadTaskStmt,*ast.ShowJobStmt, *ast.ShowJobTaskStmt,diff --git a/backend/plugin/parser/doris/query_type_test.go b/backend/plugin/parser/doris/query_type_test.goindex 8cd0396e16..56b58ae6bc 100644--- a/backend/plugin/parser/doris/query_type_test.go+++ b/backend/plugin/parser/doris/query_type_test.go@@ -38,6 +38,18 @@ func TestGetQueryType(t *testing.T) {statement: "SHOW DATABASES",want: base.SelectInfoSchema,},+ {+ statement: "(SELECT * FROM users)",+ want: base.Select,+ },+ {+ statement: "(SELECT 1 LIMIT 1) LIMIT 2",+ want: base.Select,+ },+ {+ statement: "(SELECT * FROM users) ORDER BY 1 LIMIT 5",+ want: base.Select,+ },{statement: "SHOW TABLES",want: base.SelectInfoSchema,diff --git a/backend/plugin/parser/starrocks/query.go b/backend/plugin/parser/starrocks/query.goindex 5aa06e01c8..c7149b6026 100644--- a/backend/plugin/parser/starrocks/query.go+++ b/backend/plugin/parser/starrocks/query.go@@ -57,6 +57,10 @@ func isReadOnlyAST(node ast.Node) bool {return n.Into == nilcase *ast.SetOpStmt:return !setOpWritesOutfile(n)+ case *ast.ParenSelect:+ // (SELECT ...) at the top level — classify by the inner query so the+ // INTO OUTFILE gate still applies inside the parens.+ return isReadOnlyAST(n.Sel)case *ast.ShowStmt:// Reject bare `SHOW` (Type is empty when the parser took the stub path// without seeing a recognised variant keyword).@@ -102,6 +106,10 @@ func setOpWritesOutfile(node ast.Node) bool {return n.Into != nilcase *ast.SetOpStmt:return setOpWritesOutfile(n.Left) || setOpWritesOutfile(n.Right)+ case *ast.ParenSelect:+ // A parenthesized arm — SELECT 1 UNION (SELECT ... INTO OUTFILE ...) —+ // must not slip the export gate.+ return setOpWritesOutfile(n.Sel)default:return false}diff --git a/backend/plugin/parser/starrocks/query_span_fail_closed_test.go b/backend/plugin/parser/starrocks/query_span_fail_closed_test.gonew file mode 100644index 0000000000..6c992bf0d4--- /dev/null+++ b/backend/plugin/parser/starrocks/query_span_fail_closed_test.go@@ -0,0 +1,35 @@+package starrocks++import (+ "context"+ "testing"++ "github.com/stretchr/testify/require"++ "github.com/bytebase/bytebase/backend/plugin/parser/base"+)++// TestQuerySpanFailClosed pins the BYT-10085 contract at the bytebase layer:+// a statement the parser cannot fully consume must FAIL the span extraction,+// not return an empty span. Before strict parsing, "SELECT a FROM secret+// xx yy" silently truncated to "SELECT a FROM secret" upstream and variants+// with a junked FROM clause could yield zero AccessTables — masking and+// table-level ACL checks then saw nothing to protect.+func TestQuerySpanFailClosed(t *testing.T) {+ a := require.New(t)+ q := newQuerySpanExtractor("db1", base.GetQuerySpanContext{}, false)++ _, err := q.getQuerySpan(context.Background(), "SELECT a FROM secret xx yy zz")+ a.Error(err, "trailing junk must fail the span, not truncate silently")++ // The newly accepted paren/grouped shapes still extract their reads.+ span, err := q.getQuerySpan(context.Background(), "(SELECT a FROM secret) LIMIT 1")+ a.NoError(err)+ a.True(span.SourceColumns[base.ColumnResource{Database: "db1", Table: "secret"}],+ "paren query must report its table read")++ span, err = q.getQuerySpan(context.Background(), "(SELECT a FROM secret ORDER BY 1) ORDER BY 1")+ a.NoError(err)+ a.True(span.SourceColumns[base.ColumnResource{Database: "db1", Table: "secret"}],+ "grouped query must report its table read")+}diff --git a/backend/plugin/parser/starrocks/query_test.go b/backend/plugin/parser/starrocks/query_test.goindex e89a81ab54..9ea59f649d 100644--- a/backend/plugin/parser/starrocks/query_test.go+++ b/backend/plugin/parser/starrocks/query_test.go@@ -107,6 +107,31 @@ func TestValidateQuery(t *testing.T) {valid: true,description: "CTE-prefixed SELECT is read-only",},+ {+ statement: "((SELECT 1))",+ valid: true,+ description: "Nested parenthesized SELECT is read-only",+ },+ {+ statement: "(SELECT 1) LIMIT 5",+ valid: true,+ description: "Parenthesized SELECT with trailing LIMIT is read-only",+ },+ {+ statement: "(WITH c AS (SELECT 1) SELECT * FROM c)",+ valid: true,+ description: "Parenthesized WITH query is read-only",+ },+ {+ statement: `SELECT 1 UNION (SELECT a FROM t INTO OUTFILE "s3://b/x")`,+ valid: false,+ description: "INTO OUTFILE inside a parenthesized set-op arm must not slip the export gate",+ },+ {+ statement: `((SELECT a FROM t INTO OUTFILE "s3://b/x"))`,+ valid: false,+ description: "INTO OUTFILE inside nested parens must not slip the export gate",+ },{statement: "SELECT EXTRACT(YEAR FROM MONTHS_ADD(NOW(), -1))",valid: true,@@ -189,6 +214,9 @@ func TestValidateQuery(t *testing.T) {// Cases that must fail validation — either because they're not read-only// or because they don't parse. Both shapes flow through the same code// path and must be rejected (either via valid=false or err!=nil).+ //+ // The trailing-junk case pins strict parsing (BYT-10085): before the fix+ // "SELECT a FROM t xx yy zz" silently truncated to its valid prefix.rejectCases := []struct {statement stringdescription string@@ -233,6 +261,10 @@ func TestValidateQuery(t *testing.T) {statement: "EXPLAIN DROP TABLE t",description: "EXPLAIN over DDL must be rejected",},+ {+ statement: "SELECT a FROM t xx yy zz",+ description: "Trailing junk after a valid prefix must be rejected",+ },}for _, tc := range rejectCases {t.Run(tc.description, func(t *testing.T) {diff --git a/backend/plugin/parser/starrocks/query_type.go b/backend/plugin/parser/starrocks/query_type.goindex 297596a5d8..1e968513e8 100644--- a/backend/plugin/parser/starrocks/query_type.go+++ b/backend/plugin/parser/starrocks/query_type.go@@ -77,6 +77,10 @@ func astQueryType(node ast.Node) (analysis.QueryType, bool) {switch n := node.(type) {case *ast.SelectStmt, *ast.SetOpStmt:return analysis.QueryTypeSelect, true+ case *ast.ParenSelect:+ // (SELECT ...) at the top level wraps a query; classify by the+ // wrapped query.+ return astQueryType(n.Sel)case *ast.ShowStmt,*ast.ShowRoutineLoadStmt, *ast.ShowRoutineLoadTaskStmt,*ast.ShowJobStmt, *ast.ShowJobTaskStmt,diff --git a/backend/plugin/parser/starrocks/query_type_test.go b/backend/plugin/parser/starrocks/query_type_test.goindex 471083dd2a..3c038dc376 100644--- a/backend/plugin/parser/starrocks/query_type_test.go+++ b/backend/plugin/parser/starrocks/query_type_test.go@@ -34,6 +34,14 @@ func TestGetQueryType(t *testing.T) {statement: "CREATE TABLE test (id INT)",want: base.DDL,},+ {+ statement: "((SELECT * FROM users))",+ want: base.Select,+ },+ {+ statement: "(SELECT * FROM users) LIMIT 5",+ want: base.Select,+ },{statement: "SHOW DATABASES",want: base.SelectInfoSchema,diff --git a/backend/plugin/parser/starrocks/starrocks_test.go b/backend/plugin/parser/starrocks/starrocks_test.goindex 60e3b3881a..ac74c23472 100644--- a/backend/plugin/parser/starrocks/starrocks_test.go+++ b/backend/plugin/parser/starrocks/starrocks_test.go@@ -12,7 +12,12 @@ func TestStarRocksSQLParser(t *testing.T) {errorMessage string}{{- statement: "SELECT * FROM person LATERAL VIEW EXPLODE(ARRAY(30, 60)) tableName AS c_age;",+ // StarRocks has no Hive-style LATERAL VIEW (its lateral form is+ // `, [LATERAL] unnest(...)`) — container-verified engine reject.+ // The old parser only "accepted" this by silently truncating at+ // LATERAL (BYT-10085); strict parsing reports it like the engine.+ statement: "SELECT * FROM person LATERAL VIEW EXPLODE(ARRAY(30, 60)) tableName AS c_age;",+ errorMessage: "syntax error at or near LATERAL",},{statement: "SELECT * FROM schema1.t1 JOIN schema2.t2 ON t1.c1 = t2.c1",diff --git a/go.mod b/go.modindex d7f68cee3c..f4dcf75eec 100644--- a/go.mod+++ b/go.mod@@ -34,7 +34,7 @@ require (github.com/bmatcuk/doublestar/v4 v4.10.0github.com/bytebase/gomongo v0.0.0-20260730033313-67ba6e249735github.com/bytebase/lsp-protocol v0.0.0-20250324071136-1586d0c10ff0- github.com/bytebase/omni v0.0.0-20260820081141-f107d677cca3+ github.com/bytebase/omni v0.0.0-20260828034652-044f516d401cgithub.com/caarlos0/env/v11 v11.4.1github.com/cenkalti/backoff/v7 v7.0.0github.com/cockroachdb/cockroachdb-parser v0.25.2diff --git a/go.sum b/go.sumindex 3110d4c91b..27b07c2d09 100644--- a/go.sum+++ b/go.sum@@ -250,8 +250,8 @@ github.com/bytebase/gomongo v0.0.0-20260730033313-67ba6e249735 h1:v8y6mXeHmYVsdMgithub.com/bytebase/gomongo v0.0.0-20260730033313-67ba6e249735/go.mod h1:vTHjcvfn8Pmf65WjnV1ytTCYyC7xNhFjrniv4YWvtA8=github.com/bytebase/lsp-protocol v0.0.0-20250324071136-1586d0c10ff0 h1:bJ8NSf2K+pccl5m/wuu97fiYjDwpJH6IzURAq/3XA2U=github.com/bytebase/lsp-protocol v0.0.0-20250324071136-1586d0c10ff0/go.mod h1:BEWMfiZtqshdmulKJcIsWb45MUaEvDO4CROcgi8dfFg=-github.com/bytebase/omni v0.0.0-20260820081141-f107d677cca3 h1:gbpLT03nnD5xVfy22UzoxUMaN5ymmcXoYx3ghgYNNO8=-github.com/bytebase/omni v0.0.0-20260820081141-f107d677cca3/go.mod h1:Gp5RN3FM07f9/FFOTZCeu8duTAIMeuinkjjBCrs2Dw4=+github.com/bytebase/omni v0.0.0-20260828034652-044f516d401c h1:Plc8vW5rGPaqRXyn+oNt72HmLMaY7E6HWkFmeS7QmA0=+github.com/bytebase/omni v0.0.0-20260828034652-044f516d401c/go.mod h1:Gp5RN3FM07f9/FFOTZCeu8duTAIMeuinkjjBCrs2Dw4=github.com/bytebase/pgx/v5 v5.0.0-20250212161523-96ff8aed8767 h1:YuR5G3LcxpO5ScSTA+Kdirxg9RW4TRc/v1t7N2Hfmbw=github.com/bytebase/pgx/v5 v5.0.0-20250212161523-96ff8aed8767/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ=github.com/bytebase/pkcs8 v0.0.0-20240612095628-fcd0a7484c94 h1:6PNsuNmSqCuR8Z616uQLzDIvujWCFsKzeVc3ECmVubk=