codeql icon indicating copy to clipboard operation
codeql copied to clipboard

Parameterized codeql queries

Open aaaayush-n opened this issue 1 year ago • 3 comments
trafficstars

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 avatar Jul 17 '24 11:07 aaaayush-n

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.

aibaars avatar Jul 17 '24 12:07 aibaars

@aibaars Are data extensions available for golang?

aaaayush-n avatar Jul 19 '24 09:07 aaaayush-n

@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.

aibaars avatar Jul 19 '24 13:07 aibaars

Hi @aaaayush-n,

I'm closing this issue because it seems that @aibaars has provided you with possible next steps. If you still have questions, feel free to re-open this issue.

rvermeulen avatar Oct 14 '24 22:10 rvermeulen