Go: database local source models#17905
Conversation
database local source models
Click to show differences in coveragegoGenerated file changes for go
- `Bun <https://bun.uptrace.dev/>`_,``github.com/uptrace/bun*``,,,63
+ `Bun <https://bun.uptrace.dev/>`_,``github.com/uptrace/bun*``,18,,63
- `Couchbase official client(gocb) <https://github.com/couchbase/gocb>`_,"``github.com/couchbase/gocb*``, ``gopkg.in/couchbase/gocb*``",,36,16
+ `Couchbase official client(gocb) <https://github.com/couchbase/gocb>`_,"``github.com/couchbase/gocb*``, ``gopkg.in/couchbase/gocb*``",44,98,16
- `Couchbase unofficial client <http://www.github.com/couchbase/go-couchbase>`_,``github.com/couchbaselabs/gocb*``,,18,8
+ `Couchbase unofficial client <http://www.github.com/couchbase/go-couchbase>`_,``github.com/couchbaselabs/gocb*``,22,49,8
- `GoFrame <https://goframe.org/en/>`_,``github.com/gogf/gf*``,,,51
+ `GoFrame <https://goframe.org/en/>`_,``github.com/gogf/gf*``,12,30,51
- `Squirrel <https://github.com/Masterminds/squirrel>`_,"``github.com/Masterminds/squirrel*``, ``github.com/lann/squirrel*``, ``gopkg.in/Masterminds/squirrel``",,,96
+ `Squirrel <https://github.com/Masterminds/squirrel>`_,"``github.com/Masterminds/squirrel*``, ``github.com/lann/squirrel*``, ``gopkg.in/Masterminds/squirrel``",84,,96
- Totals,,494,958,1556
+ Totals,,674,1081,1556
- github.com/Masterminds/squirrel,32,,,,,,,,,,,,,,32,,,,,,,,,,,,
+ github.com/Masterminds/squirrel,32,28,,,,,,,,,,,,,32,,,,,,28,,,,,,
- github.com/couchbase/gocb,8,,18,,,,,8,,,,,,,,,,,,,,,,,,18,
+ github.com/couchbase/gocb,8,22,49,,,,,8,,,,,,,,,,,,,22,,,,,49,
- github.com/couchbaselabs/gocb,8,,18,,,,,8,,,,,,,,,,,,,,,,,,18,
+ github.com/couchbaselabs/gocb,8,22,49,,,,,8,,,,,,,,,,,,,22,,,,,49,
- github.com/gogf/gf/database/gdb,51,,,,,,,,,,,,,,51,,,,,,,,,,,,
+ github.com/gogf/gf/database/gdb,51,12,30,,,,,,,,,,,,51,,,,,,12,,,,,30,
- github.com/lann/squirrel,32,,,,,,,,,,,,,,32,,,,,,,,,,,,
+ github.com/lann/squirrel,32,28,,,,,,,,,,,,,32,,,,,,28,,,,,,
- github.com/uptrace/bun,63,,,,,,,,,,,,,,63,,,,,,,,,,,,
+ github.com/uptrace/bun,63,18,,,,,,,,,,,,,63,,,,,,18,,,,,,
- gopkg.in/Masterminds/squirrel,32,,,,,,,,,,,,,,32,,,,,,,,,,,,
+ gopkg.in/Masterminds/squirrel,32,28,,,,,,,,,,,,,32,,,,,,28,,,,,,
- gopkg.in/couchbase/gocb,8,,18,,,,,8,,,,,,,,,,,,,,,,,,18,
+ gopkg.in/couchbase/gocb,8,22,49,,,,,8,,,,,,,,,,,,,22,,,,,49, |
|
Two tests need to have their results updated. I haven't had time to look at the models themselves yet. Are these new models, or are you converting models from QL? If the latter, should we also delete the QL models? |
95ebab7 to
006f91b
Compare
Yes these are primarily new models. There weren't many existing database models as far as I could tell. The one package where I'm unsure about the existing models vs the new ones are the beego-orm models. The discrepancy seems to be from API changes in v2 |
owen-mc
left a comment
There was a problem hiding this comment.
I've only reviewed half of the new models so far (stdlib, beego, couchbase).
I note that we do have some existing database read models - see the source definition for the stored xss query. We should convert them to MaD, deprecate the QL classes where they are only used for that, and use the database MaD sources for that query (ignoring what the active threat model is, I think).
Extremely minor stylistic comment: within one .model.yml file I prefer to put sources first, sinks second and summaries third. This is because there are generally the fewest sources, the second fewest sinks and the most summaries. It makes it slightly easier to read and see at a glance which extensible predicates are being extended. When summaries go first, it is easy to miss that other predicates are extended below.
There was a problem hiding this comment.
- Please test for all sources defined in each package.
- That will probably make the file a bit longer - I would split this up into a separate source file for each package, so it is easier to find particular tests.
go/ql/lib/ext/ghproxy-9d2.pages.dev.beego.beego.client.orm.model.yml
Outdated
Show resolved
Hide resolved
| - ["group:gocb2", "QueryResult", True, "One", "", "", "Argument[0]", "database", "manual"] | ||
| - ["group:gocb2", "QueryResult", True, "Row", "", "", "Argument[0]", "database", "manual"] |
There was a problem hiding this comment.
I think it would make more sense to model Cluster.Query and Scope.Query (which are the only way of getting a QueryResult) as the sources and model the two methods above as summary models. There is a nice symmetry that the same function is an sql-injection sink for one argument and a database source for the return value.
Also, add summary models for QueryResult.Raw and QueryResultRaw.NextBytes.
There was a problem hiding this comment.
I also think that Cluster.AnalyticsQuery and Scope.AnalyticsQuery should be sources, and all the summary models for QueryResult should be duplicated for AnalyticsResult.
| - ["group:gocb2", "TransactionQueryResult", True, "One", "", "", "Argument[0]", "database", "manual"] | ||
| - ["group:gocb2", "TransactionQueryResult", True, "Row", "", "", "Argument[0]", "database", "manual"] |
There was a problem hiding this comment.
Same as above, I think TransactionAttemptContext.Query should be the source and these should be summary models. (It should probably be an sql-injection sink as well - I've noted this down somewhere else, no need to do it in this PR.)
| - ["group:gocb2", "Collection", True, "GetAndLock", "", "", "ReturnValue[0]", "database", "manual"] | ||
| - ["group:gocb2", "Collection", True, "GetAndTouch", "", "", "ReturnValue[0]", "database", "manual"] | ||
| - ["group:gocb2", "Collection", True, "GetAnyReplica", "", "", "ReturnValue[0]", "database", "manual"] | ||
| - ["group:gocb2", "Collection", True, "LookupIn", "", "", "ReturnValue[0]", "database", "manual"] |
There was a problem hiding this comment.
Presumably we should model LookupInAllReplicas and LookupInAnyReplica as sources, and a summary model for LookupInAllReplicasResult.Next.
| - ["group:gocb2", "Collection", True, "GetAndTouch", "", "", "ReturnValue[0]", "database", "manual"] | ||
| - ["group:gocb2", "Collection", True, "GetAnyReplica", "", "", "ReturnValue[0]", "database", "manual"] | ||
| - ["group:gocb2", "Collection", True, "LookupIn", "", "", "ReturnValue[0]", "database", "manual"] | ||
| - ["group:gocb2", "Collection", True, "Scan", "", "", "ReturnValue[0]", "database", "manual"] |
There was a problem hiding this comment.
We also need a summary model for ScanResultItem.Content
owen-mc
left a comment
There was a problem hiding this comment.
I've done another four libraries. jmoiron/sqlx was such hard going!
go/ql/lib/ext/ghproxy-9d2.pages.dev.gogf.gf.database.gdb.model.yml
Outdated
Show resolved
Hide resolved
go/ql/lib/ext/ghproxy-9d2.pages.dev.gogf.gf.database.gdb.model.yml
Outdated
Show resolved
Hide resolved
go/ql/lib/ext/ghproxy-9d2.pages.dev.gogf.gf.database.gdb.model.yml
Outdated
Show resolved
Hide resolved
go/ql/lib/ext/ghproxy-9d2.pages.dev.gogf.gf.database.gdb.model.yml
Outdated
Show resolved
Hide resolved
| - ["github.com/gogf/gf/database/gdb", "Model", True, "FindOne", "", "", "Argument[receiver]", "ReturnValue[0]", "taint", "manual"] | ||
| - ["github.com/gogf/gf/database/gdb", "Model", True, "FindValue", "", "", "Argument[receiver]", "ReturnValue[0]", "taint", "manual"] | ||
| - ["github.com/gogf/gf/database/gdb", "Model", True, "FindScan", "", "", "Argument[receiver]", "Argument[0]", "taint", "manual"] | ||
| - ["github.com/gogf/gf/database/gdb", "Model", True, "One", "", "", "Argument[receiver]", "ReturnValue[0]", "taint", "manual"] |
There was a problem hiding this comment.
Also want models for methods Scan, ScanList, Select, Struct and Structs on Model.
There was a problem hiding this comment.
Also, most of these methods on Model return a Model, which we aren't modelling at the moment. It would mean a huge number of models though. But without that, the examples they give, like db.Model("user").Where("id", 1).Scan(&user) , won't get the taint tracked through it properly. I'm not sure what to do here, to be honest.
go/ql/lib/ext/ghproxy-9d2.pages.dev.kanikanema.gorqlite.model.yml
Outdated
Show resolved
Hide resolved
go/ql/lib/ext/ghproxy-9d2.pages.dev.kanikanema.gorqlite.model.yml
Outdated
Show resolved
Hide resolved
go/ql/lib/ext/ghproxy-9d2.pages.dev.kanikanema.gorqlite.model.yml
Outdated
Show resolved
Hide resolved
go/ql/lib/ext/ghproxy-9d2.pages.dev.mastermind.squirrel.model.yml
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Also needs models for QueryContextWith, QueryWith, QueryRowContextWith, QueryRowWith, Row.Scan (it seems to override the inherited Scan method from embedding RowScanner), *Builder.Query (different method signature to QueryRower.Query, unfortunately), *Builder.QueryContext, *Builder.QueryRow, *Builder.QueryRowContext, *Builder.Scan, *Builder.ScanContext. (Do we care about all the Builders? Delete? I guess safest to model them all...)
owen-mc
left a comment
There was a problem hiding this comment.
I've finished going through all the libraries. Modeling is such hard work! Thanks for doing all this - it must have taken a long time.
| - ["github.com/uptrace/bun", "DeleteQuery", True, "Scan", "", "", "Argument[0]", "database", "manual"] | ||
| - ["github.com/uptrace/bun", "InsertQuery", True, "Scan", "", "", "Argument[0]", "database", "manual"] | ||
| - ["github.com/uptrace/bun", "MergeQuery", True, "Scan", "", "", "Argument[0]", "database", "manual"] | ||
| - ["github.com/uptrace/bun", "RawQuery", True, "Scan", "", "", "Argument[0]", "database", "manual"] | ||
| - ["github.com/uptrace/bun", "SelectQuery", True, "Scan", "", "", "Argument[0]", "database", "manual"] | ||
| - ["github.com/uptrace/bun", "TruncateQuery", True, "Scan", "", "", "Argument[0]", "database", "manual"] | ||
| - ["github.com/uptrace/bun", "UpdateQuery", True, "Scan", "", "", "Argument[0]", "database", "manual"] |
There was a problem hiding this comment.
If I remember correctly, this model won't work because dataflow out of a variadic parameter doesn't work currently. It can be modeled in QL.
There was a problem hiding this comment.
These docs make me think we need source models for DB.Query* and summary models for DB.ScanRow and DB.ScanRows.
16c84f7 to
bf8bed4
Compare
7b3faab to
eacb8a8
Compare
e52e438 to
4ef3d31
Compare
2c27c88 to
00b8a86
Compare
Co-authored-by: Owen Mansel-Chan <62447351+owen-mc@users.noreply.github.com>
Remove already-merged packages from change note
00b8a86 to
4a79a89
Compare
|
Superseded by #19203. |
Pull Request checklist
All query authors
.qhelp. See the documentation in this repository.Internal query authors only
.ql,.qll, or.qhelpfiles. See the documentation (internal access required).