Skip to content

Commit dd6db16

Browse files
knewbury01asgerf
authored andcommitted
Add DomValueSource for react useRef output (object's prop named current)
1 parent 9534188 commit dd6db16

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
22
category: minorAnalysis
33
---
4-
* Added PreCallGraphStep flow model for React's `useRef` hook.
4+
* Added `PreCallGraphStep` flow model for React's `useRef` hook.
5+
* Added a `DomValueSource` that uses the `current` property off the object returned by React's `useRef` hook.

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,16 @@ private class ReactRouterLocationSource extends DOM::LocationSource::Range {
804804
}
805805
}
806806

807+
private class UseRefDomValueSource extends DOM::DomValueSource::Range {
808+
UseRefDomValueSource() {
809+
exists(DataFlow::PropRead current, UseRefStep step, string prop | current = this |
810+
step.step(_, current) and
811+
current.mayHavePropertyName(prop) and
812+
prop = "current"
813+
)
814+
}
815+
}
816+
807817
/**
808818
* Gets a reference to a function which, if called with a React component, returns wrapped
809819
* version of that component, which we model as a direct reference to the underlying component.

0 commit comments

Comments
 (0)