Skip to content

Commit a49296b

Browse files
committed
Handling of axios in functions and making axios create function recursive
1 parent 254789c commit a49296b

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

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

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,36 @@ module ClientRequest {
204204
override DataFlow::SourceNode getASource() { result = DataFlow::globalVarRef("axios") }
205205
}
206206

207+
/** An API entry-point for the `axios` library inside a function */
208+
private class AxiosInFunction extends API::EntryPoint {
209+
AxiosInFunction() { this = "axios" }
210+
211+
override DataFlow::SourceNode getASource() {
212+
// Handle direct parameter naming: function(axios){}
213+
exists(Function f, Parameter p |
214+
p.getName() = "axios" and
215+
result = DataFlow::parameterNode(p)
216+
)
217+
or
218+
// Handle destructured parameters: function({axios}){}
219+
exists(DataFlow::ParameterNode param, DataFlow::SourceNode prop |
220+
prop = param.getAPropertyRead("axios") and
221+
result = prop
222+
)
223+
}
224+
}
207225
/** Gets a reference to the `axios` library. */
208226
private API::Node axios() {
209227
result = API::moduleImport("axios")
210228
or
211229
result = API::root().getASuccessor(API::Label::entryPoint(any(AxiosGlobalEntryPoint entry)))
230+
or
231+
result = API::root().getASuccessor(API::Label::entryPoint(any(AxiosInFunction entry)))
232+
}
233+
234+
/** Recursively gets the `create` method of an axios instance. */
235+
private API::Node axiosWithCreate() {
236+
result = [axios(), axios().getMember("create").getReturn()]
212237
}
213238

214239
/**
@@ -218,14 +243,11 @@ module ClientRequest {
218243
string method;
219244

220245
AxiosUrlRequest() {
221-
this = axios().getACall() and
246+
this = axiosWithCreate().getACall() and
222247
method = "request"
223248
or
224-
this = axios().getMember(method).getACall() and
249+
this = axiosWithCreate().getMember(method).getACall() and
225250
method = [httpMethodName(), "request", "postForm", "putForm", "patchForm", "getUri"]
226-
or
227-
this = axios().getMember("create").getReturn().getACall() and
228-
method = "request"
229251
}
230252

231253
private int getOptionsArgIndex() {

0 commit comments

Comments
 (0)