Skip to content

Handling of axios in functions and making axios create function recur… #19337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
category: minorAnalysis
---
* Added support for `axios` `create` method recursively
* Added support for `axios` parameters in functions
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,36 @@ module ClientRequest {
override DataFlow::SourceNode getASource() { result = DataFlow::globalVarRef("axios") }
}

/** An API entry-point for the `axios` library inside a function */
private class AxiosInFunction extends API::EntryPoint {
AxiosInFunction() { this = "axios" }

override DataFlow::SourceNode getASource() {
// Handle direct parameter naming: function(axios){}
exists(Function f, Parameter p |
p.getName() = "axios" and
result = DataFlow::parameterNode(p)
)
or
// Handle destructured parameters: function({axios}){}
exists(DataFlow::ParameterNode param, DataFlow::SourceNode prop |
prop = param.getAPropertyRead("axios") and
result = prop
)
}
}
/** Gets a reference to the `axios` library. */
private API::Node axios() {
result = API::moduleImport("axios")
or
result = API::root().getASuccessor(API::Label::entryPoint(any(AxiosGlobalEntryPoint entry)))
or
result = API::root().getASuccessor(API::Label::entryPoint(any(AxiosInFunction entry)))
}

/** Recursively gets the `create` method of an axios instance. */
private API::Node axiosWithCreate() {
result = [axios(), axios().getMember("create").getReturn()]
}

/**
Expand All @@ -218,14 +243,11 @@ module ClientRequest {
string method;

AxiosUrlRequest() {
this = axios().getACall() and
this = axiosWithCreate().getACall() and
method = "request"
or
this = axios().getMember(method).getACall() and
this = axiosWithCreate().getMember(method).getACall() and
method = [httpMethodName(), "request", "postForm", "putForm", "patchForm", "getUri"]
or
this = axios().getMember("create").getReturn().getACall() and
method = "request"
}

private int getOptionsArgIndex() {
Expand Down