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

False positive on "Query built by concatenation with a possibly-untrusted string" - "java/concatenated-sql-query" #16984

Open
bpmarinho opened this issue Jul 15, 2024 · 1 comment

Comments

@bpmarinho
Copy link

bpmarinho commented Jul 15, 2024

False positive on Query built by concatenation with a possibly-untrusted string - java/concatenated-sql-query

We have a constant value from enum

public enum CommentType {

    REVIEW_SIMPLE_COMMENT("comment.review.simple"),
    SIMPLE_COMMENT("comment.simple");

    private final String type;

    private CommentType(String type) {
        this.type = type;
    }

    public String getType() {
        return this.type;
    }
}

Used in query

sql.append(" AND REVIEW_COMMENT.COMMENT_TYPE = '").append(CommentType.REVIEW_SIMPLE_COMMENT.getType()).append("') ");

And CodeQL is stating Query built by concatenation with a possibly-untrusted string in CommentType.REVIEW_SIMPLE_COMMENT.getType(). From my understanding the enum is immutable. Could you take a look?

@aibaars
Copy link
Contributor

aibaars commented Jul 17, 2024

Thank you for this false positive report. Resolving this issue is not a current product priority, but we acknowledge the report and will track it internally for future consideration, or if we observe repeated instances of the same problem.

Your right that this is a false positive. The query is simply looking for SQL strings built by string concatenation without proper escaping of variables, which is usually a bad thing to do. In your case the two type values in the enum are string constants that do not contain any special SQL characters, so it is indeed safe. You can dismiss the alert, or apply some SQL string escaping to CommentType.REVIEW_SIMPLE_COMMENT.getType() before appending.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants