Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions java/ql/src/semmle/code/java/dataflow/FlowSteps.qll
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module Frameworks {
private import semmle.code.java.frameworks.Guice
private import semmle.code.java.frameworks.Protobuf
private import semmle.code.java.frameworks.guava.Guava
private import semmle.code.java.frameworks.apache.Lang
}

/**
Expand Down
56 changes: 47 additions & 9 deletions java/ql/src/semmle/code/java/frameworks/apache/Lang.qll
Original file line number Diff line number Diff line change
@@ -1,27 +1,65 @@
/** Definitions related to the Apache Commons Lang library. */

import java
private import semmle.code.java.dataflow.FlowSteps
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs bidirectional import to work, i.e. you need to add private import java/ql/src/semmle/code/java/frameworks/apache/Lang.qll in FlowSteps.qll


/*--- Types ---*/
/** The class `org.apache.commons.lang.RandomStringUtils` or `org.apache.commons.lang3.RandomStringUtils`. */
/**
* The class `org.apache.commons.lang.RandomStringUtils` or `org.apache.commons.lang3.RandomStringUtils`.
*/
class TypeApacheRandomStringUtils extends Class {
TypeApacheRandomStringUtils() {
hasQualifiedName("org.apache.commons.lang", "RandomStringUtils") or
hasQualifiedName("org.apache.commons.lang3", "RandomStringUtils")
this.hasQualifiedName(["org.apache.commons.lang", "org.apache.commons.lang3"],
"RandomStringUtils")
}
}

/**
* The class `org.apache.commons.lang.ArrayUtils` or `org.apache.commons.lang3.ArrayUtils`.
*/
class TypeApacheArrayUtils extends Class {
TypeApacheArrayUtils() {
hasQualifiedName(["org.apache.commons.lang", "org.apache.commons.lang3"], "ArrayUtils")
}
}

/*--- Methods ---*/
/**
* The method `deserialize` in either `org.apache.commons.lang.SerializationUtils`
* or `org.apache.commons.lang3.SerializationUtils`.
*/
class MethodApacheSerializationUtilsDeserialize extends Method {
MethodApacheSerializationUtilsDeserialize() {
(
this.getDeclaringType().hasQualifiedName("org.apache.commons.lang", "SerializationUtils") or
this.getDeclaringType().hasQualifiedName("org.apache.commons.lang3", "SerializationUtils")
) and
this.getDeclaringType()
.hasQualifiedName(["org.apache.commons.lang", "org.apache.commons.lang3"],
"SerializationUtils") and
this.hasName("deserialize")
}
}

/**
* A taint preserving method on `org.apache.commons.lang.ArrayUtils` or `org.apache.commons.lang3.ArrayUtils`
*/
private class ApacheLangArrayUtilsTaintPreservingMethod extends TaintPreservingCallable {
ApacheLangArrayUtilsTaintPreservingMethod() {
this.getDeclaringType() instanceof TypeApacheArrayUtils
}

override predicate returnsTaintFrom(int src) {
this.hasName(["addAll", "addFirst"]) and
src = [0 .. getNumberOfParameters() - 1]
or
this.hasName([
"clone", "nullToEmpty", "remove", "removeAll", "removeElement", "removeElements", "reverse",
"shift", "shuffle", "subarray", "swap", "toArray", "toMap", "toObject", "toPrimitive",
"toString", "toStringArray"
]) and
src = 0
or
this.hasName("add") and
this.getNumberOfParameters() = 2 and
src = [0, 1]
or
this.hasName("add") and
this.getNumberOfParameters() = 3 and
src = [0, 2]
}
}