General issue Go. Why isn't the following code recognized as a source in a global data stream?

Aperta
#19,807 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
go
Ambito
devtools, security

Direzione di ricerca

Inizia confrontando il flusso della sorgente in router.go, controller.go, validator.go e param.go con la ActiveThreatModelSource predefinita in TainterPath.ql. Riproduci la differenza tra Quick Evaluation e TaintTracking::Global, quindi esamina la query personalizzata GinContextGetSource e i suoi riferimenti a val.Get, req e c. Il lavoro è completato quando la sorgente prevista viene riconosciuta nel flusso di dati globale.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

question

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".
Image

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!

Lingua principale
CodeQL
Stelle
10.1k
Fork
2.1k
Merge medio
2g 10h
PR unite (30g)
134

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di github/codeql

Tutte le issue di github/codeql

Issue simili

Altre issue su DevTools

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.