-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 8 commits
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-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
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
go/ql/lib/change-notes/2025-03-27-database-local-source-models.md
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,4 @@ | ||
| --- | ||
| category: minorAnalysis | ||
| --- | ||
| * Local source models for APIs reading from databases have been added for `github.com/gogf/gf/database/gdb` and `github.com/uptrace/bun`. |
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
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 | ||
| // } | ||
| // } | ||
| } | ||
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
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
Oops, something went wrong.
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.