Draft
Conversation
…r better node expansion control
…feature/builder_functionalities
… enhanced interactivity
…ing for builder components
… builder components
…oved styling management
…nced style management
| await fs.mkdir(generatedDir, { recursive: true }); | ||
|
|
||
| // Write or replace the per-page CSS file | ||
| await fs.writeFile(targetCssPath, css, "utf8"); |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 months ago
To mitigate this vulnerability, server-side validation of fileName must be performed before constructing and using any file path based on it. The best way to fix this is to ensure that the generated path (after joining generatedDir and fileName and normalizing) is still inside generatedDir, preventing path traversal. Steps:
- Use
path.resolveto combinegeneratedDirandfileName, producing an absolute, normalized path. - Ensure that the resolved path begins with the absolute path for
generatedDir(for example, usingstartsWith). - If the check fails, return an error and do not use the path.
- Optionally, add a regex check to ensure
fileNameis a "safe" filename (e.g., only alphanumerics, dashes, underscore, .css extension)—but the path containment check is more general and robust.
Modify only the section between lines 24 and 30 ofsrc/feature/builder/actions/cssActions.ts.
No additional dependencies are needed; all can be done with Node.js built-inpath.
Suggested changeset
1
src/feature/builder/actions/cssActions.ts
| @@ -21,7 +21,12 @@ | ||
| const appDir = path.join(cwd, "src", "app"); | ||
| const generatedDir = path.join(appDir, "generated"); | ||
| const generated = path.join(appDir, "generated.css"); | ||
| const targetCssPath = path.join(generatedDir, fileName); | ||
| // Compute target CSS path and validate it to prevent path traversal | ||
| const targetCssPath = path.resolve(generatedDir, fileName); | ||
| // Ensure resulting path is within generatedDir | ||
| if (!targetCssPath.startsWith(path.resolve(generatedDir) + path.sep)) { | ||
| return { ok: false, error: "Invalid file name" }; | ||
| } | ||
|
|
||
| // Ensure generated directory exists | ||
| await fs.mkdir(generatedDir, { recursive: true }); |
Copilot is powered by AI and may make mistakes. Always verify output.
…rove width resolution
… useCssGeneration
…ComponentRenderer
…ved margin/padding updates
…eader and usePageFooter
…th breakpoint support
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.
No description provided.