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 @@ -426,18 +426,33 @@ private class JaxRSXssSink extends XssSink {
426
426
|
427
427
not exists ( resourceMethod .getProducesAnnotation ( ) )
428
428
or
429
- isXssVulnerableContentType ( getContentTypeString ( resourceMethod
430
- .getProducesAnnotation ( )
431
- .getADeclaredContentTypeExpr ( ) ) )
429
+ isXssVulnerableContentTypeExpr ( resourceMethod
430
+ .getProducesAnnotation ( )
431
+ .getADeclaredContentTypeExpr ( ) )
432
432
)
433
433
}
434
434
}
435
435
436
+ pragma [ nomagic]
437
+ private predicate contentTypeString ( string s ) { s = getContentTypeString ( _) }
438
+
439
+ pragma [ nomagic]
440
+ private predicate isXssVulnerableContentTypeString ( string s ) {
441
+ contentTypeString ( s ) and isXssVulnerableContentType ( s )
442
+ }
443
+
444
+ pragma [ nomagic]
445
+ private predicate isXssSafeContentTypeString ( string s ) {
446
+ contentTypeString ( s ) and isXssSafeContentType ( s )
447
+ }
448
+
436
449
private predicate isXssVulnerableContentTypeExpr ( Expr e ) {
437
- isXssVulnerableContentType ( getContentTypeString ( e ) )
450
+ isXssVulnerableContentTypeString ( getContentTypeString ( e ) )
438
451
}
439
452
440
- private predicate isXssSafeContentTypeExpr ( Expr e ) { isXssSafeContentType ( getContentTypeString ( e ) ) }
453
+ private predicate isXssSafeContentTypeExpr ( Expr e ) {
454
+ isXssSafeContentTypeString ( getContentTypeString ( e ) )
455
+ }
441
456
442
457
/**
443
458
* 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