Skip to content

Feature/builder functionalities#162

Draft
JMauclair wants to merge 44 commits intomainfrom
feature/builder_functionalities
Draft

Feature/builder functionalities#162
JMauclair wants to merge 44 commits intomainfrom
feature/builder_functionalities

Conversation

@JMauclair
Copy link
Contributor

No description provided.

@JMauclair JMauclair marked this pull request as draft November 5, 2025 17:36
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

This path depends on a
user-provided value
.

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:

  1. Use path.resolve to combine generatedDir and fileName, producing an absolute, normalized path.
  2. Ensure that the resolved path begins with the absolute path for generatedDir (for example, using startsWith).
  3. If the check fails, return an error and do not use the path.
  4. Optionally, add a regex check to ensure fileName is 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 of src/feature/builder/actions/cssActions.ts.
    No additional dependencies are needed; all can be done with Node.js built-in path.

Suggested changeset 1
src/feature/builder/actions/cssActions.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/feature/builder/actions/cssActions.ts b/src/feature/builder/actions/cssActions.ts
--- a/src/feature/builder/actions/cssActions.ts
+++ b/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 });
EOF
@@ -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.
JMauclair and others added 16 commits November 6, 2025 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant