Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b3b997c

Browse files
author
Esben Sparre Andreasen
committed
JS: refactor DefaultUrlRequest: extract the axios library
1 parent d7a81ef commit b3b997c

1 file changed

Lines changed: 30 additions & 14 deletions

File tree

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

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,6 @@ private class DefaultUrlRequest extends CustomUrlRequest {
7474
url = getArgument(0)
7575
)
7676
or
77-
(
78-
moduleName = "axios" and
79-
(
80-
callee = DataFlow::moduleImport(moduleName) or
81-
callee = DataFlow::moduleMember(moduleName, httpMethodName()) or
82-
callee = DataFlow::moduleMember(moduleName, "request")
83-
) and
84-
(
85-
url = getArgument(0) or
86-
url = getOptionArgument([0..2], urlPropertyName()) // slightly over-approximate, in the name of simplicity
87-
)
88-
)
89-
or
9077
(
9178
moduleName = "got" and
9279
(
@@ -154,4 +141,33 @@ private class RequestUrlRequest extends CustomUrlRequest {
154141
result = url
155142
}
156143

157-
}
144+
}
145+
146+
/**
147+
* A model of a URL request in the `axios` library.
148+
*/
149+
private class AxiosUrlRequest extends CustomUrlRequest {
150+
151+
DataFlow::Node url;
152+
153+
AxiosUrlRequest() {
154+
exists (string moduleName, DataFlow::SourceNode callee |
155+
this = callee.getACall() |
156+
moduleName = "axios" and
157+
(
158+
callee = DataFlow::moduleImport(moduleName) or
159+
callee = DataFlow::moduleMember(moduleName, httpMethodName()) or
160+
callee = DataFlow::moduleMember(moduleName, "request")
161+
) and
162+
(
163+
url = getArgument(0) or
164+
url = getOptionArgument([0..2], urlPropertyName()) // slightly over-approximate, in the name of simplicity
165+
)
166+
)
167+
}
168+
169+
override DataFlow::Node getUrl() {
170+
result = url
171+
}
172+
173+
}

0 commit comments

Comments
 (0)