snapshot of https://github.com/mattermost/mattermost.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Nightly Race / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 1s
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Nightly Race / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 1s
This commit is contained in:
59
tools/mattermost-govet/rawSql/rawSql.go
Normal file
59
tools/mattermost-govet/rawSql/rawSql.go
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package rawSql
|
||||
|
||||
import (
|
||||
"go/ast"
|
||||
"go/token"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost/tools/mattermost-govet/util"
|
||||
"golang.org/x/tools/go/analysis"
|
||||
)
|
||||
|
||||
const (
|
||||
sqlstorePackagePath = util.ServerModulePath + "/channels/store/sqlstore"
|
||||
)
|
||||
|
||||
var Analyzer = &analysis.Analyzer{
|
||||
Name: "rawSql",
|
||||
Doc: "check invalid usage of raw SQL queries instead of using the squirrel lib",
|
||||
Run: run,
|
||||
}
|
||||
|
||||
func run(pass *analysis.Pass) (interface{}, error) {
|
||||
if !strings.HasPrefix(pass.Pkg.Path(), sqlstorePackagePath) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
for _, file := range pass.Files {
|
||||
ast.Inspect(file, func(node ast.Node) bool {
|
||||
switch n := node.(type) {
|
||||
case *ast.BasicLit:
|
||||
if n.Kind != token.STRING {
|
||||
return false
|
||||
}
|
||||
|
||||
unquoted, err := strconv.Unquote(n.Value)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
words := strings.Fields(strings.TrimSpace(unquoted))
|
||||
if len(words) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
switch lead := strings.ToLower(words[0]); lead {
|
||||
case "select", "insert", "update":
|
||||
pass.Reportf(n.Pos(), "Found leading %q in a string. Creating raw SQL queries is not allowed, please use the squirrel builder instead.", lead)
|
||||
}
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
16
tools/mattermost-govet/rawSql/rawSql_test.go
Normal file
16
tools/mattermost-govet/rawSql/rawSql_test.go
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package rawSql
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"golang.org/x/tools/go/analysis/analysistest"
|
||||
)
|
||||
|
||||
func TestAll(t *testing.T) {
|
||||
// The analyzer only runs on the sqlstore package with full path
|
||||
testdata := analysistest.TestData()
|
||||
analysistest.Run(t, testdata, Analyzer, "github.com/mattermost/mattermost/server/v8/channels/store/sqlstore")
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package sqlstore
|
||||
|
||||
// Mock squirrel builder types
|
||||
type SelectBuilder struct{}
|
||||
type InsertBuilder struct{}
|
||||
type UpdateBuilder struct{}
|
||||
|
||||
func (s SelectBuilder) Where(pred interface{}, args ...interface{}) SelectBuilder { return s }
|
||||
func (s InsertBuilder) Values(values ...interface{}) InsertBuilder { return s }
|
||||
func (s UpdateBuilder) Set(column string, value interface{}) UpdateBuilder { return s }
|
||||
|
||||
func Select(columns ...string) SelectBuilder { return SelectBuilder{} }
|
||||
func Insert(into string) InsertBuilder { return InsertBuilder{} }
|
||||
func Update(table string) UpdateBuilder { return UpdateBuilder{} }
|
||||
|
||||
// Valid: Using squirrel builder
|
||||
func validUsingSquirrel() {
|
||||
// Valid: Using the squirrel builder for SELECT
|
||||
query := Select("*").Where("id = ?", 123)
|
||||
_ = query
|
||||
|
||||
// Valid: Using the squirrel builder for INSERT
|
||||
insert := Insert("users").Values("john", 30)
|
||||
_ = insert
|
||||
|
||||
// Valid: Using the squirrel builder for UPDATE
|
||||
update := Update("users").Set("name", "jane")
|
||||
_ = update
|
||||
|
||||
// Valid: SQL keywords in comments
|
||||
// SELECT * FROM users WHERE id = 1
|
||||
|
||||
// Valid: SQL keywords in variable names
|
||||
selectAll := true
|
||||
insertMode := false
|
||||
updateFlag := true
|
||||
_ = selectAll
|
||||
_ = insertMode
|
||||
_ = updateFlag
|
||||
}
|
||||
|
||||
// Invalid: Raw SQL queries
|
||||
func invalidRawSQLQueries() {
|
||||
// Invalid: Raw SELECT query
|
||||
query1 := "SELECT * FROM users WHERE id = ?" // want "Found leading \"select\" in a string"
|
||||
|
||||
// Invalid: Raw SELECT with different case
|
||||
query2 := "Select name FROM users" // want "Found leading \"select\" in a string"
|
||||
|
||||
// Invalid: Raw SELECT all caps
|
||||
query3 := "SELECT id, name FROM users" // want "Found leading \"select\" in a string"
|
||||
|
||||
// Invalid: Raw INSERT query
|
||||
query4 := "INSERT INTO users (name, age) VALUES (?, ?)" // want "Found leading \"insert\" in a string"
|
||||
|
||||
// Invalid: Raw INSERT with different case
|
||||
query5 := "Insert INTO users VALUES (?)" // want "Found leading \"insert\" in a string"
|
||||
|
||||
// Invalid: Raw UPDATE query
|
||||
query6 := "UPDATE users SET name = ? WHERE id = ?" // want "Found leading \"update\" in a string"
|
||||
|
||||
// Invalid: Raw UPDATE with different case
|
||||
query7 := "Update users SET status = 'active'" // want "Found leading \"update\" in a string"
|
||||
|
||||
// Invalid: Multi-line raw SQL
|
||||
query8 := /* want "Found leading \"select\" in a string" */ `SELECT
|
||||
id,
|
||||
name,
|
||||
email
|
||||
FROM users`
|
||||
|
||||
_ = query1
|
||||
_ = query2
|
||||
_ = query3
|
||||
_ = query4
|
||||
_ = query5
|
||||
_ = query6
|
||||
_ = query7
|
||||
_ = query8
|
||||
}
|
||||
|
||||
// Valid: Non-SQL strings
|
||||
func validNonSQLStrings() {
|
||||
// These should not trigger warnings - strings that don't start with SQL keywords
|
||||
msg1 := "Please choose your favorite color"
|
||||
msg2 := "Put the key into the lock"
|
||||
msg3 := "Change your profile settings"
|
||||
msg4 := "The button is blue"
|
||||
|
||||
_ = msg1
|
||||
_ = msg2
|
||||
_ = msg3
|
||||
_ = msg4
|
||||
}
|
||||
|
||||
// Invalid: SQL in function calls
|
||||
func invalidSQLInFunctionCalls() {
|
||||
executeQuery("SELECT * FROM posts") // want "Found leading \"select\" in a string"
|
||||
executeQuery("INSERT INTO posts VALUES (?)") // want "Found leading \"insert\" in a string"
|
||||
executeQuery("UPDATE posts SET content = ?") // want "Found leading \"update\" in a string"
|
||||
}
|
||||
|
||||
func executeQuery(query string) {
|
||||
_ = query
|
||||
}
|
||||
|
||||
// Valid: Empty strings and non-SQL content
|
||||
func validEdgeCases() {
|
||||
empty := ""
|
||||
whitespace := " "
|
||||
notSQL := "This is not SQL"
|
||||
deleteSQL := "DELETE FROM users" // DELETE is not checked
|
||||
|
||||
_ = empty
|
||||
_ = whitespace
|
||||
_ = notSQL
|
||||
_ = deleteSQL
|
||||
}
|
||||
Reference in New Issue
Block a user