Merge branch 'main' into nate/more-warnings-fixes
This commit is contained in:
commit
7dfb58bf37
37 changed files with 1028 additions and 82 deletions
16
.github/workflows/cli-pr-checks.yml
vendored
16
.github/workflows/cli-pr-checks.yml
vendored
|
|
@ -25,6 +25,14 @@ jobs:
|
|||
cache: "npm"
|
||||
cache-dependency-path: extensions/cli/package-lock.json
|
||||
|
||||
- name: Setup packages
|
||||
uses: ./.github/actions/setup-packages
|
||||
- name: Setup core component
|
||||
uses: ./.github/actions/setup-component
|
||||
with:
|
||||
component: core
|
||||
include-root: true
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
cd extensions/cli
|
||||
|
|
@ -53,6 +61,14 @@ jobs:
|
|||
cache: "npm"
|
||||
cache-dependency-path: extensions/cli/package-lock.json
|
||||
|
||||
- name: Setup packages
|
||||
uses: ./.github/actions/setup-packages
|
||||
- name: Setup core component
|
||||
uses: ./.github/actions/setup-component
|
||||
with:
|
||||
component: core
|
||||
include-root: true
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
cd extensions/cli
|
||||
|
|
|
|||
8
.github/workflows/jetbrains-release.yaml
vendored
8
.github/workflows/jetbrains-release.yaml
vendored
|
|
@ -120,7 +120,7 @@ jobs:
|
|||
|
||||
# # Set up Java environment for the next steps
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: zulu
|
||||
java-version: 17
|
||||
|
|
@ -433,7 +433,7 @@ jobs:
|
|||
|
||||
# Set up Java environment for the next steps
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: zulu
|
||||
java-version: 17
|
||||
|
|
@ -486,7 +486,7 @@ jobs:
|
|||
|
||||
# Set up Java environment for the next steps
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: zulu
|
||||
java-version: 17
|
||||
|
|
@ -517,7 +517,7 @@ jobs:
|
|||
|
||||
# Set up Java environment for the next steps
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: zulu
|
||||
java-version: 17
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ jobs:
|
|||
- name: Checkout sources
|
||||
uses: actions/checkout@v5
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: "temurin"
|
||||
java-version: 17
|
||||
|
|
|
|||
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
|
@ -42,7 +42,8 @@
|
|||
"extensions/vscode/e2e/_output": true,
|
||||
"extensions/vscode/e2e/storage": true,
|
||||
"extensions/vscode/e2e/vsix": true,
|
||||
"extensions/.continue-debug": true
|
||||
"extensions/.continue-debug": true,
|
||||
"extensions/cli/dist/**": true
|
||||
// "sync/**": true
|
||||
},
|
||||
"editor.formatOnSave": true,
|
||||
|
|
|
|||
2
binary/package-lock.json
generated
2
binary/package-lock.json
generated
|
|
@ -83,7 +83,7 @@
|
|||
"http-proxy-agent": "^7.0.1",
|
||||
"https-proxy-agent": "^7.0.3",
|
||||
"iconv-lite": "^0.6.3",
|
||||
"ignore": "^5.3.1",
|
||||
"ignore": "^7.0.5",
|
||||
"is-localhost-ip": "^2.0.0",
|
||||
"jinja-js": "0.1.8",
|
||||
"js-tiktoken": "^1.0.8",
|
||||
|
|
|
|||
|
|
@ -6,12 +6,13 @@ import { DEFAULT_AUTOCOMPLETE_OPTS } from "../util/parameters.js";
|
|||
import { shouldCompleteMultiline } from "./classification/shouldCompleteMultiline.js";
|
||||
import { ContextRetrievalService } from "./context/ContextRetrievalService.js";
|
||||
|
||||
import { isSecurityConcern } from "../indexing/ignore.js";
|
||||
import { BracketMatchingService } from "./filtering/BracketMatchingService.js";
|
||||
import { CompletionStreamer } from "./generation/CompletionStreamer.js";
|
||||
import { postprocessCompletion } from "./postprocessing/index.js";
|
||||
import { shouldPrefilter } from "./prefiltering/index.js";
|
||||
import { renderPromptWithTokenLimit } from "./templating/index.js";
|
||||
import { getAllSnippetsWithoutRace } from "./snippets/index.js";
|
||||
import { renderPromptWithTokenLimit } from "./templating/index.js";
|
||||
import { GetLspDefinitionsFunction } from "./types.js";
|
||||
import { AutocompleteDebouncer } from "./util/AutocompleteDebouncer.js";
|
||||
import { AutocompleteLoggingService } from "./util/AutocompleteLoggingService.js";
|
||||
|
|
@ -150,6 +151,10 @@ export class CompletionProvider {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
if (isSecurityConcern(input.filepath)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const options = await this._getAutocompleteOptions(llm);
|
||||
|
||||
// Debounce
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { IDE } from "../..";
|
|||
import {
|
||||
getGlobalContinueIgArray,
|
||||
getWorkspaceContinueIgArray,
|
||||
} from "../../indexing/ignore";
|
||||
} from "../../indexing/continueignore";
|
||||
import { getConfigJsonPath } from "../../util/paths";
|
||||
import { findUriInDirs } from "../../util/uri";
|
||||
import { HelperVars } from "../util/HelperVars";
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
import ignore from "ignore";
|
||||
|
||||
import type { FileType, IDE, SlashCommand } from "../../..";
|
||||
import {
|
||||
DEFAULT_IGNORE,
|
||||
getGlobalContinueIgArray,
|
||||
gitIgArrayFromFile,
|
||||
} from "../../../indexing/ignore";
|
||||
import { getGlobalContinueIgArray } from "../../../indexing/continueignore";
|
||||
import { DEFAULT_IGNORE, gitIgArrayFromFile } from "../../../indexing/ignore";
|
||||
import { renderChatMessage } from "../../../util/messageContent";
|
||||
import {
|
||||
findUriInDirs,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import {
|
|||
ContextSubmenuItem,
|
||||
LoadSubmenuItemsArgs,
|
||||
} from "../../";
|
||||
import { isSecurityConcern } from "../../indexing/ignore";
|
||||
import { walkDirs } from "../../indexing/walkDir";
|
||||
import {
|
||||
getShortestUniqueRelativeUriPaths,
|
||||
|
|
@ -36,6 +37,21 @@ class FileContextProvider extends BaseContextProvider {
|
|||
await extras.ide.getWorkspaceDirs(),
|
||||
);
|
||||
|
||||
if (isSecurityConcern(relativePathOrBasename)) {
|
||||
return [
|
||||
{
|
||||
description: last2Parts,
|
||||
content:
|
||||
"Content redacted, this file cannot be viewed for security reasons",
|
||||
name: baseName,
|
||||
uri: {
|
||||
type: "file",
|
||||
value: fileUri,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
name: baseName,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import {
|
|||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
} from "../../index.js";
|
||||
import { isSecurityConcern } from "../../indexing/ignore.js";
|
||||
import { getUriDescription } from "../../util/uri.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
|
||||
|
|
@ -27,10 +28,23 @@ class OpenFilesContextProvider extends BaseContextProvider {
|
|||
|
||||
return await Promise.all(
|
||||
openFiles.map(async (filepath: string) => {
|
||||
const content = await ide.readFile(filepath);
|
||||
const { relativePathOrBasename, last2Parts, baseName } =
|
||||
getUriDescription(filepath, workspaceDirs);
|
||||
|
||||
if (isSecurityConcern(filepath)) {
|
||||
return {
|
||||
description: last2Parts,
|
||||
content:
|
||||
"Content redacted, this file cannot be viewed for security reasons",
|
||||
name: baseName,
|
||||
uri: {
|
||||
type: "file",
|
||||
value: filepath,
|
||||
},
|
||||
};
|
||||
}
|
||||
const content = await ide.readFile(filepath);
|
||||
|
||||
return {
|
||||
description: last2Parts,
|
||||
content: `\`\`\`${relativePathOrBasename}\n${content}\n\`\`\``,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import {
|
|||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
} from "../../index.js";
|
||||
import { isSecurityConcern } from "../../indexing/ignore.js";
|
||||
import { getUriDescription } from "../../util/uri.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
|
||||
|
|
@ -28,6 +29,14 @@ class ProblemsContextProvider extends BaseContextProvider {
|
|||
problem.filepath,
|
||||
workspaceDirs,
|
||||
);
|
||||
if (isSecurityConcern(relativePathOrBasename)) {
|
||||
return {
|
||||
description: "Problems in current file",
|
||||
content:
|
||||
"Content was redacted because the file is detected as a potential security concern",
|
||||
name: `Warnings in ${baseName}`,
|
||||
};
|
||||
}
|
||||
const content = await ide.readFile(problem.filepath);
|
||||
const lines = content.split("\n");
|
||||
const rangeContent = lines
|
||||
|
|
@ -40,7 +49,7 @@ class ProblemsContextProvider extends BaseContextProvider {
|
|||
return {
|
||||
description: "Problems in current file",
|
||||
content: `\`\`\`${relativePathOrBasename}\n${rangeContent}\n\`\`\`\n${problem.message}\n\n`,
|
||||
name: `Warning in ${baseName}`,
|
||||
name: `Warnings in ${baseName}`,
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
|
|
|||
26
core/indexing/continueignore.ts
Normal file
26
core/indexing/continueignore.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import fs from "fs";
|
||||
import { IDE } from "..";
|
||||
import { getGlobalContinueIgnorePath } from "../util/paths";
|
||||
import { gitIgArrayFromFile } from "./ignore";
|
||||
|
||||
export const getGlobalContinueIgArray = () => {
|
||||
const contents = fs.readFileSync(getGlobalContinueIgnorePath(), "utf8");
|
||||
return gitIgArrayFromFile(contents);
|
||||
};
|
||||
|
||||
export const getWorkspaceContinueIgArray = async (ide: IDE) => {
|
||||
const dirs = await ide.getWorkspaceDirs();
|
||||
return await dirs.reduce(
|
||||
async (accPromise, dir) => {
|
||||
const acc = await accPromise;
|
||||
try {
|
||||
const contents = await ide.readFile(`${dir}/.continueignore`);
|
||||
return [...acc, ...gitIgArrayFromFile(contents)];
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return acc;
|
||||
}
|
||||
},
|
||||
Promise.resolve([] as string[]),
|
||||
);
|
||||
};
|
||||
|
|
@ -1,11 +1,108 @@
|
|||
import fs from "fs";
|
||||
|
||||
import ignore from "ignore";
|
||||
|
||||
import { IDE } from "..";
|
||||
import { getGlobalContinueIgnorePath } from "../util/paths";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
export const DEFAULT_IGNORE_FILETYPES = [
|
||||
// Security-focused ignore patterns - these should always be excluded for security reasons
|
||||
export const DEFAULT_SECURITY_IGNORE_FILETYPES = [
|
||||
// Environment and configuration files with secrets
|
||||
"*.env",
|
||||
"*.env.*",
|
||||
".env*",
|
||||
"config.json",
|
||||
"config.yaml",
|
||||
"config.yml",
|
||||
"settings.json",
|
||||
"appsettings.json",
|
||||
"appsettings.*.json",
|
||||
|
||||
// Certificate and key files
|
||||
"*.key",
|
||||
"*.pem",
|
||||
"*.p12",
|
||||
"*.pfx",
|
||||
"*.crt",
|
||||
"*.cer",
|
||||
"*.jks",
|
||||
"*.keystore",
|
||||
"*.truststore",
|
||||
|
||||
// Database files that may contain sensitive data
|
||||
"*.db",
|
||||
"*.sqlite",
|
||||
"*.sqlite3",
|
||||
"*.mdb",
|
||||
"*.accdb",
|
||||
|
||||
// Credential and secret files
|
||||
"*.secret",
|
||||
"*.secrets",
|
||||
"credentials",
|
||||
"credentials.*",
|
||||
"auth.json",
|
||||
"token",
|
||||
"token.*",
|
||||
"*.token",
|
||||
|
||||
// Backup files that might contain sensitive data
|
||||
"*.bak",
|
||||
"*.backup",
|
||||
"*.old",
|
||||
"*.orig",
|
||||
|
||||
// Docker secrets
|
||||
"docker-compose.override.yml",
|
||||
"docker-compose.override.yaml",
|
||||
|
||||
// SSH and GPG
|
||||
"id_rsa",
|
||||
"id_dsa",
|
||||
"id_ecdsa",
|
||||
"id_ed25519",
|
||||
"*.ppk",
|
||||
"*.gpg",
|
||||
];
|
||||
|
||||
export const DEFAULT_SECURITY_IGNORE_DIRS = [
|
||||
// Environment and configuration directories
|
||||
".env/",
|
||||
"env/",
|
||||
".venv/",
|
||||
"venv/",
|
||||
|
||||
// IDE directories that may contain cached credentials
|
||||
// For now excluding, reasons for this unclear
|
||||
// ".vscode/",
|
||||
// ".idea/",
|
||||
// ".vs/",
|
||||
|
||||
// Cloud provider credential directories
|
||||
".aws/",
|
||||
".gcp/",
|
||||
".azure/",
|
||||
".kube/",
|
||||
".docker/",
|
||||
|
||||
// Secret directories
|
||||
"secrets/",
|
||||
".secrets/",
|
||||
"private/",
|
||||
".private/",
|
||||
"certs/",
|
||||
"certificates/",
|
||||
"keys/",
|
||||
".ssh/",
|
||||
".gnupg/",
|
||||
".gpg/",
|
||||
|
||||
// Temporary directories that might contain sensitive data
|
||||
"tmp/secrets/",
|
||||
"temp/secrets/",
|
||||
".tmp/",
|
||||
];
|
||||
|
||||
// Additional non-security patterns for general indexing exclusion
|
||||
export const ADDITIONAL_INDEXING_IGNORE_FILETYPES = [
|
||||
"*.DS_Store",
|
||||
"*-lock.json",
|
||||
"*.lock",
|
||||
|
|
@ -46,8 +143,6 @@ export const DEFAULT_IGNORE_FILETYPES = [
|
|||
"*.mpeg",
|
||||
"*.mov",
|
||||
"*.mp3",
|
||||
"*.mp4",
|
||||
"*.mkv",
|
||||
"*.mkv",
|
||||
"*.webm",
|
||||
"*.jar",
|
||||
|
|
@ -56,20 +151,15 @@ export const DEFAULT_IGNORE_FILETYPES = [
|
|||
"*.pqt",
|
||||
"*.wav",
|
||||
"*.webp",
|
||||
"*.db",
|
||||
"*.sqlite",
|
||||
"*.wasm",
|
||||
"*.plist",
|
||||
"*.profraw",
|
||||
"*.gcda",
|
||||
"*.gcno",
|
||||
"go.sum",
|
||||
"*.env",
|
||||
"*.gitignore",
|
||||
"*.gitkeep",
|
||||
"*.continueignore",
|
||||
"config.json",
|
||||
"config.yaml",
|
||||
"*.csv",
|
||||
"*.uasset",
|
||||
"*.pdb",
|
||||
|
|
@ -80,17 +170,9 @@ export const DEFAULT_IGNORE_FILETYPES = [
|
|||
// "*.prompt", // can be incredibly confusing for the LLM to have another set of instructions injected into the prompt
|
||||
];
|
||||
|
||||
export const defaultIgnoreFile = ignore().add(DEFAULT_IGNORE_FILETYPES);
|
||||
export const DEFAULT_IGNORE_DIRS = [
|
||||
export const ADDITIONAL_INDEXING_IGNORE_DIRS = [
|
||||
".git/",
|
||||
".svn/",
|
||||
".vscode/",
|
||||
".idea/",
|
||||
".vs/",
|
||||
"venv/",
|
||||
".venv/",
|
||||
"env/",
|
||||
".env/",
|
||||
"node_modules/",
|
||||
"dist/",
|
||||
"build/",
|
||||
|
|
@ -100,7 +182,6 @@ export const DEFAULT_IGNORE_DIRS = [
|
|||
"bin/",
|
||||
".pytest_cache/",
|
||||
".vscode-test/",
|
||||
".continue/",
|
||||
"__pycache__/",
|
||||
"site-packages/",
|
||||
".gradle/",
|
||||
|
|
@ -110,40 +191,75 @@ export const DEFAULT_IGNORE_DIRS = [
|
|||
"vendor/",
|
||||
];
|
||||
|
||||
// Combined patterns: security + additional
|
||||
export const DEFAULT_IGNORE_FILETYPES = [
|
||||
...DEFAULT_SECURITY_IGNORE_FILETYPES,
|
||||
...ADDITIONAL_INDEXING_IGNORE_FILETYPES,
|
||||
];
|
||||
|
||||
export const DEFAULT_IGNORE_DIRS = [
|
||||
...DEFAULT_SECURITY_IGNORE_DIRS,
|
||||
...ADDITIONAL_INDEXING_IGNORE_DIRS,
|
||||
];
|
||||
|
||||
// Create ignore instances
|
||||
export const defaultSecurityIgnoreFile = ignore().add(
|
||||
DEFAULT_SECURITY_IGNORE_FILETYPES,
|
||||
);
|
||||
export const defaultSecurityIgnoreDir = ignore().add(
|
||||
DEFAULT_SECURITY_IGNORE_DIRS,
|
||||
);
|
||||
export const defaultIgnoreFile = ignore().add(DEFAULT_IGNORE_FILETYPES);
|
||||
export const defaultIgnoreDir = ignore().add(DEFAULT_IGNORE_DIRS);
|
||||
|
||||
// String representations
|
||||
export const DEFAULT_SECURITY_IGNORE =
|
||||
DEFAULT_SECURITY_IGNORE_FILETYPES.join("\n") +
|
||||
"\n" +
|
||||
DEFAULT_SECURITY_IGNORE_DIRS.join("\n");
|
||||
|
||||
export const DEFAULT_IGNORE =
|
||||
DEFAULT_IGNORE_FILETYPES.join("\n") + "\n" + DEFAULT_IGNORE_DIRS.join("\n");
|
||||
|
||||
// Combined ignore instances
|
||||
export const defaultFileAndFolderSecurityIgnores = ignore()
|
||||
.add(defaultSecurityIgnoreFile)
|
||||
.add(defaultSecurityIgnoreDir);
|
||||
|
||||
export const defaultIgnoreFileAndDir = ignore()
|
||||
.add(defaultIgnoreFile)
|
||||
.add(defaultIgnoreDir);
|
||||
|
||||
export function isSecurityConcern(filePathOrUri: string) {
|
||||
if (!filePathOrUri) {
|
||||
return false;
|
||||
}
|
||||
let filepath = filePathOrUri;
|
||||
try {
|
||||
filepath = fileURLToPath(filePathOrUri);
|
||||
} catch {}
|
||||
if (path.isAbsolute(filepath)) {
|
||||
const dir = path.dirname(filepath).split(/\/|\\/).at(-1) ?? "";
|
||||
const basename = path.basename(filepath);
|
||||
filepath = `${dir ? dir + "/" : ""}${basename}`;
|
||||
}
|
||||
if (!filepath) {
|
||||
return false;
|
||||
}
|
||||
return defaultFileAndFolderSecurityIgnores.ignores(filepath);
|
||||
}
|
||||
|
||||
export function throwIfFileIsSecurityConcern(filepath: string) {
|
||||
if (isSecurityConcern(filepath)) {
|
||||
throw new Error(
|
||||
`Reading or Editing ${filepath} is not allowed because it is a security concern. Do not attempt to read or edit this file in any way.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function gitIgArrayFromFile(file: string) {
|
||||
return file
|
||||
.split(/\r?\n/) // Split on new line
|
||||
.map((l) => l.trim()) // Remove whitespace
|
||||
.filter((l) => !/^#|^$/.test(l)); // Remove empty lines
|
||||
}
|
||||
|
||||
export const getGlobalContinueIgArray = () => {
|
||||
const contents = fs.readFileSync(getGlobalContinueIgnorePath(), "utf8");
|
||||
return gitIgArrayFromFile(contents);
|
||||
};
|
||||
|
||||
export const getWorkspaceContinueIgArray = async (ide: IDE) => {
|
||||
const dirs = await ide.getWorkspaceDirs();
|
||||
return await dirs.reduce(
|
||||
async (accPromise, dir) => {
|
||||
const acc = await accPromise;
|
||||
try {
|
||||
const contents = await ide.readFile(`${dir}/.continueignore`);
|
||||
return [...acc, ...gitIgArrayFromFile(contents)];
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return acc;
|
||||
}
|
||||
},
|
||||
Promise.resolve([] as string[]),
|
||||
);
|
||||
};
|
||||
|
|
|
|||
268
core/indexing/ignore.vitest.ts
Normal file
268
core/indexing/ignore.vitest.ts
Normal file
|
|
@ -0,0 +1,268 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
DEFAULT_SECURITY_IGNORE_DIRS,
|
||||
DEFAULT_SECURITY_IGNORE_FILETYPES,
|
||||
defaultFileAndFolderSecurityIgnores,
|
||||
isSecurityConcern,
|
||||
} from "./ignore";
|
||||
|
||||
describe("isSecurityConcern", () => {
|
||||
describe("Security file types", () => {
|
||||
it("should detect environment files as security concerns", () => {
|
||||
expect(isSecurityConcern(".env")).toBe(true);
|
||||
expect(isSecurityConcern(".env.local")).toBe(true);
|
||||
expect(isSecurityConcern(".env.production")).toBe(true);
|
||||
expect(isSecurityConcern("config/.env")).toBe(true);
|
||||
expect(isSecurityConcern("/path/to/.env")).toBe(true);
|
||||
expect(isSecurityConcern("file:///path/to/.env")).toBe(true);
|
||||
});
|
||||
|
||||
it("should detect configuration files as security concerns", () => {
|
||||
expect(isSecurityConcern("config.json")).toBe(true);
|
||||
expect(isSecurityConcern("config.yaml")).toBe(true);
|
||||
expect(isSecurityConcern("config.yml")).toBe(true);
|
||||
expect(isSecurityConcern("settings.json")).toBe(true);
|
||||
expect(isSecurityConcern("appsettings.json")).toBe(true);
|
||||
expect(isSecurityConcern("appsettings.development.json")).toBe(true);
|
||||
expect(isSecurityConcern("appsettings.production.json")).toBe(true);
|
||||
});
|
||||
|
||||
it("should detect certificate and key files as security concerns", () => {
|
||||
expect(isSecurityConcern("private.key")).toBe(true);
|
||||
expect(isSecurityConcern("certificate.pem")).toBe(true);
|
||||
expect(isSecurityConcern("server.crt")).toBe(true);
|
||||
expect(isSecurityConcern("keystore.jks")).toBe(true);
|
||||
expect(isSecurityConcern("ssl/server.key")).toBe(true);
|
||||
expect(isSecurityConcern("/etc/ssl/certs/server.pem")).toBe(true);
|
||||
});
|
||||
|
||||
it("should detect database files as security concerns", () => {
|
||||
expect(isSecurityConcern("database.db")).toBe(true);
|
||||
expect(isSecurityConcern("users.sqlite")).toBe(true);
|
||||
expect(isSecurityConcern("data.sqlite3")).toBe(true);
|
||||
expect(isSecurityConcern("app.mdb")).toBe(true);
|
||||
expect(isSecurityConcern("data/users.db")).toBe(true);
|
||||
});
|
||||
|
||||
it("should detect credential files as security concerns", () => {
|
||||
expect(isSecurityConcern("app.secret")).toBe(true);
|
||||
expect(isSecurityConcern("api.secrets")).toBe(true);
|
||||
expect(isSecurityConcern("credentials")).toBe(true);
|
||||
expect(isSecurityConcern("credentials.json")).toBe(true);
|
||||
expect(isSecurityConcern("auth.json")).toBe(true);
|
||||
expect(isSecurityConcern("token")).toBe(true);
|
||||
expect(isSecurityConcern("api.token")).toBe(true);
|
||||
expect(isSecurityConcern("access.token")).toBe(true);
|
||||
});
|
||||
|
||||
it("should detect backup files as security concerns", () => {
|
||||
expect(isSecurityConcern("database.bak")).toBe(true);
|
||||
expect(isSecurityConcern("config.backup")).toBe(true);
|
||||
expect(isSecurityConcern("settings.old")).toBe(true);
|
||||
expect(isSecurityConcern("app.orig")).toBe(true);
|
||||
});
|
||||
|
||||
it("should detect Docker override files as security concerns", () => {
|
||||
expect(isSecurityConcern("docker-compose.override.yml")).toBe(true);
|
||||
expect(isSecurityConcern("docker-compose.override.yaml")).toBe(true);
|
||||
});
|
||||
|
||||
it("should detect SSH and GPG files as security concerns", () => {
|
||||
expect(isSecurityConcern("id_rsa")).toBe(true);
|
||||
expect(isSecurityConcern("id_dsa")).toBe(true);
|
||||
expect(isSecurityConcern("id_ecdsa")).toBe(true);
|
||||
expect(isSecurityConcern("id_ed25519")).toBe(true);
|
||||
expect(isSecurityConcern("private.ppk")).toBe(true);
|
||||
expect(isSecurityConcern("secret.gpg")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Security directories", () => {
|
||||
it("should detect environment directories as security concerns", () => {
|
||||
expect(isSecurityConcern(".env/")).toBe(true);
|
||||
expect(isSecurityConcern("env/")).toBe(true);
|
||||
expect(isSecurityConcern(".venv/")).toBe(true);
|
||||
expect(isSecurityConcern("venv/")).toBe(true);
|
||||
expect(isSecurityConcern(".env/config")).toBe(true);
|
||||
expect(isSecurityConcern("project/.venv/lib")).toBe(true);
|
||||
});
|
||||
|
||||
it("should detect IDE directories as security concerns", () => {
|
||||
// expect(isSecurityConcern(".vscode/")).toBe(true);
|
||||
// expect(isSecurityConcern(".idea/")).toBe(true);
|
||||
// expect(isSecurityConcern(".vs/")).toBe(true);
|
||||
expect(isSecurityConcern(".vscode/settings.json")).toBe(true);
|
||||
// expect(isSecurityConcern(".idea/workspace.xml")).toBe(true);
|
||||
});
|
||||
|
||||
it("should detect cloud provider directories as security concerns", () => {
|
||||
expect(isSecurityConcern(".aws/")).toBe(true);
|
||||
expect(isSecurityConcern(".gcp/")).toBe(true);
|
||||
expect(isSecurityConcern(".azure/")).toBe(true);
|
||||
expect(isSecurityConcern(".kube/")).toBe(true);
|
||||
expect(isSecurityConcern(".docker/")).toBe(true);
|
||||
expect(isSecurityConcern(".aws/credentials")).toBe(true);
|
||||
expect(isSecurityConcern(".kube/config")).toBe(true);
|
||||
});
|
||||
|
||||
it("should detect secret directories as security concerns", () => {
|
||||
expect(isSecurityConcern("secrets/")).toBe(true);
|
||||
expect(isSecurityConcern(".secrets/")).toBe(true);
|
||||
expect(isSecurityConcern("private/")).toBe(true);
|
||||
expect(isSecurityConcern(".private/")).toBe(true);
|
||||
expect(isSecurityConcern("certs/")).toBe(true);
|
||||
expect(isSecurityConcern("certificates/")).toBe(true);
|
||||
expect(isSecurityConcern("keys/")).toBe(true);
|
||||
expect(isSecurityConcern(".ssh/")).toBe(true);
|
||||
expect(isSecurityConcern(".gnupg/")).toBe(true);
|
||||
expect(isSecurityConcern(".gpg/")).toBe(true);
|
||||
});
|
||||
|
||||
it("should detect continue directory as security concern", () => {
|
||||
expect(isSecurityConcern(".continue/config.json")).toBe(true);
|
||||
});
|
||||
|
||||
it("should detect temporary secret directories as security concerns", () => {
|
||||
expect(isSecurityConcern("tmp/secrets/")).toBe(true);
|
||||
expect(isSecurityConcern("temp/secrets/")).toBe(true);
|
||||
expect(isSecurityConcern(".tmp/")).toBe(true);
|
||||
expect(isSecurityConcern("tmp/secrets/api.key")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Path variations", () => {
|
||||
it("should handle absolute paths", () => {
|
||||
expect(isSecurityConcern("/home/user/.env")).toBe(true);
|
||||
expect(isSecurityConcern("/var/www/.secrets/")).toBe(true);
|
||||
expect(isSecurityConcern("/etc/ssl/private.key")).toBe(true);
|
||||
});
|
||||
|
||||
it("should handle URI schemes", () => {
|
||||
expect(isSecurityConcern("file:///home/user/.env")).toBe(true);
|
||||
expect(isSecurityConcern("file:///var/secrets/api.key")).toBe(true);
|
||||
});
|
||||
|
||||
it("should handle nested paths", () => {
|
||||
expect(isSecurityConcern("project/config/.env")).toBe(true);
|
||||
expect(isSecurityConcern("src/main/resources/application.secret")).toBe(
|
||||
true,
|
||||
);
|
||||
expect(isSecurityConcern("backend/certs/server.key")).toBe(true);
|
||||
});
|
||||
|
||||
// it("should handle Windows-style paths", () => {
|
||||
// expect(isSecurityConcern("C:\\Users\\user\\.env")).toBe(true);
|
||||
// expect(isSecurityConcern("D:\\projects\\app\\secrets\\")).toBe(true);
|
||||
// });
|
||||
});
|
||||
|
||||
describe("Non-security files", () => {
|
||||
it("should not flag regular source code files", () => {
|
||||
expect(isSecurityConcern("src/main.js")).toBe(false);
|
||||
expect(isSecurityConcern("components/App.tsx")).toBe(false);
|
||||
expect(isSecurityConcern("utils/helper.py")).toBe(false);
|
||||
expect(isSecurityConcern("models/User.java")).toBe(false);
|
||||
expect(isSecurityConcern("styles/main.css")).toBe(false);
|
||||
});
|
||||
|
||||
it("should not flag regular configuration files", () => {
|
||||
expect(isSecurityConcern("package.json")).toBe(false);
|
||||
expect(isSecurityConcern("tsconfig.json")).toBe(false);
|
||||
expect(isSecurityConcern("webpack.config.js")).toBe(false);
|
||||
expect(isSecurityConcern("babel.config.js")).toBe(false);
|
||||
expect(isSecurityConcern("jest.config.js")).toBe(false);
|
||||
});
|
||||
|
||||
it("should not flag documentation files", () => {
|
||||
expect(isSecurityConcern("README.md")).toBe(false);
|
||||
expect(isSecurityConcern("CHANGELOG.md")).toBe(false);
|
||||
expect(isSecurityConcern("docs/api.md")).toBe(false);
|
||||
expect(isSecurityConcern("LICENSE")).toBe(false);
|
||||
});
|
||||
|
||||
it("should not flag regular directories", () => {
|
||||
expect(isSecurityConcern("src/")).toBe(false);
|
||||
expect(isSecurityConcern("components/")).toBe(false);
|
||||
expect(isSecurityConcern("utils/")).toBe(false);
|
||||
expect(isSecurityConcern("tests/")).toBe(false);
|
||||
expect(isSecurityConcern("docs/")).toBe(false);
|
||||
});
|
||||
|
||||
it("should not flag files with similar names but different extensions", () => {
|
||||
expect(isSecurityConcern("environment.js")).toBe(false);
|
||||
expect(isSecurityConcern("config-template.json")).toBe(false);
|
||||
expect(isSecurityConcern("secret-utils.js")).toBe(false);
|
||||
expect(isSecurityConcern("token-validator.ts")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Edge cases", () => {
|
||||
it("should handle empty strings", () => {
|
||||
expect(isSecurityConcern("")).toBe(false);
|
||||
});
|
||||
|
||||
it("should handle paths with only separators", () => {
|
||||
expect(isSecurityConcern("/")).toBe(false);
|
||||
});
|
||||
|
||||
it("should handle paths with multiple extensions", () => {
|
||||
expect(isSecurityConcern("backup.env.old")).toBe(true); // matches *.old
|
||||
expect(isSecurityConcern("config.json.bak")).toBe(true); // matches *.bak
|
||||
expect(isSecurityConcern("server.key.backup")).toBe(true); // matches *.backup
|
||||
});
|
||||
|
||||
it("should handle files in root vs subdirectories", () => {
|
||||
expect(isSecurityConcern(".env")).toBe(true);
|
||||
expect(isSecurityConcern("project/.env")).toBe(true);
|
||||
expect(isSecurityConcern("deeply/nested/path/.env")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Pattern matching consistency", () => {
|
||||
it("should match all defined security file patterns", () => {
|
||||
// Test a sample from each category to ensure patterns work
|
||||
DEFAULT_SECURITY_IGNORE_FILETYPES.forEach((pattern) => {
|
||||
// Create a test file name that should match the pattern
|
||||
let testFile: string;
|
||||
if (pattern.startsWith("*.")) {
|
||||
testFile = `test${pattern.substring(1)}`;
|
||||
} else if (pattern.includes("*")) {
|
||||
testFile = pattern.replace("*", "test");
|
||||
} else {
|
||||
testFile = pattern;
|
||||
}
|
||||
|
||||
expect(isSecurityConcern(testFile)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it("should match all defined security directory patterns", () => {
|
||||
DEFAULT_SECURITY_IGNORE_DIRS.forEach((pattern) => {
|
||||
// Test the directory pattern directly
|
||||
expect(isSecurityConcern(pattern)).toBe(true);
|
||||
|
||||
// Test a file inside the directory
|
||||
const fileInDir = `${pattern}testfile.txt`;
|
||||
expect(isSecurityConcern(fileInDir)).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Integration with ignore library", () => {
|
||||
it("should use the same ignore instance as defaultFileAndFolderSecurityIgnores", () => {
|
||||
// Test that our function uses the same logic as the exported ignore instance
|
||||
const testFiles = [
|
||||
".env",
|
||||
"secrets/api.key",
|
||||
".aws/credentials",
|
||||
"regular-file.js",
|
||||
];
|
||||
|
||||
testFiles.forEach((file) => {
|
||||
const functionResult = isSecurityConcern(file);
|
||||
const ignoreResult = defaultFileAndFolderSecurityIgnores.ignores(file);
|
||||
expect(functionResult).toBe(ignoreResult);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
import ignore from "ignore";
|
||||
import type { FileType, IDE } from "../";
|
||||
import { findUriInDirs, getUriPathBasename } from "../util/uri";
|
||||
import { defaultIgnoreFileAndDir, getGlobalContinueIgArray } from "./ignore";
|
||||
import { getGlobalContinueIgArray } from "./continueignore";
|
||||
import { defaultIgnoreFileAndDir } from "./ignore";
|
||||
import { getIgnoreContext } from "./walkDir";
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -3,11 +3,8 @@ import ignore, { Ignore } from "ignore";
|
|||
import type { FileType, IDE } from "..";
|
||||
|
||||
import { joinPathsToUri } from "../util/uri";
|
||||
import {
|
||||
defaultIgnoreFileAndDir,
|
||||
getGlobalContinueIgArray,
|
||||
gitIgArrayFromFile,
|
||||
} from "./ignore";
|
||||
import { getGlobalContinueIgArray } from "./continueignore";
|
||||
import { defaultIgnoreFileAndDir, gitIgArrayFromFile } from "./ignore";
|
||||
|
||||
export interface WalkerOptions {
|
||||
include?: "dirs" | "files" | "both";
|
||||
|
|
|
|||
|
|
@ -124,6 +124,7 @@ export const PROVIDER_TOOL_SUPPORT: Record<string, (model: string) => boolean> =
|
|||
"nova-pro",
|
||||
"nova-micro",
|
||||
"nova-premier",
|
||||
"gpt-oss",
|
||||
].some((part) => model.toLowerCase().includes(part))
|
||||
) {
|
||||
return true;
|
||||
|
|
@ -302,6 +303,7 @@ export const PROVIDER_TOOL_SUPPORT: Record<string, (model: string) => boolean> =
|
|||
"meta-llama/llama-3-70b-instruct",
|
||||
"arcee-ai/caller-large",
|
||||
"nousresearch/hermes-3-llama-3.1-70b",
|
||||
"moonshotai/kimi-k2",
|
||||
];
|
||||
for (const model of specificModels) {
|
||||
if (model.toLowerCase() === model) {
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import AutocompleteLruCache from "../autocomplete/util/AutocompleteLruCache.js";
|
|||
import { HelperVars } from "../autocomplete/util/HelperVars.js";
|
||||
import { AutocompleteInput } from "../autocomplete/util/types.js";
|
||||
import { myersDiff } from "../diff/myers.js";
|
||||
import { isSecurityConcern } from "../indexing/ignore.js";
|
||||
import { modelSupportsNextEdit } from "../llm/autodetect.js";
|
||||
import { NEXT_EDIT_MODELS } from "../llm/constants.js";
|
||||
import { countTokens } from "../llm/countTokens.js";
|
||||
|
|
@ -285,6 +286,9 @@ export class NextEditProvider {
|
|||
usingFullFileDiff: boolean;
|
||||
},
|
||||
): Promise<NextEditOutcome | undefined> {
|
||||
if (isSecurityConcern(input.filepath)) {
|
||||
return undefined;
|
||||
}
|
||||
try {
|
||||
this.previousRequest = input;
|
||||
const {
|
||||
|
|
@ -715,8 +719,8 @@ export class NextEditProvider {
|
|||
// .split(`${MERCURY_CODE_TO_EDIT_OPEN}\n`)[1]
|
||||
// .replace(/\n$/, "") ?? msg.content;
|
||||
const nextCompletion = msg.content.slice(
|
||||
msg.content.indexOf("\`\`\`\n") + "\'\'\'\n".length,
|
||||
msg.content.lastIndexOf("\n\n\`\`\`"),
|
||||
msg.content.indexOf("```\n") + "'''\n".length,
|
||||
msg.content.lastIndexOf("\n\n```"),
|
||||
);
|
||||
|
||||
if (opts?.usingFullFileDiff === false || !opts?.usingFullFileDiff) {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import {
|
|||
} from "../../autocomplete/util/types";
|
||||
import { ConfigHandler } from "../../config/ConfigHandler";
|
||||
import { IDE, ILLM } from "../../index";
|
||||
import { isSecurityConcern } from "../../indexing/ignore";
|
||||
import { DEFAULT_AUTOCOMPLETE_OPTS } from "../../util/parameters";
|
||||
|
||||
/**
|
||||
|
|
@ -61,6 +62,10 @@ export const getAutocompleteContext = async (
|
|||
throw new Error("No config available");
|
||||
}
|
||||
|
||||
if (isSecurityConcern(input.filepath)) {
|
||||
throw new Error("File is a security concern, autocomplete disabled");
|
||||
}
|
||||
|
||||
// Use provided autocomplete model or fall back to configured autocomplete model
|
||||
let finalModel: ILLM;
|
||||
let modelNameForTemplating: string;
|
||||
|
|
|
|||
45
core/package-lock.json
generated
45
core/package-lock.json
generated
|
|
@ -44,7 +44,7 @@
|
|||
"http-proxy-agent": "^7.0.1",
|
||||
"https-proxy-agent": "^7.0.3",
|
||||
"iconv-lite": "^0.6.3",
|
||||
"ignore": "^5.3.1",
|
||||
"ignore": "^7.0.5",
|
||||
"is-localhost-ip": "^2.0.0",
|
||||
"jinja-js": "0.1.8",
|
||||
"js-tiktoken": "^1.0.8",
|
||||
|
|
@ -3458,6 +3458,15 @@
|
|||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/@eslint/eslintrc/node_modules/ignore": {
|
||||
"version": "5.3.2",
|
||||
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz",
|
||||
"integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 4"
|
||||
}
|
||||
},
|
||||
"node_modules/@eslint/eslintrc/node_modules/minimatch": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
|
||||
|
|
@ -7006,6 +7015,15 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/eslint-plugin/node_modules/ignore": {
|
||||
"version": "5.3.2",
|
||||
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz",
|
||||
"integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 4"
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/parser": {
|
||||
"version": "7.18.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.18.0.tgz",
|
||||
|
|
@ -10577,6 +10595,15 @@
|
|||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/eslint/node_modules/ignore": {
|
||||
"version": "5.3.2",
|
||||
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz",
|
||||
"integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 4"
|
||||
}
|
||||
},
|
||||
"node_modules/eslint/node_modules/minimatch": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
|
||||
|
|
@ -11679,6 +11706,15 @@
|
|||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/globby/node_modules/ignore": {
|
||||
"version": "5.3.2",
|
||||
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz",
|
||||
"integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 4"
|
||||
}
|
||||
},
|
||||
"node_modules/google-auth-library": {
|
||||
"version": "9.15.0",
|
||||
"resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-9.15.0.tgz",
|
||||
|
|
@ -12133,9 +12169,10 @@
|
|||
]
|
||||
},
|
||||
"node_modules/ignore": {
|
||||
"version": "5.3.2",
|
||||
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz",
|
||||
"integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==",
|
||||
"version": "7.0.5",
|
||||
"resolved": "https://registry.npmjs.org/ignore/-/ignore-7.0.5.tgz",
|
||||
"integrity": "sha512-Hs59xBNfUIunMFgWAbGX5cq6893IbWg4KnrjbYwX3tx0ztorVgTDA6B2sxf8ejHJ4wz8BqGUMYlnzNBer5NvGg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 4"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@
|
|||
"http-proxy-agent": "^7.0.1",
|
||||
"https-proxy-agent": "^7.0.3",
|
||||
"iconv-lite": "^0.6.3",
|
||||
"ignore": "^5.3.1",
|
||||
"ignore": "^7.0.5",
|
||||
"is-localhost-ip": "^2.0.0",
|
||||
"jinja-js": "0.1.8",
|
||||
"js-tiktoken": "^1.0.8",
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import ignore from "ignore";
|
||||
|
||||
import { ToolImpl } from ".";
|
||||
import { walkDir } from "../../indexing/walkDir";
|
||||
import { resolveRelativePathInDir } from "../../util/ideUtils";
|
||||
|
|
@ -27,6 +29,7 @@ export const lsToolImpl: ToolImpl = async (args, extras) => {
|
|||
returnRelativeUrisPaths: true,
|
||||
include: "both",
|
||||
recursive: args?.recursive ?? false,
|
||||
overrideDefaultIgnores: ignore(), // Show all directories including dist/, build/, etc.
|
||||
});
|
||||
|
||||
const lines = entries.slice(0, MAX_LS_TOOL_LINES);
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
import { getUriDescription } from "../../util/uri";
|
||||
|
||||
import { ToolImpl } from ".";
|
||||
import { throwIfFileIsSecurityConcern } from "../../indexing/ignore";
|
||||
import { throwIfFileExceedsHalfOfContext } from "./readFileLimit";
|
||||
|
||||
export const readCurrentlyOpenFileImpl: ToolImpl = async (args, extras) => {
|
||||
export const readCurrentlyOpenFileImpl: ToolImpl = async (_, extras) => {
|
||||
const result = await extras.ide.getCurrentFile();
|
||||
|
||||
if (result) {
|
||||
throwIfFileIsSecurityConcern(result.path);
|
||||
await throwIfFileExceedsHalfOfContext(
|
||||
result.path,
|
||||
result.contents,
|
||||
|
|
|
|||
|
|
@ -2,11 +2,13 @@ import { resolveRelativePathInDir } from "../../util/ideUtils";
|
|||
import { getUriPathBasename } from "../../util/uri";
|
||||
|
||||
import { ToolImpl } from ".";
|
||||
import { throwIfFileIsSecurityConcern } from "../../indexing/ignore";
|
||||
import { getStringArg } from "../parseArgs";
|
||||
import { throwIfFileExceedsHalfOfContext } from "./readFileLimit";
|
||||
|
||||
export const readFileImpl: ToolImpl = async (args, extras) => {
|
||||
const filepath = getStringArg(args, "filepath");
|
||||
throwIfFileIsSecurityConcern(filepath);
|
||||
|
||||
const firstUriMatch = await resolveRelativePathInDir(filepath, extras.ide);
|
||||
if (!firstUriMatch) {
|
||||
|
|
|
|||
15
extensions/cli/package-lock.json
generated
15
extensions/cli/package-lock.json
generated
|
|
@ -29,6 +29,7 @@
|
|||
"@workos-inc/node": "^7.45.0",
|
||||
"chalk": "^5.4.1",
|
||||
"commander": "^14.0.0",
|
||||
"core": "file:../../core",
|
||||
"date-fns": "^4.1.0",
|
||||
"diff": "^7.0.0",
|
||||
"dotenv": "^16.5.0",
|
||||
|
|
@ -36,6 +37,7 @@
|
|||
"glob": "^11.0.3",
|
||||
"gpt-tokenizer": "^3.0.1",
|
||||
"gradient-string": "^3.0.0",
|
||||
"ignore": "^7.0.5",
|
||||
"ignore-walk": "^7.0.0",
|
||||
"ink": "^6.1.0",
|
||||
"jszip": "^3.10.1",
|
||||
|
|
@ -51,6 +53,7 @@
|
|||
"swr": "^2.3.4",
|
||||
"turndown": "^7.2.0",
|
||||
"typescript": "^5.8.3",
|
||||
"uri-js": "^4.4.1",
|
||||
"uuid": "^9.0.1",
|
||||
"winston": "^3.17.0",
|
||||
"yaml": "^2.8.0"
|
||||
|
|
@ -6935,6 +6938,10 @@
|
|||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/core": {
|
||||
"resolved": "../../core",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/core-util-is": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
|
||||
|
|
@ -8842,14 +8849,15 @@
|
|||
}
|
||||
},
|
||||
"node_modules/form-data": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.2.tgz",
|
||||
"integrity": "sha512-hGfm/slu0ZabnNt4oaRZ6uREyfCj6P4fT/n6A1rGV+Z0VdGXjfOhVUpkn6qVQONHGIFwmveGXyDs75+nr6FM8w==",
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.4.tgz",
|
||||
"integrity": "sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.8",
|
||||
"es-set-tostringtag": "^2.1.0",
|
||||
"hasown": "^2.0.2",
|
||||
"mime-types": "^2.1.12"
|
||||
},
|
||||
"engines": {
|
||||
|
|
@ -9628,7 +9636,6 @@
|
|||
"version": "7.0.5",
|
||||
"resolved": "https://registry.npmjs.org/ignore/-/ignore-7.0.5.tgz",
|
||||
"integrity": "sha512-Hs59xBNfUIunMFgWAbGX5cq6893IbWg4KnrjbYwX3tx0ztorVgTDA6B2sxf8ejHJ4wz8BqGUMYlnzNBer5NvGg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 4"
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@
|
|||
"@workos-inc/node": "^7.45.0",
|
||||
"chalk": "^5.4.1",
|
||||
"commander": "^14.0.0",
|
||||
"core": "file:../../core",
|
||||
"date-fns": "^4.1.0",
|
||||
"diff": "^7.0.0",
|
||||
"dotenv": "^16.5.0",
|
||||
|
|
@ -71,6 +72,7 @@
|
|||
"glob": "^11.0.3",
|
||||
"gpt-tokenizer": "^3.0.1",
|
||||
"gradient-string": "^3.0.0",
|
||||
"ignore": "^7.0.5",
|
||||
"ignore-walk": "^7.0.0",
|
||||
"ink": "^6.1.0",
|
||||
"jszip": "^3.10.1",
|
||||
|
|
@ -86,6 +88,7 @@
|
|||
"swr": "^2.3.4",
|
||||
"turndown": "^7.2.0",
|
||||
"typescript": "^5.8.3",
|
||||
"uri-js": "^4.4.1",
|
||||
"uuid": "^9.0.1",
|
||||
"winston": "^3.17.0",
|
||||
"yaml": "^2.8.0"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import * as fs from "fs";
|
||||
|
||||
import { throwIfFileIsSecurityConcern } from "core/indexing/ignore.js";
|
||||
|
||||
import { telemetryService } from "../telemetry/telemetryService.js";
|
||||
import {
|
||||
calculateLinesOfCodeDiff,
|
||||
|
|
@ -80,7 +82,7 @@ parameter is useful if you want to rename a variable for instance.`,
|
|||
new_string,
|
||||
replace_all = false,
|
||||
} = args as EditArgs;
|
||||
|
||||
throwIfFileIsSecurityConcern(file_path);
|
||||
// Check if file has been read
|
||||
if (!readFilesSet.has(file_path)) {
|
||||
throw new Error(
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
|
||||
import { throwIfFileIsSecurityConcern } from "core/indexing/ignore.js";
|
||||
|
||||
import { telemetryService } from "../telemetry/telemetryService.js";
|
||||
import {
|
||||
calculateLinesOfCodeDiff,
|
||||
|
|
@ -237,6 +239,8 @@ If you want to create a new file, use:
|
|||
// Validate and extract arguments
|
||||
const { original_path, file_path, edits } = validateMultiEditArgs(args);
|
||||
|
||||
throwIfFileIsSecurityConcern(file_path);
|
||||
|
||||
// Validate each edit operation
|
||||
validateEdits(edits);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import * as fs from "fs";
|
||||
|
||||
import { throwIfFileIsSecurityConcern } from "core/indexing/ignore.js";
|
||||
|
||||
import { markFileAsRead } from "./edit.js";
|
||||
import { formatToolArgument } from "./formatters.js";
|
||||
import { Tool } from "./types.js";
|
||||
|
|
@ -18,6 +20,7 @@ export const readFileTool: Tool = {
|
|||
readonly: true,
|
||||
isBuiltIn: true,
|
||||
preprocess: async (args) => {
|
||||
throwIfFileIsSecurityConcern(args.filepath);
|
||||
return {
|
||||
args,
|
||||
preview: [
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import * as fs from "fs";
|
||||
|
||||
import { throwIfFileIsSecurityConcern } from "core/indexing/ignore.js";
|
||||
|
||||
import { telemetryService } from "../../telemetry/telemetryService.js";
|
||||
import {
|
||||
calculateLinesOfCodeDiff,
|
||||
|
|
@ -95,7 +97,7 @@ Each string in the diffs array can contain multiple SEARCH/REPLACE blocks, and a
|
|||
preprocess: async (args) => {
|
||||
// Get and validate args
|
||||
const { filepath, diffs } = parseSearchAndReplaceArgs(args);
|
||||
|
||||
throwIfFileIsSecurityConcern(filepath);
|
||||
// Get current file contents
|
||||
if (!fs.existsSync(filepath)) {
|
||||
throw new Error(`file ${filepath} does not exist`);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { type AssistantConfig } from "@continuedev/sdk";
|
||||
import { throwIfFileIsSecurityConcern } from "core/indexing/ignore.js";
|
||||
import { Box, Text, useApp, useInput } from "ink";
|
||||
import React, { useCallback, useState } from "react";
|
||||
|
||||
|
|
@ -265,6 +266,7 @@ const UserInput: React.FC<UserInputProps> = ({
|
|||
// Read the file content and notify parent component
|
||||
if (onFileAttached) {
|
||||
try {
|
||||
throwIfFileIsSecurityConcern(filePath);
|
||||
const fs = await import("fs/promises");
|
||||
const content = await fs.readFile(filePath, "utf-8");
|
||||
onFileAttached(filePath, content);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
pluginGroup=com.github.continuedev.continueintellijextension
|
||||
pluginVersion=1.0.38
|
||||
pluginVersion=1.0.39
|
||||
platformVersion=2024.1
|
||||
kotlin.stdlib.default.dependency=false
|
||||
org.gradle.configuration-cache=true
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"name": "continue",
|
||||
"icon": "media/icon.png",
|
||||
"author": "Continue Dev, Inc",
|
||||
"version": "1.1.79",
|
||||
"version": "1.1.80",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/continuedev/continue"
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import {
|
|||
AutocompleteCodeSnippet,
|
||||
AutocompleteSnippetType,
|
||||
} from "core/autocomplete/snippets/types";
|
||||
import { isSecurityConcern } from "core/indexing/ignore";
|
||||
import { PosthogFeatureFlag, Telemetry } from "core/util/posthog";
|
||||
import { LRUCache } from "lru-cache";
|
||||
import * as vscode from "vscode";
|
||||
|
|
@ -51,6 +52,10 @@ export class RecentlyVisitedRangesService {
|
|||
private cacheCurrentSelectionContext = async (
|
||||
event: vscode.TextEditorSelectionChangeEvent,
|
||||
) => {
|
||||
const fsPath = event.textEditor.document.fileName;
|
||||
if (isSecurityConcern(fsPath)) {
|
||||
return;
|
||||
}
|
||||
const filepath = event.textEditor.document.uri.toString();
|
||||
const line = event.selections[0].active.line;
|
||||
const startLine = Math.max(0, line - this.numSurroundingLines);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,218 @@
|
|||
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { SecureImageComponent } from "./SecureImageComponent";
|
||||
|
||||
describe("SecureImageComponent", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe("Default blocking behavior", () => {
|
||||
it("should block images by default and show warning message", () => {
|
||||
render(<SecureImageComponent src="https://example.com/image.jpg" />);
|
||||
|
||||
expect(
|
||||
screen.getByText(
|
||||
/Image blocked for security.*External images can leak data/,
|
||||
),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByText("Load Image")).toBeInTheDocument();
|
||||
expect(screen.queryByRole("img")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should display the image URL", () => {
|
||||
const testUrl = "https://example.com/test-image.png";
|
||||
render(<SecureImageComponent src={testUrl} />);
|
||||
|
||||
expect(screen.getByText(testUrl)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should handle invalid src prop", () => {
|
||||
render(<SecureImageComponent src={undefined} />);
|
||||
|
||||
expect(
|
||||
screen.getByText("[Invalid image: no source]"),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.queryByText("Load Image")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Query parameter detection", () => {
|
||||
it("should detect and display query parameters", () => {
|
||||
render(
|
||||
<SecureImageComponent src="https://example.com/image.jpg?user=123&token=abc" />,
|
||||
);
|
||||
|
||||
expect(
|
||||
screen.getByText(/Warning: URL contains query parameters/),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByText(/"user": "123"/)).toBeInTheDocument();
|
||||
expect(screen.getByText(/"token": "abc"/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should not show query parameter warning for URLs without parameters", () => {
|
||||
render(<SecureImageComponent src="https://example.com/image.jpg" />);
|
||||
|
||||
expect(
|
||||
screen.queryByText(/Warning: URL contains query parameters/),
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should handle relative URLs with query parameters", () => {
|
||||
render(
|
||||
<SecureImageComponent src="/images/test.jpg?id=456&session=xyz" />,
|
||||
);
|
||||
|
||||
expect(
|
||||
screen.getByText(/Warning: URL contains query parameters/),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByText(/"id": "456"/)).toBeInTheDocument();
|
||||
expect(screen.getByText(/"session": "xyz"/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should handle malformed URLs gracefully", () => {
|
||||
render(<SecureImageComponent src="not-a-valid-url://image" />);
|
||||
|
||||
// Should still display the URL even if it can't be parsed
|
||||
expect(screen.getByText("not-a-valid-url://image")).toBeInTheDocument();
|
||||
expect(screen.getByText("Load Image")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("User interaction", () => {
|
||||
it("should show image when Load Image button is clicked", () => {
|
||||
const testUrl = "https://example.com/image.jpg";
|
||||
render(<SecureImageComponent src={testUrl} alt="Test image" />);
|
||||
|
||||
// Initially no image
|
||||
expect(screen.queryByRole("img")).not.toBeInTheDocument();
|
||||
|
||||
// Click load button
|
||||
const loadButton = screen.getByText("Load Image");
|
||||
fireEvent.click(loadButton);
|
||||
|
||||
// Image should now be displayed (query by tag since it might be role="presentation")
|
||||
const image = screen.getByAltText("Test image");
|
||||
expect(image).toBeInTheDocument();
|
||||
expect(image).toHaveAttribute("src", testUrl);
|
||||
expect(image).toHaveAttribute("alt", "Test image");
|
||||
|
||||
// Warning message should be gone
|
||||
expect(
|
||||
screen.queryByText(
|
||||
/Image blocked for security.*External images can leak data/,
|
||||
),
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should handle image load errors", async () => {
|
||||
const testUrl = "https://example.com/broken-image.jpg";
|
||||
render(<SecureImageComponent src={testUrl} alt="broken image" />);
|
||||
|
||||
// Click load button
|
||||
const loadButton = screen.getByText("Load Image");
|
||||
fireEvent.click(loadButton);
|
||||
|
||||
// Simulate image error (query by alt text since role might be presentation)
|
||||
const image = screen.getByAltText("broken image");
|
||||
fireEvent.error(image);
|
||||
|
||||
// Should show error message and hide image
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText(/Failed to load image/)).toBeInTheDocument();
|
||||
expect(screen.queryByAltText("broken image")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
// Load button should be available again
|
||||
expect(screen.getByText("Load Image")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should pass through title and className props", () => {
|
||||
render(
|
||||
<SecureImageComponent
|
||||
src="https://example.com/image.jpg"
|
||||
alt="test image"
|
||||
title="Image title"
|
||||
className="custom-class"
|
||||
/>,
|
||||
);
|
||||
|
||||
// Click load button
|
||||
fireEvent.click(screen.getByText("Load Image"));
|
||||
|
||||
// Check image has title (query by alt text)
|
||||
const image = screen.getByAltText("test image");
|
||||
expect(image).toHaveAttribute("title", "Image title");
|
||||
|
||||
// Check container has className
|
||||
const container = image.parentElement;
|
||||
expect(container).toHaveClass("custom-class");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Security features", () => {
|
||||
it("should display query parameters as JSON for transparency", () => {
|
||||
render(
|
||||
<SecureImageComponent src="https://malicious.com/track.gif?email=user@example.com&id=12345&action=view" />,
|
||||
);
|
||||
|
||||
// Should show all parameters clearly
|
||||
expect(
|
||||
screen.getByText(/Warning: URL contains query parameters/),
|
||||
).toBeInTheDocument();
|
||||
|
||||
// Check JSON is properly formatted
|
||||
const preElement = screen.getByText(/"email": "user@example.com"/);
|
||||
expect(preElement).toBeInTheDocument();
|
||||
expect(screen.getByText(/"id": "12345"/)).toBeInTheDocument();
|
||||
expect(screen.getByText(/"action": "view"/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should handle encoded query parameters", () => {
|
||||
render(
|
||||
<SecureImageComponent src="https://example.com/img.png?data=%7B%22user%22%3A%22test%22%7D" />,
|
||||
);
|
||||
|
||||
// Should decode and display the parameter
|
||||
expect(
|
||||
screen.getByText(/Warning: URL contains query parameters/),
|
||||
).toBeInTheDocument();
|
||||
// The decoded value should be shown in the pre element
|
||||
const preElement = document.querySelector("pre");
|
||||
expect(preElement).toBeTruthy();
|
||||
// Check that the JSON contains the decoded data
|
||||
expect(preElement?.textContent).toContain('"data"');
|
||||
// The value is decoded as a string containing JSON
|
||||
expect(preElement?.textContent).toContain('"{');
|
||||
expect(preElement?.textContent).toContain("user");
|
||||
expect(preElement?.textContent).toContain("test");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Alt text handling", () => {
|
||||
it("should use empty string for alt when not provided", () => {
|
||||
render(<SecureImageComponent src="https://example.com/image.jpg" />);
|
||||
|
||||
fireEvent.click(screen.getByText("Load Image"));
|
||||
|
||||
// Query by tag name since empty alt makes it role="presentation"
|
||||
const images = document.querySelectorAll("img");
|
||||
expect(images.length).toBe(1);
|
||||
expect(images[0]).toHaveAttribute("alt", "");
|
||||
});
|
||||
|
||||
it("should use provided alt text", () => {
|
||||
render(
|
||||
<SecureImageComponent
|
||||
src="https://example.com/image.jpg"
|
||||
alt="Description of image"
|
||||
/>,
|
||||
);
|
||||
|
||||
fireEvent.click(screen.getByText("Load Image"));
|
||||
|
||||
const image = screen.getByAltText("Description of image");
|
||||
expect(image).toHaveAttribute("alt", "Description of image");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,168 @@
|
|||
import React, { useState } from "react";
|
||||
import styled from "styled-components";
|
||||
import {
|
||||
lightGray,
|
||||
vscBackground,
|
||||
vscButtonBackground,
|
||||
vscButtonForeground,
|
||||
vscForeground,
|
||||
vscInputBorder,
|
||||
} from "../";
|
||||
|
||||
const ImagePlaceholder = styled.div`
|
||||
border: 1px solid ${vscInputBorder};
|
||||
border-radius: 4px;
|
||||
padding: 12px;
|
||||
margin: 8px 0;
|
||||
background-color: ${vscBackground};
|
||||
display: inline-block;
|
||||
max-width: 100%;
|
||||
`;
|
||||
|
||||
const WarningText = styled.div`
|
||||
color: ${lightGray};
|
||||
font-size: 12px;
|
||||
margin-bottom: 8px;
|
||||
`;
|
||||
|
||||
const UrlDisplay = styled.div`
|
||||
font-family: var(--vscode-editor-font-family);
|
||||
font-size: 12px;
|
||||
color: ${vscForeground};
|
||||
word-break: break-all;
|
||||
margin: 8px 0;
|
||||
padding: 8px;
|
||||
background-color: rgba(0, 0, 0, 0.1);
|
||||
border-radius: 3px;
|
||||
`;
|
||||
|
||||
const QueryParamsDisplay = styled.div`
|
||||
font-family: var(--vscode-editor-font-family);
|
||||
font-size: 11px;
|
||||
color: ${vscForeground};
|
||||
margin: 8px 0;
|
||||
padding: 8px;
|
||||
background-color: rgba(128, 128, 128, 0.1);
|
||||
border-radius: 3px;
|
||||
border: 1px solid ${lightGray};
|
||||
`;
|
||||
|
||||
const LoadButton = styled.button`
|
||||
background-color: ${vscButtonBackground};
|
||||
color: ${vscButtonForeground};
|
||||
border: 1px solid ${vscInputBorder};
|
||||
padding: 6px 12px;
|
||||
border-radius: 3px;
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
margin-top: 8px;
|
||||
|
||||
&:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
&:active {
|
||||
transform: translateY(1px);
|
||||
}
|
||||
`;
|
||||
|
||||
const ImageContainer = styled.div`
|
||||
max-width: 100%;
|
||||
display: inline-block;
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
display: block;
|
||||
}
|
||||
`;
|
||||
|
||||
interface SecureImageComponentProps {
|
||||
src?: string;
|
||||
alt?: string;
|
||||
title?: string;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export const SecureImageComponent: React.FC<SecureImageComponentProps> = ({
|
||||
src,
|
||||
alt,
|
||||
title,
|
||||
className,
|
||||
}) => {
|
||||
const [showImage, setShowImage] = useState(false);
|
||||
const [imageError, setImageError] = useState(false);
|
||||
|
||||
if (!src) {
|
||||
return <span>[Invalid image: no source]</span>;
|
||||
}
|
||||
|
||||
// Parse URL to check for query parameters
|
||||
let queryParams: Record<string, string> = {};
|
||||
let hasQueryParams = false;
|
||||
|
||||
try {
|
||||
const url = new URL(src, window.location.href);
|
||||
const params = new URLSearchParams(url.search);
|
||||
params.forEach((value, key) => {
|
||||
queryParams[key] = value;
|
||||
hasQueryParams = true;
|
||||
});
|
||||
} catch (e) {
|
||||
// If URL parsing fails, treat src as a relative path
|
||||
const queryIndex = src.indexOf("?");
|
||||
if (queryIndex > -1) {
|
||||
hasQueryParams = true;
|
||||
const params = new URLSearchParams(src.substring(queryIndex));
|
||||
params.forEach((value, key) => {
|
||||
queryParams[key] = value;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (showImage && !imageError) {
|
||||
return (
|
||||
<ImageContainer className={className}>
|
||||
<img
|
||||
src={src}
|
||||
alt={alt || ""}
|
||||
title={title}
|
||||
onError={() => {
|
||||
setImageError(true);
|
||||
setShowImage(false);
|
||||
}}
|
||||
/>
|
||||
</ImageContainer>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<ImagePlaceholder>
|
||||
<WarningText>
|
||||
Image blocked for security. External images can leak data through URL
|
||||
parameters. Click to load if you trust the source.
|
||||
</WarningText>
|
||||
|
||||
<UrlDisplay>
|
||||
<strong>URL:</strong> {src}
|
||||
</UrlDisplay>
|
||||
|
||||
{hasQueryParams && (
|
||||
<QueryParamsDisplay>
|
||||
<strong>Warning: URL contains query parameters:</strong>
|
||||
<pre style={{ margin: "4px 0", fontSize: "11px" }}>
|
||||
{JSON.stringify(queryParams, null, 2)}
|
||||
</pre>
|
||||
</QueryParamsDisplay>
|
||||
)}
|
||||
|
||||
{imageError && (
|
||||
<div style={{ color: lightGray, fontSize: "12px", marginTop: "8px" }}>
|
||||
Failed to load image. The URL may be invalid or inaccessible.
|
||||
</div>
|
||||
)}
|
||||
|
||||
<LoadButton onClick={() => setShowImage(true)}>Load Image</LoadButton>
|
||||
</ImagePlaceholder>
|
||||
);
|
||||
};
|
||||
|
|
@ -23,6 +23,7 @@ import "./katex.css";
|
|||
import "./markdown.css";
|
||||
import MermaidBlock from "./MermaidBlock";
|
||||
import { rehypeHighlightPlugin } from "./rehypeHighlightPlugin";
|
||||
import { SecureImageComponent } from "./SecureImageComponent";
|
||||
import { StepContainerPreToolbar } from "./StepContainerPreToolbar";
|
||||
import SymbolLink from "./SymbolLink";
|
||||
import { SyntaxHighlightedPre } from "./SyntaxHighlightedPre";
|
||||
|
|
@ -346,6 +347,16 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
|
|||
}
|
||||
return <code {...codeProps}>{codeProps.children}</code>;
|
||||
},
|
||||
img: ({ ...imgProps }) => {
|
||||
return (
|
||||
<SecureImageComponent
|
||||
src={imgProps.src}
|
||||
alt={imgProps.alt}
|
||||
title={imgProps.title}
|
||||
className={imgProps.className}
|
||||
/>
|
||||
);
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue