Elffuss BraidHub

kikocis/continue public

main · 5.4 KiBRawPermalink
1import ignore from "ignore";
2
3import path from "path";
4import { fileURLToPath } from "url";
5import { ContinueError, ContinueErrorReason } from "../util/errors";
6
7// Security-focused ignore patterns - these should always be excluded for security reasons
8export const DEFAULT_SECURITY_IGNORE_FILETYPES = [
9 // Environment and configuration files with secrets
10 "*.env",
11 "*.env.*",
12 ".env*",
13 "config.json",
14 "config.yaml",
15 "config.yml",
16 "settings.json",
17 "appsettings.json",
18 "appsettings.*.json",
19
20 // Certificate and key files
21 "*.key",
22 "*.pem",
23 "*.p12",
24 "*.pfx",
25 "*.crt",
26 "*.cer",
27 "*.jks",
28 "*.keystore",
29 "*.truststore",
30
31 // Database files that may contain sensitive data
32 "*.db",
33 "*.sqlite",
34 "*.sqlite3",
35 "*.mdb",
36 "*.accdb",
37
38 // Credential and secret files
39 "*.secret",
40 "*.secrets",
41 "credentials",
42 "credentials.*",
43 "auth.json",
44 "token",
45 "token.*",
46 "*.token",
47
48 // Backup files that might contain sensitive data
49 "*.bak",
50 "*.backup",
51 "*.old",
52 "*.orig",
53
54 // Docker secrets
55 "docker-compose.override.yml",
56 "docker-compose.override.yaml",
57
58 // SSH and GPG
59 "id_rsa",
60 "id_dsa",
61 "id_ecdsa",
62 "id_ed25519",
63 "*.ppk",
64 "*.gpg",
65];
66
67export const DEFAULT_SECURITY_IGNORE_DIRS = [
68 // Environment and configuration directories
69 ".env/",
70 "env/",
71
72 // Cloud provider credential directories
73 ".aws/",
74 ".gcp/",
75 ".azure/",
76 ".kube/",
77 ".docker/",
78
79 // Secret directories
80 "secrets/",
81 ".secrets/",
82 "private/",
83 ".private/",
84 "certs/",
85 "certificates/",
86 "keys/",
87 ".ssh/",
88 ".gnupg/",
89 ".gpg/",
90
91 // Temporary directories that might contain sensitive data
92 "tmp/secrets/",
93 "temp/secrets/",
94 ".tmp/",
95];
96
97// Additional non-security patterns for general indexing exclusion
98export const ADDITIONAL_INDEXING_IGNORE_FILETYPES = [
99 "*.DS_Store",
100 "*-lock.json",
101 "*.lock",
102 "*.log",
103 "*.ttf",
104 "*.png",
105 "*.jpg",
106 "*.jpeg",
107 "*.gif",
108 "*.mp4",
109 "*.svg",
110 "*.ico",
111 "*.pdf",
112 "*.zip",
113 "*.gz",
114 "*.tar",
115 "*.dmg",
116 "*.tgz",
117 "*.rar",
118 "*.7z",
119 "*.exe",
120 "*.dll",
121 "*.obj",
122 "*.o",
123 "*.o.d",
124 "*.a",
125 "*.lib",
126 "*.so",
127 "*.dylib",
128 "*.ncb",
129 "*.sdf",
130 "*.woff",
131 "*.woff2",
132 "*.eot",
133 "*.cur",
134 "*.avi",
135 "*.mpg",
136 "*.mpeg",
137 "*.mov",
138 "*.mp3",
139 "*.mkv",
140 "*.webm",
141 "*.jar",
142 "*.onnx",
143 "*.parquet",
144 "*.pqt",
145 "*.wav",
146 "*.webp",
147 "*.wasm",
148 "*.plist",
149 "*.profraw",
150 "*.gcda",
151 "*.gcno",
152 "go.sum",
153 "*.gitignore",
154 "*.gitkeep",
155 "*.continueignore",
156 "*.csv",
157 "*.uasset",
158 "*.pdb",
159 "*.bin",
160 "*.pag",
161 "*.swp",
162 "*.jsonl",
163 // "*.prompt", // can be incredibly confusing for the LLM to have another set of instructions injected into the prompt
164 // Application specific
165 ".continue/",
166];
167
168export const ADDITIONAL_INDEXING_IGNORE_DIRS = [
169 ".git/",
170 ".svn/",
171 "node_modules/",
172 "dist/",
173 "build/",
174 "Build/",
175 "target/",
176 "out/",
177 "bin/",
178 ".pytest_cache/",
179 ".vscode-test/",
180 "__pycache__/",
181 "site-packages/",
182 ".gradle/",
183 ".mvn/",
184 ".cache/",
185 "gems/",
186 "vendor/",
187
188 ".venv/",
189 "venv/",
190
191 ".vscode/",
192 ".idea/",
193 ".vs/",
194];
195
196// Combined patterns: security + additional
197export const DEFAULT_IGNORE_FILETYPES = [
198 ...DEFAULT_SECURITY_IGNORE_FILETYPES,
199 ...ADDITIONAL_INDEXING_IGNORE_FILETYPES,
200];
201
202export const DEFAULT_IGNORE_DIRS = [
203 ...DEFAULT_SECURITY_IGNORE_DIRS,
204 ...ADDITIONAL_INDEXING_IGNORE_DIRS,
205];
206
207export const DEFAULT_IGNORES = [
208 ...DEFAULT_IGNORE_FILETYPES,
209 ...DEFAULT_IGNORE_DIRS,
210];
211
212export const defaultIgnoresGlob = `!{${DEFAULT_IGNORES.join(",")}}`;
213
214// Create ignore instances
215export const defaultSecurityIgnoreFile = ignore().add(
216 DEFAULT_SECURITY_IGNORE_FILETYPES,
217);
218export const defaultSecurityIgnoreDir = ignore().add(
219 DEFAULT_SECURITY_IGNORE_DIRS,
220);
221export const defaultIgnoreFile = ignore().add(DEFAULT_IGNORE_FILETYPES);
222export const defaultIgnoreDir = ignore().add(DEFAULT_IGNORE_DIRS);
223
224// String representations
225export const DEFAULT_SECURITY_IGNORE =
226 DEFAULT_SECURITY_IGNORE_FILETYPES.join("\n") +
227 "\n" +
228 DEFAULT_SECURITY_IGNORE_DIRS.join("\n");
229
230export const DEFAULT_IGNORE =
231 DEFAULT_IGNORE_FILETYPES.join("\n") + "\n" + DEFAULT_IGNORE_DIRS.join("\n");
232
233// Combined ignore instances
234export const defaultFileAndFolderSecurityIgnores = ignore()
235 .add(defaultSecurityIgnoreFile)
236 .add(defaultSecurityIgnoreDir);
237
238export const defaultIgnoreFileAndDir = ignore()
239 .add(defaultIgnoreFile)
240 .add(defaultIgnoreDir);
241
242export function isSecurityConcern(filePathOrUri: string) {
243 if (!filePathOrUri) {
244 return false;
245 }
246 let filepath = filePathOrUri;
247 try {
248 filepath = fileURLToPath(filePathOrUri);
249 } catch {}
250 if (path.isAbsolute(filepath)) {
251 const dir = path.dirname(filepath).split(/\/|\\/).at(-1) ?? "";
252 const basename = path.basename(filepath);
253 filepath = `${dir ? dir + "/" : ""}${basename}`;
254 }
255 if (!filepath) {
256 return false;
257 }
258 return defaultFileAndFolderSecurityIgnores.ignores(filepath);
259}
260
261export function throwIfFileIsSecurityConcern(filepath: string) {
262 if (isSecurityConcern(filepath)) {
263 throw new ContinueError(
264 ContinueErrorReason.FileIsSecurityConcern,
265 `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.`,
266 );
267 }
268}
269
270export function gitIgArrayFromFile(file: string) {
271 return file
272 .split(/\r?\n/) // Split on new line
273 .map((l) => l.trim()) // Remove whitespace
274 .filter((l) => !/^#|^$/.test(l)); // Remove empty lines
275}