-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Go: Add database source models for uptrace/bun
and gogf/gf/database/gdb
#19203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
88b061e
Add change note
owen-mc 89e853b
Don't use non-existent dependency
owen-mc c54f0d8
[bun] Model github.com/uptrace/bun
egregius313 db65a6f
[gogf] Model github.com/gogf/gf/database/gdb
egregius313 9cf4117
Add tests for gogf/gf/database/gdb
egregius313 ddb7da4
Add gogf models and tests
owen-mc 1687042
Add Bun models and tests
owen-mc ecd09ed
Add stubs for gogf/gf and uptrace/bun
owen-mc 1ed8fbd
Delete commented out code
owen
8000
-mc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add Bun models and tests
- Loading branch information
commit 1687042c3be5d5a07e80c9465b0e4867cefb5ba8
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/** | ||
* Provides classes modeling security-relevant aspects of the `Bun` package. | ||
*/ | ||
|
||
import go | ||
|
||
/** | ||
* Provides classes modeling security-relevant aspects of the `Bun` package. | ||
*/ | ||
private module Bun { | ||
private string packagePath() { result = package("github.com/uptrace/bun", "") } | ||
|
||
private class RawQuerySources extends SourceNode { | ||
RawQuerySources() { | ||
// func (q *RawQuery) Exec(ctx context.Context, dest ...interface{}) (sql.Result, error) | ||
// func (q *RawQuery) Scan(ctx context.Context, dest ...interface{}) error | ||
exists(DataFlow::CallNode cn, int i | | ||
cn.getTarget().(Method).hasQualifiedName(packagePath(), "RawQuery", ["Exec", "Scan"]) and | ||
i >= 1 | ||
| | ||
this = cn.getSyntacticArgument(i) | ||
) | ||
} | ||
|
||
override string getThreatModel() { result = "database" } | ||
} | ||
|
||
private class SelectQuerySources extends SourceNode { | ||
SelectQuerySources() { | ||
// func (q *SelectQuery) Exec(ctx context.Context, dest ...interface{}) (res sql.Result, err error) | ||
// func (q *SelectQuery) Scan(ctx context.Context, dest ...interface{}) error | ||
// func (q *SelectQuery) ScanAndCount(ctx context.Context, dest ...interface{}) (int, error) | ||
exists(DataFlow::CallNode cn, int i | | ||
cn.getTarget() | ||
.(Method) | ||
.hasQualifiedName(packagePath(), "SelectQuery", ["Exec", "Scan", "ScanAndCount"]) and | ||
i >= 1 | ||
| | ||
this = cn.getSyntacticArgument(i) | ||
) | ||
} | ||
|
||
override string getThreatModel() { result = "database" } | ||
} | ||
|
||
private class DBScanRows extends TaintTracking::FunctionModel, Method { | ||
FunctionInput inp; | ||
FunctionOutput outp; | ||
|
||
DBScanRows() { | ||
// func (db *DB) ScanRow(ctx context.Context, rows *sql.Rows, dest ...interface{}) error | ||
// func (db *DB) ScanRows(ctx context.Context, rows *sql.Rows, dest ...interface{}) error | ||
this.hasQualifiedName(packagePath(), "DB", ["ScanRow", "ScanRows"]) and | ||
inp.isParameter(1) and | ||
outp.isParameter(any(int i | i >= 2)) | ||
} | ||
|
||
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) { | ||
input = inp and output = outp | ||
} | ||
} | ||
// private class BuilderScan extends TaintTracking::FunctionModel, Method { | ||
// FunctionInput inp; | ||
// FunctionOutput outp; | ||
// BuilderScan() { | ||
// // signature: func (b {Insert,Delete,Select,Update}Builder) Scan(dest ...interface{}) error | ||
// this.hasQualifiedName(packagePath(), | ||
// ["DeleteBuilder", "InsertBuilder", "SelectBuilder", "UpdateBuilder"], "Scan") and | ||
// inp.isReceiver() and | ||
// outp.isParameter(_) | ||
// } | ||
// override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) { | ||
// input = inp and output = outp | ||
// } | ||
// } | ||
// private class BuilderScanContext extends TaintTracking::FunctionModel, Method { | ||
// FunctionInput inp; | ||
// FunctionOutput outp; | ||
// BuilderScanContext() { | ||
// // signature: func (b {Insert,Delete,Select,Update}Builder) ScanContext(ctx context.Context, dest ...interface{}) error | ||
// this.hasQualifiedName(packagePath(), | ||
// ["DeleteBuilder", "InsertBuilder", "SelectBuilder", "UpdateBuilder"], "ScanContext") and | ||
// inp.isReceiver() and | ||
// exists(int i | i > 0 | outp.isParameter(i)) | ||
// } | ||
// override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) { | ||
// input = inp and output = outp | ||
// } | ||
// } | ||
} |
77 changes: 77 additions & 0 deletions
77
go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/database/test_uptrace_bun.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package test | ||
|
||
//go:generate depstubber -vendor github.com/uptrace/bun Conn,DB,RawQuery,SelectQuery,Tx | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/uptrace/bun" | ||
) | ||
|
||
func Test_bun_conn(conn bun.Conn) { | ||
ctx := context.Background() | ||
|
||
rows1, _ := conn.QueryContext(ctx, "SELECT * FROM users") // $ source | ||
conn.QueryRowContext(ctx, "SELECT * FROM users") // $ source | ||
|
||
ignore(rows1) | ||
} | ||
|
||
func Test_bun_db(db bun.DB) { | ||
ctx := context.Background() | ||
|
||
rows1, _ := db.Query("SELECT * FROM users") // $ source | ||
|
||
for rows1.Next() { | ||
var user User | ||
db.ScanRow(ctx, rows1, &user) | ||
sink(user) // $ hasTaintFlow="user" | ||
} | ||
|
||
rows2, _ := db.QueryContext(ctx, "SELECT * FROM users") // $ source | ||
var users []User | ||
|
||
db.ScanRows(ctx, rows2, &users) | ||
sink(users) // $ hasTaintFlow="users" | ||
|
||
db.QueryRow("SELECT * FROM users") // $ source | ||
db.QueryRowContext(ctx, "SELECT * FROM users") // $ source | ||
} | ||
|
||
func Test_bun_rawquery(q bun.RawQuery) { | ||
ctx := context.Background() | ||
|
||
var u1 []User | ||
q.Exec(ctx, &u1) // $ source | ||
var u2 []User | ||
q.Scan(ctx, &u2) // $ source | ||
} | ||
|
||
func Test_bun_selectquery(q bun.SelectQuery) { | ||
ctx := context.Background() | ||
|
||
rows, _ := q.Rows(ctx) // $ source | ||
var u1 []User | ||
q.Exec(ctx, &u1) // $ source | ||
var u2 []User | ||
q.Model(&u2).Scan(ctx) // $ source | ||
var u3 map[string]interface{} | ||
q.Scan(ctx, &u3) // $ source | ||
var u4 []User | ||
q.Model(&u4).ScanAndCount(ctx) // $ source | ||
var u5 map[string]interface{} | ||
q.ScanAndCount(ctx, &u5) // $ source | ||
|
||
ignore(rows) | ||
} | ||
|
||
func Test_bun_tx(tx bun.Tx) { | ||
ctx := context.Background() | ||
|
||
rows1, _ := tx.Query("SELECT * FROM users") // $ source | ||
rows2, _ := tx.QueryContext(ctx, "SELECT * FROM users") // $ source | ||
tx.QueryRow("SELECT * FROM users") // $ source | ||
tx.QueryRowContext(ctx, "SELECT * FROM users") // $ source | ||
|
||
ignore(rows1, rows2) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.