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 {
426426 |
427427 not exists ( resourceMethod .getProducesAnnotation ( ) )
428428 or
429- isXssVulnerableContentType ( getContentTypeString ( resourceMethod
430- .getProducesAnnotation ( )
431- .getADeclaredContentTypeExpr ( ) ) )
429+ isXssVulnerableContentTypeExpr ( resourceMethod
430+ .getProducesAnnotation ( )
431+ .getADeclaredContentTypeExpr ( ) )
432432 )
433433 }
434434}
435435
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+
436449private predicate isXssVulnerableContentTypeExpr ( Expr e ) {
437- isXssVulnerableContentType ( getContentTypeString ( e ) )
450+ isXssVulnerableContentTypeString ( getContentTypeString ( e ) )
438451}
439452
440- private predicate isXssSafeContentTypeExpr ( Expr e ) { isXssSafeContentType ( getContentTypeString ( e ) ) }
453+ private predicate isXssSafeContentTypeExpr ( Expr e ) {
454+ isXssSafeContentTypeString ( getContentTypeString ( e ) )
455+ }
441456
442457/**
443458 * 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) {
152152 )
153153}
154154
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+
155173private predicate isXssVulnerableContentTypeExpr ( Expr e ) {
156- XSS:: isXssVulnerableContentType ( e .( CompileTimeConstantExpr ) .getStringValue ( ) ) or
157- XSS:: isXssVulnerableContentType ( getSpringConstantContentType ( e ) )
174+ isXssVulnerableContentTypeString ( getContentTypeString ( e ) )
158175}
159176
160177private predicate isXssSafeContentTypeExpr ( Expr e ) {
161- XSS:: isXssSafeContentType ( e .( CompileTimeConstantExpr ) .getStringValue ( ) ) or
162- XSS:: isXssSafeContentType ( getSpringConstantContentType ( e ) )
178+ isXssSafeContentTypeString ( getContentTypeString ( e ) )
163179}
164180
165181private DataFlow:: Node getABodyBuilderWithExplicitContentType ( Expr contentType ) {
Original file line number Diff line number Diff line change @@ -118,10 +118,15 @@ class XssVulnerableWriterSourceNode extends ApiSourceNode {
118118 */
119119bindingset [ s]
120120predicate 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.*" + ")" )
125130}
126131
127132/**
You can’t perform that action at this time.
0 commit comments