Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion extensions/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"dependencies": {
"@sentry/profiling-node": "^9.43.0",
"fdir": "^6.4.2",
"find-up": "^8.0.0",
"fzf": "^0.5.2",
"js-yaml": "^4.1.1"
},
Expand Down Expand Up @@ -87,6 +88,7 @@
"@vitest/ui": "^3.2.4",
"@workos-inc/node": "^7.45.0",
"chalk": "^5.4.1",
"clipboardy": "^4.0.0",
"commander": "^14.0.0",
"conventional-changelog-conventionalcommits": "^9.1.0",
"core": "file:../../core",
Expand All @@ -100,7 +102,6 @@
"eslint-plugin-import": "^2.32.0",
"eslint-plugin-unused-imports": "^4.1.4",
"execa": "^9.6.0",
"clipboardy": "^4.0.0",
"express": "^5.1.0",
"glob": "^11.0.3",
"gpt-tokenizer": "^3.0.1",
Expand Down
19 changes: 19 additions & 0 deletions extensions/cli/src/tools/searchCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,26 @@ import * as fs from "fs";
import * as util from "util";

import { ContinueError, ContinueErrorReason } from "core/util/errors.js";
import { findUp } from "find-up";

import { Tool } from "./types.js";

const execPromise = util.promisify(child_process.exec);

async function getGitignorePatterns() {
const gitIgnorePath = await findUp(".gitignore");
if (!gitIgnorePath) return [];
const content = fs.readFileSync(gitIgnorePath, "utf-8");
const ignorePatterns = [];
for (let line of content.trim().split("\n")) {
line = line.trim();
if (line.startsWith("#") || line === "") continue; // ignore comments and empty line
if (line.startsWith("!")) continue; // ignore negated ignores
ignorePatterns.push(line);
}
return ignorePatterns;
}

// Default maximum number of results to display
const DEFAULT_MAX_RESULTS = 100;
const MAX_LINE_LENGTH = 1000;
Expand Down Expand Up @@ -70,6 +85,10 @@ export const searchCodeTool: Tool = {
command += ` -g "${args.file_pattern}"`;
}

for (const ignorePattern of await getGitignorePatterns()) {
command += ` -g "!${ignorePattern}"`;
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Nov 6, 2025

Choose a reason for hiding this comment

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

Sanitize the .gitignore-derived glob before interpolating it into the shell command (or switch to a non-shell exec routine) to prevent command injection.

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

<comment>Sanitize the .gitignore-derived glob before interpolating it into the shell command (or switch to a non-shell exec routine) to prevent command injection.</comment>

<file context>
@@ -69,8 +84,13 @@ export const searchCodeTool: Tool = {
     }
 
+    for (const ignorePattern of await getGitignorePatterns()) {
+      command += ` -g &quot;!${ignorePattern}&quot;`;
+    }
+
</file context>
Fix with Cubic

}

command += ` "${searchPath}"`;
try {
const { stdout, stderr } = await execPromise(command);
Expand Down
Loading