Skip to content

Commit e0870e0

Browse files
esbenaStephan Brandauer
authored andcommitted
support import in getSimpleAccessPath
1 parent e7de6cb commit e0870e0

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

  • javascript/ql/experimental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling

javascript/ql/experimental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/EndpointFeatures.qll

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -469,21 +469,33 @@ private module SyntacticUtilities {
469469
if e instanceof VarAccess
470470
then result = e.(VarAccess).getName()
471471
else
472-
if e instanceof AwaitExpr
473-
then result = getSimpleAccessPath(e.(AwaitExpr).getOperand().flow()) + ".then()"
472+
if e instanceof Import
473+
then result = "import(" + getSimpleImportPath(e) + ")"
474474
else
475-
if node instanceof DataFlow::PropRead
476-
then
477-
result =
478-
getSimpleAccessPath(node.(DataFlow::PropRead).getBase()) + "." +
479-
getPropertyNameOrUnknown(node)
475+
if e instanceof AwaitExpr
476+
then result = getSimpleAccessPath(e.(AwaitExpr).getOperand().flow()) + ".then()"
480477
else
481-
if node instanceof DataFlow::InvokeNode
478+
if node instanceof DataFlow::PropRead
482479
then
483-
result = getSimpleAccessPath(node.(DataFlow::InvokeNode).getCalleeNode()) + "()"
484-
else result = "?"
480+
result =
481+
getSimpleAccessPath(node.(DataFlow::PropRead).getBase()) + "." +
482+
getPropertyNameOrUnknown(node)
483+
else
484+
if node instanceof DataFlow::InvokeNode
485+
then
486+
result = getSimpleAccessPath(node.(DataFlow::InvokeNode).getCalleeNode()) + "()"
487+
else result = "?"
485488
)
486489
}
490+
491+
string getSimpleImportPath(Import i) {
492+
if exists(i.getImportedPath().getValue())
493+
then
494+
exists(string p | p = i.getImportedPath().getValue() |
495+
if p.matches(".%") then result = p else result = "!" // hide absolute imports from the ML training
496+
)
497+
else result = "?"
498+
}
487499
}
488500

489501
/**

0 commit comments

Comments
 (0)