Skip to content

Conversation

@RomneyDa
Copy link
Collaborator

@RomneyDa RomneyDa commented Sep 25, 2025

Description

remake of #7795


Summary by cubic

Fixes listFiles tool to handle relative paths safely and predictably. Resolves dirpath against the current working directory, blocks "../", validates the directory early, and simplifies run.

  • Bug Fixes
    • Normalize and reject paths containing ".." to prevent directory traversal.
    • Resolve dirpath to an absolute path using process.cwd().
    • Validate existence and directory in preprocess; throw clear errors.
    • Update preview to show resolved path and remove duplicate checks in run.

@RomneyDa RomneyDa requested a review from a team as a code owner September 25, 2025 22:27
@RomneyDa RomneyDa requested review from sestinj and removed request for a team September 25, 2025 22:27
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Sep 25, 2025
@github-actions
Copy link

⚠️ AI review completed but no review output was generated. Check the action logs for details.


💡 To request a new review, comment @continue-general-review

@github-actions
Copy link

AI Code Review

AI review failed due to service initialization issues. Please check the Continue API key and configuration.

No specific line comments generated.


💡 To request a new detailed review, comment @continue-detailed-review

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 1 file

Prompt for AI agents (all 3 issues)

Understand the root cause of the following 3 issues and fix them.


<file name="extensions/cli/src/tools/listFiles.ts">

<violation number="1" location="extensions/cli/src/tools/listFiles.ts:27">
Using includes(&quot;..&quot;) can cause false positives; prefer checking for parent traversal via startsWith(&quot;..&quot;) (or a project-root relative check).</violation>

<violation number="2" location="extensions/cli/src/tools/listFiles.ts:27">
Path validation allows absolute paths outside project and falsely blocks valid names containing &quot;..&quot;</violation>

<violation number="3" location="extensions/cli/src/tools/listFiles.ts:34">
Absolute paths can escape the project root; ensure dirPath stays within process.cwd() to prevent directory traversal.</violation>
</file>

React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.

preprocess: async (args) => {
// Prevent "../"
const normalizedPath = path.normalize(args.dirpath);
if (normalizedPath.includes("..")) {
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using includes("..") can cause false positives; prefer checking for parent traversal via startsWith("..") (or a project-root relative check).

Prompt for AI agents
Address the following comment on extensions/cli/src/tools/listFiles.ts at line 27:

<comment>Using includes(&quot;..&quot;) can cause false positives; prefer checking for parent traversal via startsWith(&quot;..&quot;) (or a project-root relative check).</comment>

<file context>
@@ -22,28 +22,41 @@ export const listFilesTool: Tool = {
   preprocess: async (args) =&gt; {
+    // Prevent &quot;../&quot;
+    const normalizedPath = path.normalize(args.dirpath);
+    if (normalizedPath.includes(&quot;..&quot;)) {
+      throw new Error(
+        &#39;For security reasons, cannot use &quot;../&quot; in dirPath. Stay within the project.&#39;,
</file context>

✅ Addressed in 3841322

preprocess: async (args) => {
// Prevent "../"
const normalizedPath = path.normalize(args.dirpath);
if (normalizedPath.includes("..")) {
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Path validation allows absolute paths outside project and falsely blocks valid names containing ".."

Prompt for AI agents
Address the following comment on extensions/cli/src/tools/listFiles.ts at line 27:

<comment>Path validation allows absolute paths outside project and falsely blocks valid names containing &quot;..&quot;</comment>

<file context>
@@ -22,28 +22,41 @@ export const listFilesTool: Tool = {
   preprocess: async (args) =&gt; {
+    // Prevent &quot;../&quot;
+    const normalizedPath = path.normalize(args.dirpath);
+    if (normalizedPath.includes(&quot;..&quot;)) {
+      throw new Error(
+        &#39;For security reasons, cannot use &quot;../&quot; in dirPath. Stay within the project.&#39;,
</file context>
Fix with Cubic

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Sep 25, 2025
@github-project-automation github-project-automation bot moved this from Todo to In Progress in Issues and PRs Sep 25, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Sep 25, 2025
@Patrick-Erichsen Patrick-Erichsen merged commit 4bf7e6d into main Sep 25, 2025
56 checks passed
@Patrick-Erichsen Patrick-Erichsen deleted the dallin/ls-tool-relative branch September 25, 2025 23:19
@github-project-automation github-project-automation bot moved this from In Progress to Done in Issues and PRs Sep 25, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Sep 25, 2025
@sestinj
Copy link
Contributor

sestinj commented Sep 26, 2025

🎉 This PR is included in version 1.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@sestinj
Copy link
Contributor

sestinj commented Sep 26, 2025

🎉 This PR is included in version 1.22.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@sestinj
Copy link
Contributor

sestinj commented Oct 1, 2025

🎉 This PR is included in version 1.21.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

lgtm This PR has been approved by a maintainer released size:S This PR changes 10-29 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants