Elffuss BraidHub

kikocis/continue public

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