Skip to content

Commit 59bb142

Browse files
committed
Revert "Convert Bun sql-injection sinks to MaD"
This reverts commit 3eb5b26.
1 parent ec59492 commit 59bb142

File tree

5 files changed

+64
-158
lines changed

5 files changed

+64
-158
lines changed

go/ql/lib/ext/github.com.uptrace.bun.model.yml

Lines changed: 0 additions & 68 deletions
This file was deleted.

go/ql/lib/semmle/go/frameworks/SQL.qll

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,45 @@ module Xorm {
167167
}
168168

169169
/**
170-
* DEPRECATED
171-
*
172170
* Provides classes for working with the [Bun](https://bun.uptrace.dev/) package.
173171
*/
174-
deprecated module Bun { }
172+
module Bun {
173+
/** Gets the package name for Bun package. */
174+
private string packagePath() { result = package("github.com/uptrace/bun", "") }
175+
176+
/** A model for sinks of Bun. */
177+
private class BunSink extends SQL::QueryString::Range {
178+
BunSink() {
179+
exists(Function f, string m, int arg | this = f.getACall().getArgument(arg) |
180+
f.hasQualifiedName(packagePath(), m) and
181+
m = "NewRawQuery" and
182+
arg = 1
183+
)
184+
or
185+
exists(Method f, string tp, string m, int arg | this = f.getACall().getArgument(arg) |
186+
f.hasQualifiedName(packagePath(), tp, m) and
187+
(
188+
tp = ["DB", "Conn"] and
189+
m = ["ExecContext", "PrepareContext", "QueryContext", "QueryRowContext"] and
190+
arg = 1
191+
or
192+
tp = ["DB", "Conn"] and
193+
m = ["Exec", "NewRaw", "Prepare", "Query", "QueryRow", "Raw"] and
194+
arg = 0
195+
or
196+
tp.matches("%Query") and
197+
m =
198+
[
199+
"ColumnExpr", "DistinctOn", "For", "GroupExpr", "Having", "ModelTableExpr",
200+
"OrderExpr", "TableExpr", "Where", "WhereOr"
201+
] and
202+
arg = 0
203+
or
204+
tp = "RawQuery" and
205+
m = "NewRaw" and
206+
arg = 0
207+
)
208+
)
209+
}
210+
}
211+
}

go/ql/test/library-tests/semmle/go/frameworks/SQL/bun/QueryString.expected

Lines changed: 0 additions & 3 deletions
This file was deleted.

go/ql/test/library-tests/semmle/go/frameworks/SQL/bun/QueryString.ql

Lines changed: 0 additions & 60 deletions
This file was deleted.

go/ql/test/library-tests/semmle/go/frameworks/SQL/bun/bun.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,28 @@ func main() {
2222
panic(err)
2323
}
2424
db := bun.NewDB(sqlite, sqlitedialect.New())
25-
bun.NewRawQuery(db, untrusted) // $ querystring=untrusted
26-
27-
db.ExecContext(ctx, untrusted) // $ querystring=untrusted
28-
db.PrepareContext(ctx, untrusted) // $ querystring=untrusted
29-
db.QueryContext(ctx, untrusted) // $ querystring=untrusted
30-
db.QueryRowContext(ctx, untrusted) // $ querystring=untrusted
31-
32-
db.Exec(untrusted) // $ querystring=untrusted
33-
db.NewRaw(untrusted) // $ querystring=untrusted
34-
db.Prepare(untrusted) // $ querystring=untrusted
35-
db.Query(untrusted) // $ querystring=untrusted
36-
db.QueryRow(untrusted) // $ querystring=untrusted
37-
db.Raw(untrusted) // $ querystring=untrusted
38-
39-
db.NewSelect().ColumnExpr(untrusted) // $ querystring=untrusted
40-
db.NewSelect().DistinctOn(untrusted) // $ querystring=untrusted
41-
db.NewSelect().For(untrusted) // $ querystring=untrusted
42-
db.NewSelect().GroupExpr(untrusted) // $ querystring=untrusted
43-
db.NewSelect().Having(untrusted) // $ querystring=untrusted
44-
db.NewSelect().ModelTableExpr(untrusted) // $ querystring=untrusted
45-
db.NewSelect().OrderExpr(untrusted) // $ querystring=untrusted
46-
db.NewSelect().TableExpr(untrusted) // $ querystring=untrusted
47-
db.NewSelect().Where(untrusted) // $ querystring=untrusted
48-
db.NewSelect().WhereOr(untrusted) // $ querystring=untrusted
25+
bun.NewRawQuery(db, untrusted)
26+
27+
db.ExecContext(ctx, untrusted)
28+
db.PrepareContext(ctx, untrusted)
29+
db.QueryContext(ctx, untrusted)
30+
db.QueryRowContext(ctx, untrusted)
31+
32+
db.Exec(untrusted)
33+
db.NewRaw(untrusted)
34+
db.Prepare(untrusted)
35+
db.Query(untrusted)
36+
db.QueryRow(untrusted)
37+
db.Raw(untrusted)
38+
39+
db.NewSelect().ColumnExpr(untrusted)
40+
db.NewSelect().DistinctOn(untrusted)
41+
db.NewSelect().For(untrusted)
42+
db.NewSelect().GroupExpr(untrusted)
43+
db.NewSelect().Having(untrusted)
44+
db.NewSelect().ModelTableExpr(untrusted)
45+
db.NewSelect().OrderExpr(untrusted)
46+
db.NewSelect().TableExpr(untrusted)
47+
db.NewSelect().Where(untrusted)
48+
db.NewSelect().WhereOr(untrusted)
4949
}

0 commit comments

Comments
 (0)