refactor copy-pasted code into getAnLibraryInputParameter

This commit is contained in:
Erik Krogh Kristensen
2021-01-12 14:08:10 +01:00
parent eaee5c2d87
commit 0a17b04650
3 changed files with 12 additions and 14 deletions

View File

@@ -6,6 +6,16 @@
import javascript
/**
* Gets a parameter that is a library input to a top-level package.
*/
DataFlow::ParameterNode getAnLibraryInputParameter() {
exists(int bound, DataFlow::FunctionNode func |
func = getAValueExportedBy(getTopmostPackageJSON()).getABoundFunctionValue(bound) and
result = func.getParameter(any(int arg | arg >= bound))
)
}
/**
* Gets the number of occurrences of "/" in `path`.
*/

View File

@@ -52,12 +52,7 @@ module UnsafeShellCommandConstruction {
*/
class ExternalInputSource extends Source, DataFlow::ParameterNode {
ExternalInputSource() {
exists(int bound, DataFlow::FunctionNode func |
func =
Exports::getAValueExportedBy(Exports::getTopmostPackageJSON())
.getABoundFunctionValue(bound) and
this = func.getParameter(any(int arg | arg >= bound))
) and
this = Exports::getAnLibraryInputParameter() and
not this.getName() = ["cmd", "command"] // looks to be on purpose.
}
}

View File

@@ -122,14 +122,7 @@ module PolynomialReDoS {
* A parameter of an exported function, seen as a source for polynomial-redos.
*/
class ExternalInputSource extends Source, DataFlow::ParameterNode {
ExternalInputSource() {
exists(int bound, DataFlow::FunctionNode func |
func =
Exports::getAValueExportedBy(Exports::getTopmostPackageJSON())
.getABoundFunctionValue(bound) and
this = func.getParameter(any(int arg | arg >= bound))
)
}
ExternalInputSource() { this = Exports::getAnLibraryInputParameter() }
override string getKind() { result = "library" }