JS: Fix project layout detection for Next.js apps#20911
Merged
asgerf merged 3 commits intogithub:mainfrom Nov 26, 2025
Merged
Conversation
Some parts of the code did not handle case where 'pages' was located at 'app/pages'.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in the Next.js model where server-side taint sources in the app/pages folder were not being detected. The fix centralizes the logic for locating Next.js special folders (pages, api, etc.) and ensures all folder structure variations are supported, including src/ prefixes and the app/pages configuration.
Key Changes:
- Added helper predicates (
packageRoot(),srcRoot(),appRoot(),pagesRoot(),apiRoot()) to systematically locate Next.js folders across different project layouts - Updated
getAPagesFolder()andapiFolder()to use the new centralized logic instead of hardcoded paths - Added test case demonstrating the fix for
app/pages/folder detection
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
javascript/ql/lib/semmle/javascript/frameworks/Next.qll |
Refactored folder detection logic with new helper predicates to support all Next.js project layout variations |
javascript/ql/test/query-tests/Security/CWE-079/ReflectedXss/app/pages/Next2.jsx |
Added test case to verify XSS detection in app/pages/ folder structure |
javascript/ql/test/query-tests/Security/CWE-079/ReflectedXss/ReflectedXss.expected |
Updated test expectations with new alerts from app/pages/Next2.jsx |
javascript/ql/test/query-tests/Security/CWE-079/ReflectedXss/ReflectedXssWithCustomSanitizer.expected |
Updated test expectations with new alerts from app/pages/Next2.jsx |
javascript/ql/src/change-notes/2025-11-25-nextjs-project-layout.md |
Documented the bug fix for app/pages folder detection |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In a Next.js app, a folder named
pageshas significant meaning, and it seems this folder can appear in different places. Some parts of the model did not support the locationapp/pages(and other parts did). This PR fixes that and ensures all parts of the model share the logic for how to locate such folders.