-
Notifications
You must be signed in to change notification settings - Fork 1.9k
JS: Support 'response' threat model and @tanstack/react-query #18834
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
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
05690c2
Added a test for tanstack/react-query useQuery
Napalys 1227a7e
Add Tanstack framework support and enhance data flow tracking for fet…
Napalys ab0241c
Added missing doc strings for Tanstack queries
Napalys 3587ba5
Add change note and added tanstack to supported framework list
Napalys e2927b2
Updated tanstack to use API graph.
Napalys bf77ffe
Applied comment
Napalys 3360829
Updated change note with `response` threat model info.
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 `useQuery` hook from `@tanstack/react-query`. | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
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
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
26 changes: 26 additions & 0 deletions
26
javascript/ql/lib/semmle/javascript/frameworks/Tanstack.qll
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,26 @@ | ||
| /** | ||
| * Provides classes and predicates modeling the Tanstack/react-query library. | ||
| */ | ||
|
|
||
| private import javascript | ||
|
|
||
| /** | ||
| * An additional flow step that propagates data from the return value of the query function, | ||
| * defined in a useQuery call from the '@tanstack/react-query' module, to the 'data' property. | ||
| */ | ||
| private class TanstackStep extends DataFlow::AdditionalFlowStep { | ||
| override predicate step(DataFlow::Node node1, DataFlow::Node node2) { | ||
| exists(API::CallNode useQuery | | ||
| useQuery = useQueryCall() and | ||
| node1 = useQuery.getParameter(0).getMember("queryFn").getReturn().getPromised().asSink() and | ||
| node2 = useQuery.getReturn().getMember("data").asSource() | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves a call node representing a useQuery invocation from the '@tanstack/react-query' module. | ||
| */ | ||
| private API::CallNode useQueryCall() { | ||
| result = API::moduleImport("@tanstack/react-query").getMember("useQuery").getACall() | ||
| } |
24 changes: 24 additions & 0 deletions
24
javascript/ql/test/query-tests/Security/CWE-079/DomBasedXssWithResponseThreat/Xss.expected
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,24 @@ | ||
| #select | ||
| | test.jsx:27:29:27:32 | data | test.jsx:5:28:5:63 | fetch(" ... ntent") | test.jsx:27:29:27:32 | data | Cross-site scripting vulnerability due to $@. | test.jsx:5:28:5:63 | fetch(" ... ntent") | user-provided value | | ||
| edges | ||
| | test.jsx:5:11:5:63 | response | test.jsx:6:24:6:31 | response | provenance | | | ||
| | test.jsx:5:22:5:63 | await f ... ntent") | test.jsx:5:11:5:63 | response | provenance | | | ||
| | test.jsx:5:28:5:63 | fetch(" ... ntent") | test.jsx:5:22:5:63 | await f ... ntent") | provenance | | | ||
| | test.jsx:6:11:6:38 | data | test.jsx:7:12:7:15 | data | provenance | | | ||
| | test.jsx:6:18:6:38 | await r ... .json() | test.jsx:6:11:6:38 | data | provenance | | | ||
| | test.jsx:6:24:6:31 | response | test.jsx:6:24:6:38 | response.json() | provenance | | | ||
| | test.jsx:6:24:6:38 | response.json() | test.jsx:6:18:6:38 | await r ... .json() | provenance | | | ||
| | test.jsx:7:12:7:15 | data | test.jsx:15:11:17:5 | data | provenance | | | ||
| | test.jsx:15:11:17:5 | data | test.jsx:27:29:27:32 | data | provenance | | | ||
| nodes | ||
| | test.jsx:5:11:5:63 | response | semmle.label | response | | ||
| | test.jsx:5:22:5:63 | await f ... ntent") | semmle.label | await f ... ntent") | | ||
| | test.jsx:5:28:5:63 | fetch(" ... ntent") | semmle.label | fetch(" ... ntent") | | ||
| | test.jsx:6:11:6:38 | data | semmle.label | data | | ||
| | test.jsx:6:18:6:38 | await r ... .json() | semmle.label | await r ... .json() | | ||
| | test.jsx:6:24:6:31 | response | semmle.label | response | | ||
| | test.jsx:6:24:6:38 | response.json() | semmle.label | response.json() | | ||
| | test.jsx:7:12:7:15 | data | semmle.label | data | | ||
| | test.jsx:15:11:17:5 | data | semmle.label | data | | ||
| | test.jsx:27:29:27:32 | data | semmle.label | data | | ||
| subpaths |
6 changes: 6 additions & 0 deletions
6
javascript/ql/test/query-tests/Security/CWE-079/DomBasedXssWithResponseThreat/Xss.ext.yml
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,6 @@ | ||
| extensions: | ||
| - addsTo: | ||
| pack: codeql/threat-models | ||
| extensible: threatModelConfiguration | ||
| data: | ||
| - ["response", true, 0] |
2 changes: 2 additions & 0 deletions
2
javascript/ql/test/query-tests/Security/CWE-079/DomBasedXssWithResponseThreat/Xss.qlref
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,2 @@ | ||
| query: Security/CWE-079/Xss.ql | ||
| postprocess: utils/test/InlineExpectationsTestQuery.ql |
34 changes: 34 additions & 0 deletions
34
javascript/ql/test/query-tests/Security/CWE-079/DomBasedXssWithResponseThreat/test.jsx
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,34 @@ | ||
| import React from "react"; | ||
| import { useQuery } from "./wrapper"; | ||
|
|
||
| const fetchContent = async () => { | ||
| const response = await fetch("https://example.com/content"); // $ Source[js/xss] | ||
| const data = await response.json(); | ||
| return data; | ||
| }; | ||
|
|
||
| const getQueryOptions = () => { | ||
| return {queryFn: fetchContent}; | ||
| } | ||
|
|
||
| const ContentWithDangerousHtml = () => { | ||
| const { data, error, isLoading } = useQuery( | ||
| getQueryOptions() | ||
| ); | ||
|
|
||
| if (isLoading) return <div>Loading...</div>; | ||
| if (error) return <div>Error fetching content!</div>; | ||
|
|
||
| return ( | ||
| <div> | ||
| <h1>Content with Dangerous HTML</h1> | ||
| <div | ||
| dangerouslySetInnerHTML={{ | ||
| __html: data, // $ Alert[js/xss] | ||
| }} | ||
| /> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default ContentWithDangerousHtml; |
2 changes: 2 additions & 0 deletions
2
javascript/ql/test/query-tests/Security/CWE-079/DomBasedXssWithResponseThreat/wrapper.js
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,2 @@ | ||
| import { useQuery } from "@tanstack/react-query"; | ||
| export { useQuery } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.