Skip to content

Commit f3d979b

Browse files
author
Alvaro Muñoz
committed
Improve go-pg support
1 parent 656b4fc commit f3d979b

File tree

240 files changed

+28852
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

240 files changed

+28852
-2
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
lgtm,codescanning
2+
* Support for the pg-go framework has been improved.
3+

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,25 @@ module SQL {
145145
f.hasQualifiedName(gopgorm(), "Q") and
146146
arg = 0
147147
or
148-
exists(string tp, string m | f.(Method).hasQualifiedName(gopgorm(), tp, m) |
148+
exists(string tp, string m | f.(Method).hasQualifiedName([gopgorm(), gopg()], tp, m) |
149+
tp = ["DB", "Conn"] and
150+
m = ["QueryContext", "QueryOneContext"] and
151+
arg = 2
152+
or
153+
tp = ["DB", "Conn"] and
154+
m = ["ExecContext", "ExecOneContext", "PrepareContext", "Query", "QueryOne"] and
155+
arg = 1
156+
or
157+
tp = ["DB", "Conn"] and
158+
m = ["Exec", "ExecOne", "Prepare"] and
159+
arg = 0
160+
or
149161
tp = "Query" and
150-
m = ["ColumnExpr", "For", "Having", "Where", "WhereIn", "WhereInMulti", "WhereOr"] and
162+
m =
163+
[
164+
"ColumnExpr", "For", "GroupExpr", "Having", "Join", "OrderExpr", "TableExpr",
165+
"Where", "WhereIn", "WhereInMulti", "WhereOr"
166+
] and
151167
arg = 0
152168
or
153169
tp = "Query" and
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
| go-pg.go:37:22:37:30 | untrusted | github.com/go-pg/pg/v10 | Conn | ExecContext |
2+
| go-pg.go:37:22:37:30 | untrusted | github.com/go-pg/pg/v10 | DB | ExecContext |
3+
| go-pg.go:37:22:37:30 | untrusted | github.com/go-pg/pg/v10 | baseDB | ExecContext |
4+
| go-pg.go:38:45:38:53 | untrusted | github.com/go-pg/pg/v10 | Conn | QueryOneContext |
5+
| go-pg.go:38:45:38:53 | untrusted | github.com/go-pg/pg/v10 | DB | QueryOneContext |
6+
| go-pg.go:38:45:38:53 | untrusted | github.com/go-pg/pg/v10 | baseDB | QueryOneContext |
7+
| go-pg.go:42:14:42:22 | untrusted | github.com/go-pg/pg/v10/orm | Query | ColumnExpr |
8+
| go-pg.go:43:8:43:16 | untrusted | github.com/go-pg/pg/v10/orm | Query | Join |
9+
| go-pg.go:44:9:44:17 | untrusted | github.com/go-pg/pg/v10/orm | Query | Where |
10+
| go-pg.go:45:13:45:21 | untrusted | github.com/go-pg/pg/v10/orm | Query | OrderExpr |
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package main
2+
3+
import (
4+
"context"
5+
pg "github.com/go-pg/pg/v10"
6+
)
7+
8+
type Profile struct {
9+
ID int
10+
Lang string
11+
}
12+
13+
type User struct {
14+
ID int
15+
Name string
16+
ProfileID int
17+
Profile *Profile `pg:"-"`
18+
}
19+
20+
func getUntrustedString() string {
21+
return "trouble"
22+
}
23+
24+
func main() {
25+
26+
untrusted := getUntrustedString()
27+
28+
ctx := context.Background()
29+
db := pg.Connect(&pg.Options{
30+
Addr: ":5432",
31+
User: "user",
32+
Password: "pass",
33+
Database: "db_name",
34+
})
35+
36+
var version string
37+
db.ExecContext(ctx, untrusted)
38+
db.QueryOneContext(ctx, pg.Scan(&version), untrusted)
39+
40+
var user User
41+
db.Model(&user).
42+
ColumnExpr(untrusted).
43+
Join(untrusted).
44+
Where(untrusted, 123).
45+
OrderExpr(untrusted).
46+
Select()
47+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import go
2+
3+
from SQL::QueryString qs, Method meth, string a, string b, string c
4+
where meth.hasQualifiedName(a, b, c) and qs = meth.getACall().getSyntacticArgument(_)
5+
select qs, a, b, c
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module pwntester/go-pg
2+
3+
go 1.19
4+
5+
require (
6+
github.com/go-pg/pg/v10 v10.11.0 // indirect
7+
github.com/go-pg/zerochecker v0.2.0 // indirect
8+
github.com/jinzhu/inflection v1.0.0 // indirect
9+
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
10+
github.com/vmihailenco/bufpool v0.1.11 // indirect
11+
github.com/vmihailenco/msgpack/v5 v5.3.4 // indirect
12+
github.com/vmihailenco/tagparser v0.1.2 // indirect
13+
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
14+
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
15+
golang.org/x/sys v0.0.0-20210923061019-b8560ed6a9b7 // indirect
16+
mellium.im/sasl v0.3.1 // indirect
17+
)

go/ql/test/library-tests/semmle/go/frameworks/SQL/go-pg/vendor/github.com/go-pg/pg/v10/.golangci.yml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/ql/test/library-tests/semmle/go/frameworks/SQL/go-pg/vendor/github.com/go-pg/pg/v10/.prettierrc

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/ql/test/library-tests/semmle/go/frameworks/SQL/go-pg/vendor/github.com/go-pg/pg/v10/CHANGELOG.md

Lines changed: 220 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/ql/test/library-tests/semmle/go/frameworks/SQL/go-pg/vendor/github.com/go-pg/pg/v10/LICENSE

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)