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

Skip to content

Commit 0a17b04

Browse files
committed
refactor copy-pasted code into getAnLibraryInputParameter
1 parent eaee5c2 commit 0a17b04

3 files changed

Lines changed: 12 additions & 14 deletions

File tree

javascript/ql/src/semmle/javascript/PackageExports.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66

77
import javascript
88

9+
/**
10+
* Gets a parameter that is a library input to a top-level package.
11+
*/
12+
DataFlow::ParameterNode getAnLibraryInputParameter() {
13+
exists(int bound, DataFlow::FunctionNode func |
14+
func = getAValueExportedBy(getTopmostPackageJSON()).getABoundFunctionValue(bound) and
15+
result = func.getParameter(any(int arg | arg >= bound))
16+
)
17+
}
18+
919
/**
1020
* Gets the number of occurrences of "/" in `path`.
1121
*/

javascript/ql/src/semmle/javascript/security/dataflow/UnsafeShellCommandConstructionCustomizations.qll

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,7 @@ module UnsafeShellCommandConstruction {
5252
*/
5353
class ExternalInputSource extends Source, DataFlow::ParameterNode {
5454
ExternalInputSource() {
55-
exists(int bound, DataFlow::FunctionNode func |
56-
func =
57-
Exports::getAValueExportedBy(Exports::getTopmostPackageJSON())
58-
.getABoundFunctionValue(bound) and
59-
this = func.getParameter(any(int arg | arg >= bound))
60-
) and
55+
this = Exports::getAnLibraryInputParameter() and
6156
not this.getName() = ["cmd", "command"] // looks to be on purpose.
6257
}
6358
}

javascript/ql/src/semmle/javascript/security/performance/PolynomialReDoSCustomizations.qll

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,7 @@ module PolynomialReDoS {
122122
* A parameter of an exported function, seen as a source for polynomial-redos.
123123
*/
124124
class ExternalInputSource extends Source, DataFlow::ParameterNode {
125-
ExternalInputSource() {
126-
exists(int bound, DataFlow::FunctionNode func |
127-
func =
128-
Exports::getAValueExportedBy(Exports::getTopmostPackageJSON())
129-
.getABoundFunctionValue(bound) and
130-
this = func.getParameter(any(int arg | arg >= bound))
131-
)
132-
}
125+
ExternalInputSource() { this = Exports::getAnLibraryInputParameter() }
133126

134127
override string getKind() { result = "library" }
135128

0 commit comments

Comments
 (0)