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

Java: sanitize values which are checked against an allowlist (currently only java.util.List.contains) #17051

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

owen-mc
Copy link
Contributor

@owen-mc owen-mc commented Jul 23, 2024

Checking that a value is in a set of compile-time constant values should be a sanitizer, because what was untrusted data has now been checked to be in a known set of values. It is hard in CodeQL to identify when this happens, as there are many ways of checking that a value is in a known set of values. This PR introduces the framework for this sanitizer and implements it for a small number of cases:

  • currently only a call to contains on a java.util.List which contains only compile-time constant values
  • the list must either be
    • an immutable list created using List.of(...) or Collections.unmodifiableList(Arrays.asList(...)), either created locally or read from a final static field.
    • a locally constructed List which has had elements added using add, and they are all constants.

@owen-mc owen-mc changed the title Java: sanitize values which are checked against an allowlist (currently only calling List.contains on a list constructed locally with List.of) Java: sanitize values which are checked against an allowlist (currently only java.util.List.contains) Oct 3, 2024
or
collectionClass = "Set" and
t.hasQualifiedName("java.util", "Set") and
m.getName() = ["add"] and

Check warning

Code scanning / CodeQL

Singleton set literal Warning

Singleton set literal can be replaced by its member.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant