Skip to content

Commit 2ce1192

Browse files
author
Alvaro Muñoz
committed
implement field taint inheritance for Struts2 unmarshalled objects
1 parent d88f557 commit 2ce1192

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

java/ql/lib/semmle/code/java/Serializability.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import java
66
private import frameworks.jackson.JacksonSerializability
77
private import frameworks.google.GsonSerializability
88
private import frameworks.google.GoogleHttpClientApi
9+
private import frameworks.struts.Struts2Serializability
910

1011
/**
1112
* A serializable field may be read without code referencing it,
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Provides classes and predicates for working with objects bound from Http requests in the context of
3+
* the Struts2 web framework.
4+
*/
5+
6+
import java
7+
private import semmle.code.java.Serializability
8+
private import semmle.code.java.dataflow.DataFlow
9+
private import semmle.code.java.dataflow.FlowSteps
10+
private import semmle.code.java.frameworks.struts.StrutsActions
11+
12+
/** A type whose values may be unmarshalled from an Http request by the Struts2 framework. */
13+
abstract class Struts2DeserializableType extends Type { }
14+
15+
/** A type whose values are explicitly unmarshalled by from an Http request by the Struts2 framework. */
16+
private class ExplicitlyReadStruts2DeserializableType extends Struts2DeserializableType {
17+
ExplicitlyReadStruts2DeserializableType() {
18+
exists(Struts2ActionSupportClass c |
19+
usesType(c.getASetterMethod().getField().getType(), this) and
20+
not this instanceof TypeClass and
21+
not this instanceof TypeObject
22+
)
23+
}
24+
}
25+
26+
/** A type used in a `Struts2ActionField` declaration. */
27+
private class FieldReferencedStruts2DeserializableType extends Struts2DeserializableType {
28+
FieldReferencedStruts2DeserializableType() {
29+
exists(Struts2ActionField f | usesType(f.getType(), this))
30+
}
31+
}
32+
33+
/** A field that may be unmarshalled from an Http request using the Struts2 framework. */
34+
private class Struts2ActionField extends DeserializableField {
35+
Struts2ActionField() {
36+
exists(Struts2DeserializableType superType |
37+
superType = this.getDeclaringType().getAnAncestor() and
38+
not superType instanceof TypeObject and
39+
superType.fromSource()
40+
)
41+
}
42+
}
43+
44+
/** A field that should convey the taint from its qualifier to itself. */
45+
private class Struts2ActionFieldInheritTaint extends DataFlow::FieldContent, TaintInheritingContent {
46+
Struts2ActionFieldInheritTaint() { this.getField() instanceof Struts2ActionField }
47+
}

0 commit comments

Comments
 (0)