General issue Go. Why isn't the following code recognized as a source in a global data stream?
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 25/100
Rechercherichtung
Beginne damit, den Quelldatenfluss in router.go, controller.go, validator.go und param.go mit der standardmäßigen ActiveThreatModelSource in TainterPath.ql zu vergleichen. Reproduziere den Unterschied zwischen Quick Evaluation und TaintTracking::Global und untersuche anschließend die benutzerdefinierte GinContextGetSource-Abfrage sowie ihre Verweise auf val.Get, req und c. Als erledigt gilt die Aufgabe, wenn die beabsichtigte Quelle im globalen Datenfluss erkannt wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Why isn't the following code recognized as a source in a global data stream? If I want to identify this source in the global data stream, how should I write my QL?
Here's the code context:
//router.go
func RegisterServers(group *gin.RouterGroup) {
group.POST("/abc/test", val.Validate[*param.TestParam], controller.TestReadFile)
}
//controller.go
func TestReadFile(c *gin.Context) {
req := val.Get[*param.TestParam](c)
cleanPath := req.Path
file, err := os.Open(cleanPath)
if err != nil {
if os.IsNotExist(err) {
c.JSON(http.StatusNotFound, gin.H{"error": "file not found"})
} else {
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to open file"})
}
return
}
......
}
//validator.go
package val
func Validate[T any](ctx *gin.Context) {
var req T
if err := ctx.ShouldBindJSON(&req); err != nil {
ctx.JSON(http.StatusBadRequest, gin.H{"code": constant.UnknownErrorCode, "msg": util.GetErrorText(constant.UnknownErrorCode)})
ctx.Abort()
return
}
ctx.Set("params", req)
ctx.Next()
}
func Get[T any](ctx *gin.Context) T {
return ctx.MustGet("params").(T)
}
//param.go
package param
type TestParam struct {
Path string `json:"filepath"`
}
I found that the default "ActiveThreatModelSource" in the official rule "TainterPath.ql" is not recognizable as a source by the above code.
Here's the code I wrote to try to add a new class about this kind of source, and I use "req" from "req.Path" as the source, although the result can be recognized when "Quick Evaluation" is used, but when it is run in the whole "TaintTracking::Global", it cannot be recognized that there is a problem with this "controller.go".
class GinContextGetSource extends DataFlow::Node {
GinContextGetSource() {
exists(Function asmGet, CallExpr call |
asmGet.hasQualifiedName("project/router/val", "Get")
and call.getTarget() = asmGet
and call.getEnclosingFunction() = this.asExpr().getEnclosingFunction()
and this.asExpr().toString() = "req"
and this.asExpr().getEnclosingFunction().getAParameter().toString() = "c"
)
}
}
I need to address this issue urgently. Because the routing and controller parts of the entire Gin project that I am currently responsible for are developed in this form, the global data flow in each of my official rules cannot be identified in any of the sources
Thank you so much!
- Vorherrschende Sprache
- CodeQL
- Sterne
- 10.1k
- Forks
- 2.1k
- Ø Merge
- 2 T. 10 Std.
- Gemergte PRs (30 T.)
- 134
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus github/codeql
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
-
C#: cs/simplifiable-boolean-expression false positive on Nullable<bool> compared with a literal Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
false-positive
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
-
false-positive
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 68/100
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
ScoopInstaller/Nonportable#639 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
ScoopInstaller/Extras#18800 ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 85/100
uqbar-project/website-wollok-ts#84 · 2 Kommentare ·
-
on hold T: core-bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100