File tree Expand file tree Collapse file tree 3 files changed +49
-13
lines changed
java/ql/lib/semmle/code/java Expand file tree Collapse file tree 3 files changed +49
-13
lines changed Original file line number Diff line number Diff line change @@ -411,18 +411,33 @@ private class JaxRSXssSink extends XssSink {
411
411
|
412
412
not exists ( resourceMethod .getProducesAnnotation ( ) )
413
413
or
414
- isXssVulnerableContentType ( getContentTypeString ( resourceMethod
415
- .getProducesAnnotation ( )
416
- .getADeclaredContentTypeExpr ( ) ) )
414
+ isXssVulnerableContentTypeExpr ( resourceMethod
415
+ .getProducesAnnotation ( )
416
+ .getADeclaredContentTypeExpr ( ) )
417
417
)
418
418
}
419
419
}
420
420
421
+ pragma [ nomagic]
422
+ private predicate contentTypeString ( string s ) { s = getContentTypeString ( _) }
423
+
424
+ pragma [ nomagic]
425
+ private predicate isXssVulnerableContentTypeString ( string s ) {
426
+ contentTypeString ( s ) and isXssVulnerableContentType ( s )
427
+ }
428
+
429
+ pragma [ nomagic]
430
+ private predicate isXssSafeContentTypeString ( string s ) {
431
+ contentTypeString ( s ) and isXssSafeContentType ( s )
432
+ }
433
+
421
434
private predicate isXssVulnerableContentTypeExpr ( Expr e ) {
422
- isXssVulnerableContentType ( getContentTypeString ( e ) )
435
+ isXssVulnerableContentTypeString ( getContentTypeString ( e ) )
423
436
}
424
437
425
- private predicate isXssSafeContentTypeExpr ( Expr e ) { isXssSafeContentType ( getContentTypeString ( e ) ) }
438
+ private predicate isXssSafeContentTypeExpr ( Expr e ) {
439
+ isXssSafeContentTypeString ( getContentTypeString ( e ) )
440
+ }
426
441
427
442
/**
428
443
* Gets a builder expression or related type that is configured to use the given `contentType`.
Original file line number Diff line number Diff line change @@ -152,14 +152,30 @@ private string getSpringConstantContentType(FieldAccess e) {
152
152
)
153
153
}
154
154
155
+ private string getContentTypeString ( Expr e ) {
156
+ result = e .( CompileTimeConstantExpr ) .getStringValue ( ) or
157
+ result = getSpringConstantContentType ( e )
158
+ }
159
+
160
+ pragma [ nomagic]
161
+ private predicate contentTypeString ( string s ) { s = getContentTypeString ( _) }
162
+
163
+ pragma [ nomagic]
164
+ private predicate isXssVulnerableContentTypeString ( string s ) {
165
+ contentTypeString ( s ) and XSS:: isXssVulnerableContentType ( s )
166
+ }
167
+
168
+ pragma [ nomagic]
169
+ private predicate isXssSafeContentTypeString ( string s ) {
170
+ contentTypeString ( s ) and XSS:: isXssSafeContentType ( s )
171
+ }
172
+
155
173
private predicate isXssVulnerableContentTypeExpr ( Expr e ) {
156
- XSS:: isXssVulnerableContentType ( e .( CompileTimeConstantExpr ) .getStringValue ( ) ) or
157
- XSS:: isXssVulnerableContentType ( getSpringConstantContentType ( e ) )
174
+ isXssVulnerableContentTypeString ( getContentTypeString ( e ) )
158
175
}
159
176
160
177
private predicate isXssSafeContentTypeExpr ( Expr e ) {
161
- XSS:: isXssSafeContentType ( e .( CompileTimeConstantExpr ) .getStringValue ( ) ) or
162
- XSS:: isXssSafeContentType ( getSpringConstantContentType ( e ) )
178
+ isXssSafeContentTypeString ( getContentTypeString ( e ) )
163
179
}
164
180
165
181
private DataFlow:: Node getABodyBuilderWithExplicitContentType ( Expr contentType ) {
Original file line number Diff line number Diff line change @@ -118,10 +118,15 @@ class XssVulnerableWriterSourceNode extends ApiSourceNode {
118
118
*/
119
119
bindingset [ s]
120
120
predicate isXssVulnerableContentType ( string s ) {
121
- s .regexpMatch ( "(?i)text/(html|xml|xsl|rdf|vtt|cache-manifest).*" ) or
122
- s .regexpMatch ( "(?i)application/(.*\\+)?xml.*" ) or
123
- s .regexpMatch ( "(?i)cache-manifest.*" ) or
124
- s .regexpMatch ( "(?i)image/svg\\+xml.*" )
121
+ s .regexpMatch ( "(?i)(" +
122
+ //
123
+ "text/(html|xml|xsl|rdf|vtt|cache-manifest).*" + "|" +
124
+ //
125
+ "application/(.*\\+)?xml.*" + "|" +
126
+ //
127
+ "cache-manifest.*" + "|" +
128
+ //
129
+ "image/svg\\+xml.*" + ")" )
125
130
}
126
131
127
132
/**
You can’t perform that action at this time.
0 commit comments