-
Notifications
You must be signed in to change notification settings - Fork 2k
JS: Support for Request and NextRequest
#19184
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 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
81cba7f
Added test cases with missing alerts for `Request` and `NextRequest`.
Napalys 63a3953
Enhance Next.js API endpoint handling for compatibility with both Pag…
Napalys 8acb024
Added test cases for `NextResponse` and `Response`
Napalys 86b64af
Added `NextResponse` to the `ResponseCall` class it models similar ne…
Napalys 208487f
Added `middleware` test
Napalys 734ad2d
Removed legacy `Consistency` check as it is redundant now with inline…
Napalys 6e09a65
Added support for `NextRequest` `middleware` SSRF.
Napalys 8674b61
Added SSRF test case with `searchParams` for `NextRequest`
Napalys 678eccb
Added `searchParams.get` as potential source for SSRF
Napalys 2c4b352
Added change note
Napalys 92e4f11
Update javascript/ql/lib/semmle/javascript/frameworks/Next.qll
Napalys 11abbf8
Now `nextUrl` is of type `parameter` and loosen the restriction for `…
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,5 @@ | ||
| --- | ||
| category: minorAnalysis | ||
| --- | ||
| * Data passed to the [NextResponse](https://nextjs.org/docs/app/api-reference/functions/next-response) constructor is now treated as a sink for `js/reflected-xss`. | ||
| * Data received from [NextRequest](https://nextjs.org/docs/app/api-reference/functions/next-request) and [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) is now treated as a remote user input `source`. |
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
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
30 changes: 30 additions & 0 deletions
30
javascript/ql/test/query-tests/Security/CWE-079/ReflectedXss/app/api/route.ts
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,30 @@ | ||
| export async function POST(req: Request) { | ||
| const body = await req.json(); // $ Source | ||
|
|
||
| new Response(body, {headers: { 'Content-Type': 'application/json' }}); | ||
| new Response(body, {headers: { 'Content-Type': 'text/html' }}); // $ Alert | ||
|
|
||
| const headers2 = new Headers(req.headers); | ||
| headers2.append('Content-Type', 'application/json'); | ||
| new Response(body, { headers: headers2 }); | ||
|
|
||
| const headers3 = new Headers(req.headers); | ||
| headers3.append('Content-Type', 'text/html'); | ||
| new Response(body, { headers: headers3 }); // $ Alert | ||
|
|
||
| const headers4 = new Headers({ | ||
| ...Object.fromEntries(req.headers), | ||
| 'Content-Type': 'application/json' | ||
| }); | ||
| new Response(body, { headers: headers4 }); | ||
|
|
||
| const headers5 = new Headers({ | ||
| ...Object.fromEntries(req.headers), | ||
| 'Content-Type': 'text/html' | ||
| }); | ||
| new Response(body, { headers: headers5 }); // $ Alert | ||
|
|
||
| const headers = new Headers(req.headers); | ||
| headers.set('Content-Type', 'text/html'); | ||
| return new Response(body, { headers }); // $ Alert | ||
| } |
32 changes: 32 additions & 0 deletions
32
javascript/ql/test/query-tests/Security/CWE-079/ReflectedXss/app/api/routeNextRequest.ts
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,32 @@ | ||
| import { NextRequest, NextResponse } from 'next/server'; | ||
|
|
||
| export async function POST(req: NextRequest) { | ||
| const body = await req.json(); // $ Source | ||
|
|
||
| new NextResponse(body, {headers: { 'Content-Type': 'application/json' }}); | ||
| new NextResponse(body, {headers: { 'Content-Type': 'text/html' }}); // $ Alert | ||
|
|
||
| const headers2 = new Headers(req.headers); | ||
| headers2.append('Content-Type', 'application/json'); | ||
| new NextResponse(body, { headers: headers2 }); | ||
|
|
||
| const headers3 = new Headers(req.headers); | ||
| headers3.append('Content-Type', 'text/html'); | ||
| new NextResponse(body, { headers: headers3 }); // $ Alert | ||
|
|
||
| const headers4 = new Headers({ | ||
| ...Object.fromEntries(req.headers), | ||
| 'Content-Type': 'application/json' | ||
| }); | ||
| new NextResponse(body, { headers: headers4 }); | ||
|
|
||
| const headers5 = new Headers({ | ||
| ...Object.fromEntries(req.headers), | ||
| 'Content-Type': 'text/html' | ||
| }); | ||
| new NextResponse(body, { headers: headers5 }); // $ Alert | ||
|
|
||
| const headers = new Headers(req.headers); | ||
| headers.set('Content-Type', 'text/html'); | ||
| return new NextResponse(body, { headers }); // $ Alert | ||
| } |
2 changes: 0 additions & 2 deletions
2
javascript/ql/test/query-tests/Security/CWE-918/Consistency.expected
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
javascript/ql/test/query-tests/Security/CWE-918/Consistency.ql
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
javascript/ql/test/query-tests/Security/CWE-918/Request/app/api/proxy/route.serverSide.ts
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,5 @@ | ||
| export async function POST(req: Request) { | ||
| const { url } = await req.json(); // $ Source[js/request-forgery] | ||
| const res = await fetch(url); // $ Alert[js/request-forgery] Sink[js/request-forgery] | ||
| return new Response(res.body, { headers: res.headers }); | ||
| } |
8 changes: 8 additions & 0 deletions
8
javascript/ql/test/query-tests/Security/CWE-918/Request/app/api/proxy/route2.serverSide.ts
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,8 @@ | ||
| import { NextRequest, NextResponse } from 'next/server'; | ||
|
|
||
| export async function POST(req: NextRequest) { | ||
| const { url } = await req.json(); // $ Source[js/request-forgery] | ||
| const res = await fetch(url); // $ Alert[js/request-forgery] Sink[js/request-forgery] | ||
| const data = await res.text(); | ||
| return new NextResponse(data, { headers: res.headers }); | ||
| } |
18 changes: 18 additions & 0 deletions
18
javascript/ql/test/query-tests/Security/CWE-918/Request/middleware.ts
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,18 @@ | ||
| import { NextRequest, NextResponse } from 'next/server'; | ||
|
|
||
| export async function middleware(req: NextRequest) { | ||
| const target = req.nextUrl // $ Source[js/request-forgery] | ||
| const target2 = target.searchParams.get('target'); // $ Source[js/request-forgery] | ||
| if (target) { | ||
| const res = await fetch(target) // $ Alert[js/request-forgery] Sink[js/request-forgery] | ||
| const data = await res.text() | ||
| return new NextResponse(data) | ||
| } | ||
| if (target2) { | ||
| const res = await fetch(target2); // $ Alert[js/request-forgery] Sink[js/request-forgery] | ||
| const data = await res.text(); | ||
| return new NextResponse(data); | ||
| } | ||
| return NextResponse.next() | ||
| } | ||
|
|
13 changes: 13 additions & 0 deletions
13
javascript/ql/test/query-tests/Security/CWE-918/Request/package.json
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,13 @@ | ||
| { | ||
| "name": "next-edge-proxy-app", | ||
| "version": "0.1.0", | ||
| "private": true, | ||
| "scripts": { | ||
| "dev": "next dev", | ||
| "build": "next build", | ||
| "start": "next start" | ||
| }, | ||
| "dependencies": { | ||
| "next": "15.1.7" | ||
| } | ||
| } |
Oops, something went wrong.
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.