Skip to content

Commit 28a1900

Browse files
committed
treat all writes to Authorization as a CredentialsExpr
1 parent 6466ab1 commit 28a1900

File tree

1 file changed

+17
-30
lines changed

1 file changed

+17
-30
lines changed

javascript/ql/src/semmle/javascript/frameworks/ClientRequests.qll

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,23 @@ module ClientRequest {
260260
}
261261
}
262262

263+
/** An expression that is used as a credential in a request. */
264+
private class AuthorizationHeader extends CredentialsExpr {
265+
AuthorizationHeader() {
266+
exists(DataFlow::PropWrite write | write.getPropertyName() = "Authorization" |
267+
this = write.getRhs().asExpr()
268+
)
269+
or
270+
exists(DataFlow::MethodCallNode call | call.getMethodName() = ["append", "set"] |
271+
call.getNumArgument() = 2 and
272+
call.getArgument(0).mayHaveStringValue("Authorization") and
273+
this = call.getArgument(1).asExpr()
274+
)
275+
}
276+
277+
override string getCredentialsKind() { result = "authorization headers" }
278+
}
279+
263280
/**
264281
* Provides predicates for working with `fetch` and its platform-specific instances as a single module.
265282
*/
@@ -273,36 +290,6 @@ module ClientRequest {
273290
result = DataFlow::globalVarRef("fetch") // https://fetch.spec.whatwg.org/#fetch-api
274291
}
275292

276-
/**
277-
* Gets an instance of the `Headers` class.
278-
*/
279-
private DataFlow::NewNode header() {
280-
result = moduleImport().getAConstructorInvocation("Headers")
281-
or
282-
result = DataFlow::globalVarRef("Headers").getAnInstantiation() // https://fetch.spec.whatwg.org/#headers-class
283-
}
284-
285-
/** An expression that is used as a credential in a fetch-request. */
286-
private class FetchAuthorization extends CredentialsExpr {
287-
FetchAuthorization() {
288-
exists(DataFlow::Node headerObject |
289-
headerObject = header().getArgument(0)
290-
or
291-
headerObject = moduleImport().getACall().getOptionArgument(1, "headers")
292-
|
293-
this = headerObject.getALocalSource().getAPropertyWrite("Authorization").getRhs().asExpr()
294-
)
295-
or
296-
exists(DataFlow::MethodCallNode appendCall |
297-
appendCall = header().getAMethodCall(["append", "set"]) and
298-
appendCall.getArgument(0).mayHaveStringValue("Authorization") and
299-
this = appendCall.getArgument(1).asExpr()
300-
)
301-
}
302-
303-
override string getCredentialsKind() { result = "authorization headers" }
304-
}
305-
306293
/**
307294
* A model of a URL request made using an implementation of the `fetch` API.
308295
*/

0 commit comments

Comments
 (0)