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

Why am I getting this error inspite of specifying @kind and the correct output format #17982

Open
akanksha1331 opened this issue Nov 14, 2024 · 2 comments
Labels
question Further information is requested

Comments

@akanksha1331
Copy link

akanksha1331 commented Nov 14, 2024

Hi, can anyone guide me on the correct @kind for this query to resolve the error:

A fatal error occurred: Could not process query metadata for C:\Users......custom-java-queries\example5.bqrs.
Error was: Cannot process query metadata for a query without the '@kind' metadata property. To learn more, see https://codeql.github.com/docs/writing-codeql-queries/metadata-for-codeql-queries/ [NO_KIND_SPECIFIED]

Note: I need to run this query from a batch script and store results in a csv.

/**
 * This is an automatically generated file
 * @name v5
 * @kind problem
 * @problem.severity warning
 * @id java/example/hello-world
 */

import java
import semmle.code.java.dataflow.DataFlow

predicate isSource(DataFlow::Node src) {
  exists(Parameter p |
    p.getName() in ["realName", "blabName", "username", "file", "command", "blabberUsername", "password", "remember", "target"] and
    src.asParameter() = p
  )
  or
  exists(MethodAccess access |
    access.getMethod().getDeclaringType().getName() = "javax.servlet.http.HttpServletRequest" and
    (
      access.getMethod().hasName("getParameter") or
      access.getMethod().hasName("getHeader") or
      access.getMethod().hasName("getCookies")
    ) and
    src.asExpr() = access
  )
  or
  exists(MethodAccess cmdClassAccess |
    cmdClassAccess.getMethod().getName() in ["forName", "newInstance"] and
    src.asExpr() = cmdClassAccess
  )
  or
  exists(MethodAccess methodAccess |
    methodAccess.getMethod().getName() in ["processLogin", "showPasswordHint", "processRegister"] and
    src.asExpr() = methodAccess
  )
}

predicate isSink(DataFlow::Node snk) {
  exists(MethodAccess fileAccess |
    fileAccess.getMethod().getDeclaringType().getName() = "java.io.File" and
    (
      fileAccess.getMethod().hasName("renameTo") or
      fileAccess.getMethod().hasName("new File")
    ) and
    snk.asExpr() = fileAccess
  )
  or
  exists(MethodAccess sqlMethod |
    sqlMethod.getMethod().getDeclaringType().getName() = "java.sql.Statement" and
    (
      sqlMethod.getMethod().hasName("executeQuery") or
      sqlMethod.getMethod().hasName("executeUpdate") or
      sqlMethod.getMethod().hasName("execute")
    ) and
    snk.asExpr() = sqlMethod
  )
  or
  exists(BinaryExpr concatExpr |
    (concatExpr.getLeftOperand() instanceof Literal or concatExpr.getRightOperand() instanceof Literal) and
    snk.asExpr() = concatExpr
  )
  or
  exists(MethodAccess cmdExec |
    cmdExec.getMethod().getName() in ["exec", "start"] and
    snk.asExpr() = cmdExec
  )
  or
  exists(MethodAccess objectStreamAccess |
    objectStreamAccess.getMethod().getDeclaringType().getName() = "java.io.ObjectInputStream" and
    objectStreamAccess.getMethod().hasName("readObject") and
    snk.asExpr() = objectStreamAccess
  )
  or
  exists(MethodAccess formatAccess |
    formatAccess.getMethod().getName() = "format" and
    snk.asExpr() = formatAccess
  )
}

from DataFlow::Node source, DataFlow::Node sink
where isSource(source) and isSink(sink)
select 
  source, 
  source.getEnclosingCallable().getBody().toString() + " is source; " + 
  sink.toString() + "; " + 
  sink.getEnclosingCallable().getBody().toString() + " is sink"

Since the result of select clause has 2 columns: element, string, I'm confused as to why I am encountering an error.

@akanksha1331 akanksha1331 added the question Further information is requested label Nov 14, 2024
@aibaars
Copy link
Contributor

aibaars commented Nov 14, 2024

At a glance the query looks indeed fine.

A common reason for this type of errors is when the cached results of an earlier query run are used. The cached results may be from an old version of the query. If you are running codeql database analyze or similar, make sure to pass the --rerun flag to avoid this problem.

If you are running the low level codeql bqrs interpret command to convert a bqrs file to CSV then you may need to explicitly supply a value for the kind property using -t kind=problem. This low-level command does not read the QL source file.

If you need further assistance, please share which command you are running and the complete error message?

@akanksha1331
Copy link
Author

Thanks, --rerun worked!

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