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

Skip to content

Commit e847043

Browse files
committed
JS: Move React steps into React library
1 parent 6324c4f commit e847043

2 files changed

Lines changed: 43 additions & 43 deletions

File tree

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

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -582,49 +582,6 @@ module TaintTracking {
582582
}
583583
}
584584

585-
/**
586-
* A taint propagating data flow edge for assignments of the form `c1.state.p = v`,
587-
* where `c1` is an instance of React component `C`; in this case, we consider
588-
* taint to flow from `v` to any read of `c2.state.p`, where `c2`
589-
* also is an instance of `C`.
590-
*/
591-
private class ReactComponentStateTaintStep extends SharedTaintStep {
592-
override predicate viewComponentStep(DataFlow::Node pred, DataFlow::Node succ) {
593-
exists(ReactComponent c, DataFlow::PropRead prn, DataFlow::PropWrite pwn |
594-
(
595-
c.getACandidateStateSource().flowsTo(pwn.getBase()) or
596-
c.getADirectStateAccess().flowsTo(pwn.getBase())
597-
) and
598-
(
599-
c.getAPreviousStateSource().flowsTo(prn.getBase()) or
600-
c.getADirectStateAccess().flowsTo(prn.getBase())
601-
)
602-
|
603-
prn.getPropertyName() = pwn.getPropertyName() and
604-
succ = prn and
605-
pred = pwn.getRhs()
606-
)
607-
}
608-
}
609-
610-
/**
611-
* A taint propagating data flow edge for assignments of the form `c1.props.p = v`,
612-
* where `c1` is an instance of React component `C`; in this case, we consider
613-
* taint to flow from `v` to any read of `c2.props.p`, where `c2`
614-
* also is an instance of `C`.
615-
*/
616-
private class ReactComponentPropsTaintStep extends SharedTaintStep {
617-
override predicate viewComponentStep(DataFlow::Node pred, DataFlow::Node succ) {
618-
exists(ReactComponent c, string name, DataFlow::PropRead prn |
619-
prn = c.getAPropRead(name) or
620-
prn = c.getAPreviousPropsSource().getAPropertyRead(name)
621-
|
622-
pred = c.getACandidatePropsValue(name) and
623-
succ = prn
624-
)
625-
}
626-
}
627-
628585
/**
629586
* A taint propagating data flow edge arising from string concatenations.
630587
*

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,3 +795,46 @@ private class HigherOrderComponentStep extends PreCallGraphStep {
795795
)
796796
}
797797
}
798+
799+
/**
800+
* A taint propagating data flow edge for assignments of the form `c1.state.p = v`,
801+
* where `c1` is an instance of React component `C`; in this case, we consider
802+
* taint to flow from `v` to any read of `c2.state.p`, where `c2`
803+
* also is an instance of `C`.
804+
*/
805+
private class StateTaintStep extends TaintTracking::SharedTaintStep {
806+
override predicate viewComponentStep(DataFlow::Node pred, DataFlow::Node succ) {
807+
exists(ReactComponent c, DataFlow::PropRead prn, DataFlow::PropWrite pwn |
808+
(
809+
c.getACandidateStateSource().flowsTo(pwn.getBase()) or
810+
c.getADirectStateAccess().flowsTo(pwn.getBase())
811+
) and
812+
(
813+
c.getAPreviousStateSource().flowsTo(prn.getBase()) or
814+
c.getADirectStateAccess().flowsTo(prn.getBase())
815+
)
816+
|
817+
prn.getPropertyName() = pwn.getPropertyName() and
818+
succ = prn and
819+
pred = pwn.getRhs()
820+
)
821+
}
822+
}
823+
824+
/**
825+
* A taint propagating data flow edge for assignments of the form `c1.props.p = v`,
826+
* where `c1` is an instance of React component `C`; in this case, we consider
827+
* taint to flow from `v` to any read of `c2.props.p`, where `c2`
828+
* also is an instance of `C`.
829+
*/
830+
private class PropsTaintStep extends TaintTracking::SharedTaintStep {
831+
override predicate viewComponentStep(DataFlow::Node pred, DataFlow::Node succ) {
832+
exists(ReactComponent c, string name, DataFlow::PropRead prn |
833+
prn = c.getAPropRead(name) or
834+
prn = c.getAPreviousPropsSource().getAPropertyRead(name)
835+
|
836+
pred = c.getACandidatePropsValue(name) and
837+
succ = prn
838+
)
839+
}
840+
}

0 commit comments

Comments
 (0)