-
Notifications
You must be signed in to change notification settings - Fork 1.9k
JS: React-relay support #18858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
JS: React-relay support #18858
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1e3b862
Added a test case where useFragment from react-relay should be marked…
Napalys 1443f31
Added react-relay useFragment as threat model source.
Napalys 0166e76
Add change note
Napalys 89040d0
Added missing `response` and `request` MaD source kinds.
Napalys 5a1991b
Added test cases for `react-relay` functions that retrieve data
Napalys c12c12c
Added modeling for `react-relay` functions that retrieve data.
Napalys d077d68
Applied changes from comments
Napalys File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| category: minorAnalysis | ||
| --- | ||
| * Added support for the `react-relay` library. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| extensions: | ||
| - addsTo: | ||
| pack: codeql/javascript-all | ||
| extensible: sourceModel | ||
| data: | ||
| - ["react-relay", "Member[useFragment].ReturnValue", "response"] | ||
| - ["react-relay", "Member[useLazyLoadQuery].ReturnValue", "response"] | ||
| - ["react-relay", "Member[usePreloadedQuery].ReturnValue", "response"] | ||
| - ["react-relay", "Member[useClientQuery].ReturnValue", "response"] | ||
| - ["react-relay", "Member[useRefetchableFragment].ReturnValue.Member[0]", "response"] | ||
| - ["react-relay", "Member[usePaginationFragment].ReturnValue.Member[data]", "response"] | ||
| - ["react-relay", "Member[useMutation].ReturnValue.Member[0].Argument[0].Member[onCompleted].Parameter[0]", "response"] | ||
| - ["react-relay", "Member[useSubscription].Argument[0].Member[onNext].Parameter[0]", "response"] | ||
| - ["react-relay", "Member[fetchQuery].ReturnValue.Member[subscribe].Argument[0].Member[next].Parameter[0]", "response"] | ||
| - ["relay-runtime", "Member[readFragment].ReturnValue", "response"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
...ipt/ql/test/query-tests/Security/CWE-079/DomBasedXssWithResponseThreat/testReactRelay.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| import React, { useState } from "react"; | ||
| import { useFragment } from 'react-relay'; | ||
|
|
||
| const func1 = ({ commentRef, query }) => { | ||
| const commentData = useFragment(query, commentRef); // $ Source=[js/xss] | ||
| return ( | ||
| <p dangerouslySetInnerHTML={{ __html: commentData.text }}> // $ Alert=[js/xss] | ||
| {" "} | ||
| {commentData.text} | ||
| </p> | ||
| ); | ||
| }; | ||
|
|
||
| import { useLazyLoadQuery } from "react-relay"; | ||
|
|
||
| function func2({ query }) { | ||
| const data = useLazyLoadQuery(query, {}); // $ Source | ||
| return <p dangerouslySetInnerHTML={{ __html: data.comments[0].text }} />; // $ Alert | ||
| } | ||
|
|
||
| import { useQueryLoader, usePreloadedQuery } from "react-relay"; | ||
|
|
||
| function func3({ initialQueryRef, query }) { | ||
| const [queryReference, loadQuery] = useQueryLoader(query, initialQueryRef); | ||
| return ( | ||
| <h1 | ||
| dangerouslySetInnerHTML={{ | ||
| __html: usePreloadedQuery(query, queryReference).user?.name, // $ Alert | ||
| }} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| import { useClientQuery } from "react-relay"; | ||
|
|
||
| function func4({ query }) { | ||
| const data = useClientQuery(query, {}); // $ Source | ||
| return <h1 dangerouslySetInnerHTML={{ __html: data }} />; // $ Alert | ||
| } | ||
|
|
||
| import { useRefetchableFragment } from "react-relay"; | ||
|
|
||
| function func5({ query, props }) { | ||
| const [data, refetch] = useRefetchableFragment(query, props.comment); // $ Source | ||
| return ( | ||
| <> | ||
| <h1 dangerouslySetInnerHTML={{ __html: data }} /> // $ Alert | ||
| <h1 dangerouslySetInnerHTML={{ __html: refetch }} /> | ||
| <Button | ||
| onClick={() => { | ||
| refetch({ lang: "SPANISH" }, { fetchPolicy: "store-or-network" }); | ||
| }} | ||
| ></Button> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| import { usePaginationFragment } from "react-relay"; | ||
|
|
||
| function func6({ query }) { | ||
| const { | ||
| data, // $ Source | ||
| loadNext, | ||
| loadPrevious, | ||
| hasNext, | ||
| hasPrevious, | ||
| isLoadingNext, | ||
| isLoadingPrevious, | ||
| refetch, | ||
| } = usePaginationFragment(query, {}); | ||
| return <h1 dangerouslySetInnerHTML={{ __html: data }} />; // $ Alert | ||
| } | ||
|
|
||
|
|
||
| import { useMutation } from 'react-relay'; | ||
| import type { FeedbackLikeMutation } from './FeedbackLikeMutation.graphql'; | ||
|
|
||
| function func7(query) { | ||
| const [commit, inFlight] = useMutation<FeedbackLikeMutation>(query); | ||
| const [feedbackText, setFeedbackText] = useState(''); | ||
|
|
||
| commit({ | ||
| onCompleted(data) { // $ Source | ||
| setFeedbackText(data); | ||
| }, | ||
| }); | ||
|
|
||
| return (<div dangerouslySetInnerHTML={{__html: feedbackText, }}/>); // $ Alert | ||
| } | ||
|
|
||
| import { useSubscription } from 'react-relay'; | ||
| import { useMemo } from 'react'; | ||
|
|
||
| function func8({GroupLessonsSubscription}) { | ||
| const [fragmentRef, setFragmentRef] = useState(); | ||
|
|
||
| const groupLessonConfig = useMemo(() => ({ | ||
| subscription: GroupLessonsSubscription, | ||
| variables: {}, | ||
| onNext: (res) => { // $ Source | ||
| setFragmentRef(res); | ||
| }, | ||
| onError: (err) => { | ||
| console.error('Error with subscription:', err); | ||
| }, | ||
| onCompleted: () => { | ||
| console.log('Subscription completed'); | ||
| }, | ||
| }), []); | ||
|
|
||
| useSubscription(groupLessonConfig); | ||
|
|
||
| return (<div dangerouslySetInnerHTML={{__html: fragmentRef, }}/>); // $ Alert | ||
| } | ||
|
|
||
|
|
||
| import { fetchQuery } from 'react-relay' | ||
|
|
||
| function func9({query, environment}) { | ||
| fetchQuery(environment, query,{id: 4},).subscribe({ | ||
| start: () => {}, | ||
| complete: () => {}, | ||
| error: (error) => {}, | ||
| next: (data) => { // $ Source | ||
| const outputElement = document.getElementById('output'); | ||
| if (outputElement) { | ||
| outputElement.innerHTML = data.user; // $ Alert | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| import { readFragment } from "relay-runtime"; | ||
|
|
||
| function func10({ query, key }) { | ||
| const data = readFragment(query, key); // $ Source | ||
| return (<h1 dangerouslySetInnerHTML={{ __html: data }} />); // $ Alert | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.