Skip to content

Commit 023c533

Browse files
committed
Combine Servlet and JSF vulnerable writer flow-tracking
JSP and Servlet already shared this logic; might as well add JSF into the same mechanism.
1 parent cb8096f commit 023c533

File tree

1 file changed

+12
-38
lines changed
  • java/ql/lib/semmle/code/java/security

1 file changed

+12
-38
lines changed

java/ql/lib/semmle/code/java/security/XSS.qll

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private class DefaultXssSink extends XssSink {
4141
DefaultXssSink() {
4242
sinkNode(this, "xss")
4343
or
44-
exists(ServletWriterSourceToWritingMethodFlowConfig writer, MethodAccess ma |
44+
exists(XssVulnerableWriterSourceToWritingMethodFlowConfig writer, MethodAccess ma |
4545
ma.getMethod() instanceof WritingMethod and
4646
writer.hasFlowToExpr(ma.getQualifier()) and
4747
this.asExpr() = ma.getArgument(_)
@@ -88,12 +88,6 @@ private class DefaultXssSink extends XssSink {
8888
returnType instanceof RawClass
8989
)
9090
)
91-
or
92-
exists(FacesWriterSourceToWritingMethodFlowConfig writer, MethodAccess ma |
93-
ma.getMethod() instanceof WritingMethod and
94-
writer.hasFlowToExpr(ma.getQualifier()) and
95-
this.asExpr() = ma.getArgument(_)
96-
)
9791
}
9892
}
9993

@@ -108,12 +102,12 @@ private class DefaultXSSSanitizer extends XssSanitizer {
108102
}
109103

110104
/** A configuration that tracks data from a servlet writer to an output method. */
111-
private class ServletWriterSourceToWritingMethodFlowConfig extends TaintTracking2::Configuration {
112-
ServletWriterSourceToWritingMethodFlowConfig() {
113-
this = "XSS::ServletWriterSourceToWritingMethodFlowConfig"
105+
private class XssVulnerableWriterSourceToWritingMethodFlowConfig extends TaintTracking2::Configuration {
106+
XssVulnerableWriterSourceToWritingMethodFlowConfig() {
107+
this = "XSS::XssVulnerableWriterSourceToWritingMethodFlowConfig"
114108
}
115109

116-
override predicate isSource(DataFlow::Node src) { src.asExpr() instanceof ServletWriterSource }
110+
override predicate isSource(DataFlow::Node src) { src.asExpr() instanceof XssVulnerableWriterSource }
117111

118112
override predicate isSink(DataFlow::Node sink) {
119113
exists(MethodAccess ma |
@@ -135,9 +129,9 @@ private class WritingMethod extends Method {
135129
}
136130
}
137131

138-
/** An output stream or writer that writes to a servlet response. */
139-
class ServletWriterSource extends MethodAccess {
140-
ServletWriterSource() {
132+
/** An output stream or writer that writes to a servlet, JSP or JSF response. */
133+
class XssVulnerableWriterSource extends MethodAccess {
134+
XssVulnerableWriterSource() {
141135
this.getMethod() instanceof ServletResponseGetWriterMethod
142136
or
143137
this.getMethod() instanceof ServletResponseGetOutputStreamMethod
@@ -146,6 +140,10 @@ class ServletWriterSource extends MethodAccess {
146140
m.getDeclaringType().getQualifiedName() = "javax.servlet.jsp.JspContext" and
147141
m.getName() = "getOut"
148142
)
143+
or
144+
this.getMethod() instanceof FacesGetResponseWriterMethod
145+
or
146+
this.getMethod() instanceof FacesGetResponseStreamMethod
149147
}
150148
}
151149

@@ -165,27 +163,3 @@ predicate isXssVulnerableContentType(string s) {
165163
*/
166164
bindingset[s]
167165
predicate isXssSafeContentType(string s) { not isXssVulnerableContentType(s) }
168-
169-
/** An output stream or writer that writes to a JSF response. */
170-
class FacesWriterSource extends MethodAccess {
171-
FacesWriterSource() {
172-
this.getMethod() instanceof FacesGetResponseWriterMethod
173-
or
174-
this.getMethod() instanceof FacesGetResponseStreamMethod
175-
}
176-
}
177-
178-
/** A configuration that tracks data from a JSF writer to an output method. */
179-
private class FacesWriterSourceToWritingMethodFlowConfig extends TaintTracking2::Configuration {
180-
FacesWriterSourceToWritingMethodFlowConfig() {
181-
this = "XSS::FacesWriterSourceToWritingMethodFlowConfig"
182-
}
183-
184-
override predicate isSource(DataFlow::Node src) { src.asExpr() instanceof FacesWriterSource }
185-
186-
override predicate isSink(DataFlow::Node sink) {
187-
exists(MethodAccess ma |
188-
sink.asExpr() = ma.getQualifier() and ma.getMethod() instanceof WritingMethod
189-
)
190-
}
191-
}

0 commit comments

Comments
 (0)