Skip to content

Conversation

@joefarebrother
Copy link
Contributor

@joefarebrother joefarebrother commented Jan 15, 2021

Models the methods of several classes in the collections package (com.google.common.collect) of the Guava framework, including Table, Multimap, the various ImmutableSomething classes and their builders, and the static utility methods in Sets.

Part of https://github.com/github/codeql-java-team/issues/39

https://jenkins.internal.semmle.com/job/Changes/job/Java-Differences/1121/
https://jenkins.internal.semmle.com/job/Changes/job/Java-Differences/1128/

@joefarebrother joefarebrother requested a review from a team as a code owner January 15, 2021 15:53
@github-actions github-actions bot added the Java label Jan 15, 2021
// ImmutableMultiset.Builder<E> addCopies(E element, int occurrences)
// ImmutableMultiset.Builder<E> setCount(E element, int count)
this.hasName(["add", "addAll", "addCopies", "setCount"]) and
argument = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will only match the first element for the varargs method add(E...), won't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The taint tracking library takes varargs into account and will match each element when a varargs parameter is specified by TaintPreservingCallable.


ImmutableContainerType() {
this.getSourceDeclaration().getASourceSupertype*().hasQualifiedName(guavaCollectPackage(), kind) and
kind = ["ImmutableCollection", "ImmutableMap", "ImmutableMultimap", "ImmutableTable"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also ImmutableClassToInstanceMap which interestingly does not extend ImmutableMap.

// static <E> CopyOnWriteArraySet<E> newCopyOnWriteArraySet(Iterable<? extends E> elements)
// static <E extends Enum<E>>EnumSet<E> newEnumSet(Iterable<E> iterable, Class<E> elementType)
// etc
this.getName().matches("new%Set") and
Copy link
Contributor

@Marcono1234 Marcono1234 Jan 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will erroneously taint the argument of newTreeSet(Comparator)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joefarebrother, do you think this will be an issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not, I don't imagine it being common for a Comparator to carry user-tainted data.

private class SetsMethod extends TaintPreservingCallable {
int arg;

SetsMethod() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also match the immutableEnumSet(...) methods? (given that it matches the newEnumSet methods)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flow through enum sets is not relevant for security analysis, since enum sets are internally bitvectors so it's not really possibe for them to be tainted by user input.

@joefarebrother joefarebrother changed the title [Java] Add flow steps for more of Guava [Java] Add flow steps for Guava collection utilities Jan 21, 2021
@joefarebrother joefarebrother changed the title [Java] Add flow steps for Guava collection utilities Java: Add flow steps for Guava collection utilities Jan 22, 2021
@aschackmull
Copy link
Contributor

QL looks good to me, but I don't think we should be adding .class files.

@aschackmull
Copy link
Contributor

We should probably squash the commits that add and remove those .class files to remove them from the git history.

@aschackmull aschackmull merged commit bbdd7c9 into github:main Jan 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants