Skip to content

Commit e2cec58

Browse files
committed
Java: XSS - ignore Spring sinks when content-type is safe.
Methods annotated with a produces field which indicates a safe content-type should not be considered XSS sinks. For example: @RequestMapping(..., produces = "application/json")
1 parent f6a99cb commit e2cec58

File tree

1 file changed

+3
-1
lines changed
  • java/ql/src/semmle/code/java/security

1 file changed

+3
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ class XssSink extends DataFlow::ExprNode {
3535
or
3636
exists(SpringRequestMappingMethod requestMappingMethod, ReturnStmt rs |
3737
requestMappingMethod = rs.getEnclosingCallable() and
38-
this.asExpr() = rs.getResult() |
38+
this.asExpr() = rs.getResult() and
39+
(not exists(requestMappingMethod.getProduces()) or requestMappingMethod.getProduces().matches("text/%"))
40+
|
3941
// If a Spring request mapping method is either annotated with @ResponseBody (or equivalent),
4042
// or returns a HttpEntity or sub-type, then the return value of the method is converted into
4143
// a HTTP reponse using a HttpMessageConverter implementation. The implementation is chosen

0 commit comments

Comments
 (0)