forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request github#18493 from egregius313/egregius313/go/mad/d…
…atabase/mongodb Go: `database` local sources for MongoDB
- Loading branch information
Showing
6 changed files
with
650 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
--- | ||
category: minorAnalysis | ||
--- | ||
* Added `database` source models for database methods from the `go.mongodb.org/mongo-driver/mongo` package. | ||
|
This file contains 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 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
121 changes: 121 additions & 0 deletions
121
...st/library-tests/semmle/go/dataflow/flowsources/local/database/test_mongo_driver_mongo.go
This file contains 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,121 @@ | ||
package test | ||
|
||
//go:generate depstubber -vendor go.mongodb.org/mongo-driver/mongo Client,Collection,Database | ||
|
||
import ( | ||
"context" | ||
|
||
"go.mongodb.org/mongo-driver/mongo" | ||
) | ||
|
||
func test_mongo_driver_mongo_collection(coll *mongo.Collection, ctx context.Context, pipeline any) { | ||
cursor, err := coll.Aggregate(ctx, pipeline) // $ source | ||
if err != nil { | ||
return | ||
} | ||
|
||
var users []User | ||
|
||
err = cursor.All(ctx, &users) | ||
|
||
sink(users) // $ hasTaintFlow="users" | ||
|
||
distinct, err := coll.Distinct(ctx, "name", nil) // $ source | ||
if err != nil { | ||
return | ||
} | ||
|
||
sink(distinct) // $ hasTaintFlow="distinct" | ||
|
||
cursor2, err := coll.Find(ctx, nil) // $ source | ||
if err != nil { | ||
return | ||
} | ||
|
||
sink(cursor2) // $ hasTaintFlow="cursor2" | ||
|
||
var user1, user2, user3, user4 User | ||
|
||
single1 := coll.FindOne(ctx, nil) // $ source | ||
if err != nil { | ||
return | ||
} | ||
|
||
single1.Decode(&user1) | ||
|
||
sink(user1) // $ hasTaintFlow="user1" | ||
|
||
single2 := coll.FindOneAndDelete(ctx, nil) // $ source | ||
if err != nil { | ||
return | ||
} | ||
|
||
single2.Decode(&user2) | ||
|
||
sink(user2) // $ hasTaintFlow="user2" | ||
|
||
single3 := coll.FindOneAndReplace(ctx, nil, nil) // $ source | ||
if err != nil { | ||
return | ||
} | ||
|
||
single3.Decode(&user3) | ||
|
||
sink(user3) // $ hasTaintFlow="user3" | ||
|
||
single4 := coll.FindOneAndUpdate(ctx, nil, nil) // $ source | ||
if err != nil { | ||
return | ||
} | ||
|
||
single4.Decode(&user4) | ||
|
||
sink(user4) // $ hasTaintFlow="user4" | ||
|
||
changeStream, err := coll.Watch(ctx, pipeline) // $ source | ||
if err != nil { | ||
return | ||
} | ||
|
||
for changeStream.Next(ctx) { | ||
var userCs User | ||
changeStream.Decode(&userCs) | ||
sink(userCs) // $ hasTaintFlow="userCs" | ||
} | ||
} | ||
|
||
func test_mongo_driver_mongo_database(db *mongo.Database, ctx context.Context, pipeline any) { | ||
agg, err := db.Aggregate(ctx, pipeline) // $ source | ||
|
||
if err != nil { | ||
return | ||
} | ||
|
||
var user User | ||
agg.Decode(&user) | ||
sink(user) // $ hasTaintFlow="user" | ||
|
||
changeStream, err := db.Watch(ctx, pipeline) // $ source | ||
if err != nil { | ||
return | ||
} | ||
|
||
for changeStream.Next(ctx) { | ||
var userCs User | ||
changeStream.Decode(&userCs) | ||
sink(userCs) // $ hasTaintFlow="userCs" | ||
} | ||
} | ||
|
||
func test_mongo_driver_mongo_Client(client *mongo.Client, ctx context.Context) { | ||
changestream, err := client.Watch(ctx, nil) // $ source | ||
if err != nil { | ||
return | ||
} | ||
|
||
for changestream.Next(ctx) { | ||
var user User | ||
changestream.Decode(&user) | ||
sink(user) // $ hasTaintFlow="user" | ||
} | ||
} |
Oops, something went wrong.