|
| 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() and |
| 40 | + ( |
| 41 | + this.isPublic() |
| 42 | + or |
| 43 | + exists(SetterMethod setter | setter.getField() = this and setter.isPublic()) |
| 44 | + ) |
| 45 | + ) |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +/** A field that should convey the taint from its qualifier to itself. */ |
| 50 | +private class Struts2ActionFieldInheritTaint extends DataFlow::FieldContent, TaintInheritingContent { |
| 51 | + Struts2ActionFieldInheritTaint() { this.getField() instanceof Struts2ActionField } |
| 52 | +} |
0 commit comments