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

Skip to content

Commit d823fd1

Browse files
committed
JS: Fix join orders and use SourceNode API in React model
1 parent 255424c commit d823fd1

1 file changed

Lines changed: 18 additions & 13 deletions

File tree

  • javascript/ql/src/semmle/javascript/frameworks

javascript/ql/src/semmle/javascript/frameworks/React.qll

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ abstract class ReactComponent extends ASTNode {
4949
*/
5050
abstract DataFlow::SourceNode getAComponentCreatorReference();
5151

52+
/**
53+
* Gets a reference to an instance of this component.
54+
*/
55+
pragma[noinline]
56+
DataFlow::SourceNode getAnInstanceReference() { result = ref() }
57+
5258
/**
5359
* Gets a reference to this component.
5460
*/
@@ -70,20 +76,19 @@ abstract class ReactComponent extends ASTNode {
7076
* Gets an access to the `state` object of this component.
7177
*/
7278
DataFlow::SourceNode getADirectStateAccess() {
73-
result.(DataFlow::PropRef).accesses(ref(), "state")
79+
result = getAnInstanceReference().getAPropertyReference("state")
7480
}
7581

7682
/**
7783
* Gets a data flow node that reads a prop of this component.
7884
*/
79-
DataFlow::PropRead getAPropRead() { getADirectPropsAccess().flowsTo(result.getBase()) }
85+
DataFlow::PropRead getAPropRead() { result = getADirectPropsAccess().getAPropertyRead() }
8086

8187
/**
8288
* Gets a data flow node that reads prop `name` of this component.
8389
*/
8490
DataFlow::PropRead getAPropRead(string name) {
85-
result = getAPropRead() and
86-
result.getPropertyName() = name
91+
result = getADirectPropsAccess().getAPropertyRead(name)
8792
}
8893

8994
/**
@@ -93,7 +98,7 @@ abstract class ReactComponent extends ASTNode {
9398
DataFlow::SourceNode getAStateAccess() {
9499
result = getADirectStateAccess()
95100
or
96-
exists(DataFlow::PropRef prn | result = prn | getAStateAccess().flowsTo(prn.getBase()))
101+
result = getAStateAccess().getAPropertyReference()
97102
}
98103

99104
/**
@@ -116,18 +121,17 @@ abstract class ReactComponent extends ASTNode {
116121
/**
117122
* Gets a call to method `name` on this component.
118123
*/
119-
DataFlow::MethodCallNode getAMethodCall(string name) { result.calls(ref(), name) }
124+
DataFlow::MethodCallNode getAMethodCall(string name) {
125+
result = getAnInstanceReference().getAMethodCall(name)
126+
}
120127

121128
/**
122129
* Gets a value that will become (part of) the state
123130
* object of this component, for example an assignment to `this.state`.
124131
*/
125132
DataFlow::SourceNode getACandidateStateSource() {
126-
exists(DataFlow::PropWrite pwn, DataFlow::Node rhs |
127-
// a direct definition: `this.state = o`
128-
result.flowsTo(rhs) and
129-
pwn.writes(ref(), "state", rhs)
130-
)
133+
// a direct definition: `this.state = o`
134+
result = getAnInstanceReference().getAPropertySource("state")
131135
or
132136
exists(DataFlow::MethodCallNode mce, DataFlow::SourceNode arg0 |
133137
mce = getAMethodCall("setState") or
@@ -314,7 +318,8 @@ abstract private class SharedReactPreactClassComponent extends ReactComponent, C
314318
}
315319

316320
override DataFlow::SourceNode getADirectPropsAccess() {
317-
result.(DataFlow::PropRef).accesses(ref(), "props") or
321+
result = getAnInstanceReference().getAPropertyRead("props")
322+
or
318323
result = DataFlow::parameterNode(getConstructor().getBody().getParameter(0))
319324
}
320325

@@ -437,7 +442,7 @@ class ES5Component extends ReactComponent, ObjectExpr {
437442
override Function getStaticMethod(string name) { none() }
438443

439444
override DataFlow::SourceNode getADirectPropsAccess() {
440-
result.(DataFlow::PropRef).accesses(ref(), "props")
445+
result = getAnInstanceReference().getAPropertyRead("props")
441446
}
442447

443448
override AbstractValue getAbstractComponent() { result = TAbstractObjectLiteral(this) }

0 commit comments

Comments
 (0)