Skip to content

How to query types with a specific composite type in CodeQL Go? #9097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cokeBeer opened this issue May 10, 2022 · 5 comments
Closed

How to query types with a specific composite type in CodeQL Go? #9097

cokeBeer opened this issue May 10, 2022 · 5 comments
Labels
question Further information is requested

Comments

@cokeBeer
Copy link
Contributor

I am working on defining a dataflow source for web framework Beego.
I tried this query on my project written in beego (https://github.com/cokeBeer/go-sec-code):

import go

from Type c
where  c.hasQualifiedName("go-sec-code/controllers", "CommandInjectVuln1Controller")
select c.getMethod("Get")

it turned out no results,but I do have a go-sec-code/controllers.CommandInjectVuln1Controller.Get Method
https://github.com/cokeBeer/go-sec-code/blob/main/controllers/commandInject.go#L23
image
I think the problem may come from that Beego.Controller is a composite type which looks like:

package controllers

import (
	"fmt"
	"go-sec-code/utils"
	"os/exec"

	beego "github.com/beego/beego/v2/server/web"
)

type CommandInjectVuln1Controller struct {
	beego.Controller
}

moreover, I've noted that there is a BeegoControllerSource in CodeQL Go standard library semmle.go.frameworks.Beego.qll.
image
I tried only query the souce node with vscode's help on the same project, but it turned out not found GetString() method called
image

How can I make a source defination that can find all Controllers that composite Beego.Controller?

@cokeBeer cokeBeer added the question Further information is requested label May 10, 2022
@cokeBeer
Copy link
Contributor Author

found that Beego's latest package name has became ""github.com/beego/beego/v2/server/web"
image
After I add the package name, I can successfully query the results by BeegoControllerSource.
May I got a PR to fix it?

@cokeBeer
Copy link
Contributor Author

Also, the NetHttp.qll lose some fields like "Host"
image
which makes me lose a result
image

@smowton
Copy link
Contributor

smowton commented May 10, 2022

The guess there is that Host is often not user-controlled because the request had to somehow get routed here, whereas of course they do control other parts of the request.

Can I take it you've solved your Beego problem?

@cokeBeer
Copy link
Contributor Author

@smowton yes, seems I don't need to query a composite struct now. What about a PR to fix the module name "github.com/beego/beego/v2/server/web"?

@smowton
Copy link
Contributor

smowton commented May 10, 2022

Sure, please do submit one

cokeBeer pushed a commit to cokeBeer/codeql-go that referenced this issue May 11, 2022
smowton added a commit to github/codeql-go that referenced this issue May 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants