Skip to content
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

Parameterized codeql queries #17005

Open
aaaayush-n opened this issue Jul 17, 2024 · 3 comments
Open

Parameterized codeql queries #17005

aaaayush-n opened this issue Jul 17, 2024 · 3 comments
Labels
question Further information is requested

Comments

@aaaayush-n
Copy link

Is there a way to write parameterized queries? Say I my query is something like:

from string methodName, MethodDecl method 
where methodName="MyFunc1"
and method.getName()=methodName
select method,"FaultyMethod"

Now I want to run this query for multiple methodNames. Can I like compile the query once and then just pass the strings of method name using some script in golang(where all strings MyFunc1, MyFunc2,MyFunc3,etc are stored) which runs this query?

@aaaayush-n aaaayush-n added the question Further information is requested label Jul 17, 2024
@aibaars
Copy link
Contributor

aibaars commented Jul 17, 2024

That is possible using external predicates or using data extensions

For external predicates you can provide the data as a CSV file using the follow flag of codeql query run -vvv --help

      --external=<pred>=<file.csv>
                             A CSV file that contains rows for external
                               predicate <pred>. Multiple --external options
                               can be supplied.

Data extensions are used to implement library models for CodeQL. See: https://codeql.github.com/docs/codeql-language-guides/customizing-library-models-for-java-and-kotlin/ . I don't have a good reference to documentation unfortunately, but searching for the words data extension should give you some starting points in the code to look at.

@aaaayush-n
Copy link
Author

@aibaars
Are data extensions available for golang?

@aibaars
Copy link
Contributor

aibaars commented Jul 19, 2024

@aibaars Are data extensions available for golang?

It's a feature of the QL language, so they should be available for all languages. It may be that the QL library for Go is not using them yet, but that does not mean they won't work for you.

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