@@ -87,7 +87,7 @@ class HttpStringLiteral extends StringLiteral {
87
87
HttpStringLiteral ( ) {
88
88
// Match URLs with the HTTP protocol and without private IP addresses to reduce false positives.
89
89
exists ( string s | this .getRepresentedString ( ) = s |
90
- s .regexpMatch ( "(?i)http://[\\[: a-zA-Z0-9].*" ) and
90
+ s .regexpMatch ( "(?i)http://[\\[a-zA-Z0-9].*" ) and
91
91
not s .substring ( 7 , s .length ( ) ) .regexpMatch ( getPrivateHostRegex ( ) )
92
92
)
93
93
}
@@ -106,37 +106,33 @@ predicate concatHttpString(Expr protocol, Expr host) {
106
106
.( CompileTimeConstantExpr )
107
107
.getStringValue ( )
108
108
.regexpMatch ( "(?i)http(://)?" )
109
- ) and // Not empty host string
110
- (
111
- host .( CompileTimeConstantExpr ) .getStringValue ( ) .length ( ) > 0 or
112
- host
113
- .( VarAccess )
114
- .getVariable ( )
115
- .getAnAssignedValue ( )
116
- .( CompileTimeConstantExpr )
117
- .getStringValue ( )
118
- .length ( ) > 0
119
109
) and
120
- not (
121
- host .( CompileTimeConstantExpr ) .getStringValue ( ) .regexpMatch ( getPrivateHostRegex ( ) ) or
122
- host
123
- .( VarAccess )
124
- .getVariable ( )
125
- .getAnAssignedValue ( )
126
- .( CompileTimeConstantExpr )
127
- .getStringValue ( )
128
- .regexpMatch ( getPrivateHostRegex ( ) )
110
+ not exists ( string hostString |
111
+ hostString = host .( CompileTimeConstantExpr ) .getStringValue ( ) or
112
+ hostString =
113
+ host .( VarAccess ) .getVariable ( ) .getAnAssignedValue ( ) .( CompileTimeConstantExpr ) .getStringValue ( )
114
+ |
115
+ hostString .length ( ) = 0 or // Empty host is loopback address
116
+ hostString .regexpMatch ( getPrivateHostRegex ( ) )
129
117
)
130
118
}
131
119
120
+ /** Gets the leftmost operand in a concatenated string */
121
+ Expr getLeftmostConcatOperand ( Expr expr ) {
122
+ if expr instanceof AddExpr
123
+ then result = getLeftmostConcatOperand ( expr .( AddExpr ) .getLeftOperand ( ) )
124
+ else result = expr
125
+ }
126
+
132
127
/**
133
128
* String concatenated with `HttpStringLiteral`.
134
129
*/
135
130
class HttpString extends Expr {
136
131
HttpString ( ) {
137
132
this instanceof HttpStringLiteral
138
133
or
139
- concatHttpString ( this .( AddExpr ) .getLeftOperand ( ) , this .( AddExpr ) .getRightOperand ( ) )
134
+ concatHttpString ( this .( AddExpr ) .getLeftOperand ( ) ,
135
+ getLeftmostConcatOperand ( this .( AddExpr ) .getRightOperand ( ) ) )
140
136
}
141
137
}
142
138
0 commit comments