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

Skip to content

Commit 6b05aa1

Browse files
committed
JS: Use global access paths to recognize .prototype
1 parent 61034be commit 6b05aa1

1 file changed

Lines changed: 26 additions & 8 deletions

File tree

  • javascript/ql/src/semmle/javascript/dataflow

javascript/ql/src/semmle/javascript/dataflow/Nodes.qll

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,12 @@ module ClassNode {
844844
override DataFlow::Node getASuperClassNode() { result = astNode.getSuperClass().flow() }
845845
}
846846

847+
private DataFlow::PropRef getAPrototypeReferenceInFile(string name, File f) {
848+
GlobalAccessPath::getAccessPath(result.getBase()) = name and
849+
result.getPropertyName() = "prototype" and
850+
result.getFile() = f
851+
}
852+
847853
/**
848854
* A function definition with prototype manipulation as a `ClassNode` instance.
849855
*/
@@ -854,9 +860,16 @@ module ClassNode {
854860

855861
FunctionStyleClass() {
856862
function.getFunction() = astNode and
857-
exists(DataFlow::PropRef read |
858-
read.getPropertyName() = "prototype" and
859-
read.getBase().analyze().getAValue() = function
863+
(
864+
exists (DataFlow::PropRef read |
865+
read.getPropertyName() = "prototype" and
866+
read.getBase().analyze().getAValue() = function
867+
)
868+
or
869+
exists(string name |
870+
name = GlobalAccessPath::fromRhs(this) and
871+
exists(getAPrototypeReferenceInFile(name, getFile()))
872+
)
860873
)
861874
}
862875

@@ -916,11 +929,16 @@ module ClassNode {
916929
result = base.getAPropertyRead("prototype")
917930
or
918931
result = base.getAPropertySource("prototype")
919-
or
920-
exists(ExtendCall call |
921-
call.getDestinationOperand() = base.getAPropertyRead("prototype") and
922-
result = call.getASourceOperand()
923-
)
932+
)
933+
or
934+
exists(string name |
935+
GlobalAccessPath::fromRhs(this) = name and
936+
result = getAPrototypeReferenceInFile(name, getFile())
937+
)
938+
or
939+
exists(ExtendCall call |
940+
call.getDestinationOperand() = getAPrototypeReference() and
941+
result = call.getASourceOperand()
924942
)
925943
}
926944

0 commit comments

Comments
 (0)