beforeopen 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.es.md +14 -11
- package/README.md +14 -11
- package/dist/cli.js +320 -31
- package/package.json +1 -1
package/README.es.md
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
<p align="center">
|
|
8
8
|
<a href="https://github.com/willor16/beforeopen"><img src="https://img.shields.io/badge/willor16%2Fbeforeopen-black?style=social&logo=github" alt="repositorio"></a>
|
|
9
9
|
<a href="https://github.com/willor16/beforeopen/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/willor16/beforeopen/ci.yml?branch=main&label=CI" alt="CI"></a>
|
|
10
|
+
<a href="https://www.npmjs.com/package/beforeopen"><img src="https://img.shields.io/npm/v/beforeopen?logo=npm" alt="versión en npm"></a>
|
|
10
11
|
<img src="https://img.shields.io/badge/dependencias-0-brightgreen" alt="sin dependencias en ejecución">
|
|
11
12
|
<a href="LICENSE"><img src="https://img.shields.io/badge/licencia-MIT-blue" alt="licencia MIT"></a>
|
|
12
13
|
</p>
|
|
@@ -32,24 +33,22 @@ Algunas de las mejores características del proyecto:
|
|
|
32
33
|
|
|
33
34
|
Necesitas [Node.js](https://nodejs.org) 20 o posterior, y git.
|
|
34
35
|
|
|
35
|
-
<p>1.
|
|
36
|
+
<p>1. Instala el comando</p>
|
|
36
37
|
|
|
37
38
|
```sh
|
|
38
|
-
|
|
39
|
-
cd beforeopen
|
|
39
|
+
npm install -g beforeopen
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
<p>2.
|
|
42
|
+
<p>2. Analiza un repositorio</p>
|
|
43
43
|
|
|
44
44
|
```sh
|
|
45
|
-
|
|
46
|
-
npm run build
|
|
45
|
+
beforeopen owner/repo
|
|
47
46
|
```
|
|
48
47
|
|
|
49
|
-
|
|
48
|
+
O úsalo sin instalar nada. Ejecútalo desde fuera de la carpeta en la que no confías, porque `npx` lee los ajustes de la carpeta actual:
|
|
50
49
|
|
|
51
50
|
```sh
|
|
52
|
-
|
|
51
|
+
npx beforeopen owner/repo
|
|
53
52
|
```
|
|
54
53
|
|
|
55
54
|
<h2>🚀 Uso:</h2>
|
|
@@ -99,7 +98,8 @@ Usa `pull_request`, nunca `pull_request_target`.
|
|
|
99
98
|
| 🌿 Al usar git | Hooks, `.git/config`, repositorios ocultos, submódulos, husky, lefthook, pre-commit |
|
|
100
99
|
| 📦 Al abrir en un contenedor | Comandos del contenedor de desarrollo y acceso a tu máquina |
|
|
101
100
|
| ⬇️ Al instalar | npm, pnpm, Yarn, Bun, node-gyp, pip, setup.py, Composer, CocoaPods |
|
|
102
|
-
| 🔨 Al compilar o probar | Cargo, Gradle, Maven, pytest, configuración que es código |
|
|
101
|
+
| 🔨 Al compilar o probar | Cargo, Gradle, Maven, pytest, eventos de Visual Studio, configuración que es código |
|
|
102
|
+
| 🕵️ Al ejecutar el proyecto | Código oculto con espacios, caracteres invisibles o codificación, y nombres de archivo disfrazados |
|
|
103
103
|
|
|
104
104
|
<h2>🔒 Cómo se protege:</h2>
|
|
105
105
|
|
|
@@ -113,8 +113,11 @@ Usa `pull_request`, nunca `pull_request_target`.
|
|
|
113
113
|
|
|
114
114
|
* Nunca dice que un repositorio es seguro
|
|
115
115
|
* No analiza tus dependencias, archivos binarios ni código construido al ejecutarse
|
|
116
|
-
*
|
|
117
|
-
*
|
|
116
|
+
* Es fuerte con el código que se ejecuta solo y débil con el código malicioso dentro del programa
|
|
117
|
+
* De 17 ataques documentados no usados para hacer las reglas, muestra 6. De los 6 que se ejecutan solos, muestra 5
|
|
118
|
+
* En 39 repositorios populares no usados para ajustar las reglas, 1 tuvo un hallazgo alto, en un archivo legítimo
|
|
119
|
+
|
|
120
|
+
La medición completa, con su método y sus fallos, está en [docs/detection.md](docs/detection.md) (en inglés).
|
|
118
121
|
|
|
119
122
|
<h2>🍰 Cómo contribuir:</h2>
|
|
120
123
|
|
package/README.md
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
<p align="center">
|
|
8
8
|
<a href="https://github.com/willor16/beforeopen"><img src="https://img.shields.io/badge/willor16%2Fbeforeopen-black?style=social&logo=github" alt="repository"></a>
|
|
9
9
|
<a href="https://github.com/willor16/beforeopen/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/willor16/beforeopen/ci.yml?branch=main&label=CI" alt="CI"></a>
|
|
10
|
+
<a href="https://www.npmjs.com/package/beforeopen"><img src="https://img.shields.io/npm/v/beforeopen?logo=npm" alt="npm version"></a>
|
|
10
11
|
<img src="https://img.shields.io/badge/runtime%20dependencies-0-brightgreen" alt="no runtime dependencies">
|
|
11
12
|
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" alt="MIT license"></a>
|
|
12
13
|
</p>
|
|
@@ -32,24 +33,22 @@ Some of the project's best features:
|
|
|
32
33
|
|
|
33
34
|
You need [Node.js](https://nodejs.org) 20 or later, and git.
|
|
34
35
|
|
|
35
|
-
<p>1.
|
|
36
|
+
<p>1. Install the command</p>
|
|
36
37
|
|
|
37
38
|
```sh
|
|
38
|
-
|
|
39
|
-
cd beforeopen
|
|
39
|
+
npm install -g beforeopen
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
<p>2.
|
|
42
|
+
<p>2. Scan a repository</p>
|
|
43
43
|
|
|
44
44
|
```sh
|
|
45
|
-
|
|
46
|
-
npm run build
|
|
45
|
+
beforeopen owner/repo
|
|
47
46
|
```
|
|
48
47
|
|
|
49
|
-
|
|
48
|
+
Or use it without installing anything. Run it from outside the folder you do not trust, because `npx` reads the settings of the current folder:
|
|
50
49
|
|
|
51
50
|
```sh
|
|
52
|
-
|
|
51
|
+
npx beforeopen owner/repo
|
|
53
52
|
```
|
|
54
53
|
|
|
55
54
|
<h2>🚀 Usage:</h2>
|
|
@@ -97,7 +96,8 @@ Use `pull_request`, never `pull_request_target`.
|
|
|
97
96
|
| 🌿 Using git | Hooks, `.git/config`, hidden repositories, submodules, husky, lefthook, pre-commit |
|
|
98
97
|
| 📦 Opening in a container | Dev container commands and access to your machine |
|
|
99
98
|
| ⬇️ Installing | npm, pnpm, Yarn, Bun, node-gyp, pip, setup.py, Composer, CocoaPods |
|
|
100
|
-
| 🔨 Building or testing | Cargo, Gradle, Maven, pytest, configuration that is code |
|
|
99
|
+
| 🔨 Building or testing | Cargo, Gradle, Maven, pytest, Visual Studio events, configuration that is code |
|
|
100
|
+
| 🕵️ Running the project | Code hidden with spaces, invisible characters or encoding, and disguised file names |
|
|
101
101
|
|
|
102
102
|
<h2>🔒 How it stays safe:</h2>
|
|
103
103
|
|
|
@@ -111,8 +111,11 @@ Use `pull_request`, never `pull_request_target`.
|
|
|
111
111
|
|
|
112
112
|
* It never says that a repository is safe
|
|
113
113
|
* It does not analyse your dependencies, binary files or code built at run time
|
|
114
|
-
* It
|
|
115
|
-
*
|
|
114
|
+
* It is strong with code that runs by itself and weak with malicious code inside the program
|
|
115
|
+
* Of 17 documented attacks not used to make the rules, it shows 6. Of the 6 that run by themselves, it shows 5
|
|
116
|
+
* On 39 popular repositories not used to adjust the rules, 1 had a high finding, in a legitimate file
|
|
117
|
+
|
|
118
|
+
The full measurement, with its method and its failures, is in [docs/detection.md](docs/detection.md).
|
|
116
119
|
|
|
117
120
|
<h2>🍰 Contribution Guidelines:</h2>
|
|
118
121
|
|
package/dist/cli.js
CHANGED
|
@@ -58,6 +58,7 @@ var init_define_BEFOREOPEN_RULES = __esm({
|
|
|
58
58
|
# command is the group named "command", the first group or the match.
|
|
59
59
|
# sibling Optional file that must exist in the same folder.
|
|
60
60
|
# script Whether the file is read as a script. By default, only without \`match\`.
|
|
61
|
+
# decode "xml" when the matched text uses entities such as >.
|
|
61
62
|
|
|
62
63
|
points:
|
|
63
64
|
# --- Terminal ---------------------------------------------------------------
|
|
@@ -121,7 +122,8 @@ points:
|
|
|
121
122
|
title: { en: MSBuild step that starts a program, es: Paso de MSBuild que inicia un programa }
|
|
122
123
|
needs: { en: you open or build the project in Visual Studio, es: que abras o compiles el proyecto en Visual Studio }
|
|
123
124
|
files: ['**/directory.build.{props,targets}', '**/*.{csproj,vbproj,fsproj,vcxproj,targets,props,user}']
|
|
124
|
-
|
|
125
|
+
decode: xml
|
|
126
|
+
match: '<Exec\\s[^>]{0,2000}?\\bCommand="(?<command>[^"]{1,20000})"|<(?:Pre|Post)(?:Build|Link)Event>\\s*(?:<Command>)?\\s*(?<event>[^<\\s][^<]{0,40000})<'
|
|
125
127
|
|
|
126
128
|
- id: editor/debugger-init
|
|
127
129
|
trigger: editor
|
|
@@ -251,6 +253,20 @@ points:
|
|
|
251
253
|
title: { en: Gemfile. It is Ruby code, es: Gemfile. Es c\xF3digo Ruby }
|
|
252
254
|
files: ['**/gemfile', '**/gems.rb', '**/*.gemspec']
|
|
253
255
|
|
|
256
|
+
- id: install/gemfile-command
|
|
257
|
+
trigger: install
|
|
258
|
+
severity: medium
|
|
259
|
+
title: { en: Gemfile that starts a program, es: Gemfile que inicia un programa }
|
|
260
|
+
needs: { en: you use any bundle command, es: que uses cualquier comando de bundle }
|
|
261
|
+
files: ['**/gemfile', '**/gems.rb']
|
|
262
|
+
match: '^[ \\t]*(?<command>(?:Kernel\\.|IO\\.)?(?:system|exec|spawn|popen)\\b[^\\n]{1,400}|%x[\\{\\[(][^\\n]{1,400}|\`[^\`\\n]{1,400}\`)'
|
|
263
|
+
|
|
264
|
+
- id: install/gem-extension
|
|
265
|
+
trigger: install
|
|
266
|
+
severity: low
|
|
267
|
+
title: { en: Native extension of a gem, es: Extensi\xF3n nativa de una gema }
|
|
268
|
+
files: ['**/extconf.rb']
|
|
269
|
+
|
|
254
270
|
- id: install/podfile
|
|
255
271
|
trigger: install
|
|
256
272
|
severity: low
|
|
@@ -356,6 +372,9 @@ points:
|
|
|
356
372
|
# patterns JavaScript regular expressions (flags: i, u, g). Any of them is enough.
|
|
357
373
|
# unless Only for instructions: lowers the finding to info when it matches nearby.
|
|
358
374
|
# It never applies to commands or scripts, where it could be abused.
|
|
375
|
+
# all Every one of these must also appear, anywhere in the same text.
|
|
376
|
+
# broad true when it means the same in any source file. Those files are read
|
|
377
|
+
# even if nothing runs them by itself.
|
|
359
378
|
# flags Replaces the default "i".
|
|
360
379
|
#
|
|
361
380
|
# Keep patterns linear: no nested quantifiers and always a limit such as {0,200}.
|
|
@@ -416,18 +435,20 @@ signals:
|
|
|
416
435
|
- '(?:^|[\\s;&|(\`])(?:env|printenv|set|export\\s+-p)\\s*\\|\\s*(?:curl|wget|nc|base64|xxd|gzip)\\b'
|
|
417
436
|
- '\\b(?:curl|wget)\\b[^\\n]{0,200}(?:-d|--data(?:-\\w+)?|-F|--post-data)[ =]["'']?@?\\$\\(\\s*(?:env|printenv)\\b'
|
|
418
437
|
- 'json\\.dumps\\(\\s*(?:dict\\(\\s*)?os\\.environ'
|
|
438
|
+
- '\\b(?:post|put|request|fetch|send)\\w*\\s*\\([^\\n]{0,160}(?:\\.\\.\\.\\s*process\\.env\\b|[,:]\\s*process\\.env\\s*[,})])'
|
|
419
439
|
|
|
420
440
|
- id: encoded-command
|
|
421
441
|
title:
|
|
422
442
|
en: Runs encoded or encrypted code
|
|
423
443
|
es: Ejecuta c\xF3digo codificado o cifrado
|
|
424
444
|
severity: { command: high, script: high, instructions: medium }
|
|
445
|
+
broad: true
|
|
425
446
|
patterns:
|
|
426
447
|
- '\\b(?:powershell|pwsh)(?:\\.exe)?\\b[^\\n]{0,200}\\s-e(?:nc(?:odedcommand)?|c)?\\s+["'']?[A-Za-z0-9+/=]{24,}'
|
|
427
448
|
- '\\bbase64\\s+(?:-d|-D|--decode)\\b[^\\n]{0,80}\\|\\s*(?:sudo\\s+)?(?:(?:ba|z|da)?sh|node|python[\\d.]*|perl|ruby)\\b'
|
|
428
449
|
- '\\beval\\s*\\(\\s*(?:atob|Buffer\\.from|decodeURIComponent|unescape|String\\.fromCharCode)\\s*\\('
|
|
429
450
|
- '\\b(?:new\\s+)?Function\\s*\\(\\s*(?:["'']require["'']\\s*,\\s*)?(?:atob|Buffer\\.from)\\s*\\('
|
|
430
|
-
- '\\bexec\\s*\\(\\s*(?:__import__\\(["'']\\w{2,10}["'']\\)|base64|zlib|marshal|codecs|bytes\\.fromhex
|
|
451
|
+
- '\\bexec\\s*\\(\\s*(?:__import__\\(["'']\\w{2,10}["'']\\)|(?:base64|zlib|marshal|codecs|bytes\\.fromhex)\\b)'
|
|
431
452
|
- '\\bFromBase64String\\b[^\\n]{0,200}\\b(?:iex|Invoke-Expression|Assembly\\]::Load)\\b'
|
|
432
453
|
- '\\bxxd\\s+-r\\b[^\\n]{0,80}\\|\\s*(?:ba|z)?sh\\b'
|
|
433
454
|
|
|
@@ -436,19 +457,104 @@ signals:
|
|
|
436
457
|
en: Deliberately unreadable code
|
|
437
458
|
es: C\xF3digo ilegible a prop\xF3sito
|
|
438
459
|
severity: high
|
|
460
|
+
broad: true
|
|
439
461
|
patterns:
|
|
440
462
|
- '(?:\\b_0x[a-f0-9]{4,6}\\b[^\\n]{0,120}?){4}'
|
|
441
|
-
- '(?:\\\\x[2-7][0-9a-f]){
|
|
463
|
+
- '(?:\\\\x[2-7][0-9a-f]){120}'
|
|
442
464
|
- '(?:String\\.fromCharCode\\([^)\\n]{0,40}\\)[^\\n]{0,10}\\+){4}'
|
|
443
465
|
- '\\bglobal\\s*\\[\\s*["'']!["'']\\s*\\]\\s*='
|
|
444
466
|
|
|
467
|
+
- id: invisible-code
|
|
468
|
+
title:
|
|
469
|
+
en: Long text made of characters that are not shown
|
|
470
|
+
es: Texto largo hecho de caracteres que no se muestran
|
|
471
|
+
severity: high
|
|
472
|
+
broad: true
|
|
473
|
+
flags: ''
|
|
474
|
+
patterns:
|
|
475
|
+
- '[\\u{fe00}-\\u{fe0f}\\u{e0100}-\\u{e01ef}]{8,}'
|
|
476
|
+
- '[\\u{e0020}-\\u{e007f}]{12,}'
|
|
477
|
+
- '[\\u{200b}-\\u{200d}\\u{2060}-\\u{2064}\\u{180e}\\u{3164}\\u{ffa0}]{16,}'
|
|
478
|
+
|
|
479
|
+
- id: remote-code
|
|
480
|
+
title:
|
|
481
|
+
en: Turns received text into a program with full access
|
|
482
|
+
es: Convierte un texto recibido en un programa con acceso total
|
|
483
|
+
severity: high
|
|
484
|
+
broad: true
|
|
485
|
+
patterns:
|
|
486
|
+
- '\\bFunction\\s*\\(\\s*["''\`]require["''\`]\\s*,[^\\n]{0,200}?\\)\\s*\\(\\s*require\\b'
|
|
487
|
+
- '\\bFunction\\s*\\.\\s*constructor\\s*\\)?\\s*\\(\\s*["''\`]require["''\`]'
|
|
488
|
+
- '\\beval\\s*\\(\\s*(?:await\\s+)?\\(?\\s*(?:await\\s+)?(?:fetch|axios\\.get|got|request)\\s*\\('
|
|
489
|
+
- '\\bexec\\s*\\(\\s*(?:requests\\.get|urllib\\.request\\.urlopen|urlopen)\\s*\\('
|
|
490
|
+
|
|
491
|
+
- id: coded-and-evaluated
|
|
492
|
+
title:
|
|
493
|
+
en: Runs a long list of coded characters
|
|
494
|
+
es: Ejecuta una lista larga de caracteres codificados
|
|
495
|
+
severity: { script: high, command: high }
|
|
496
|
+
broad: true
|
|
497
|
+
patterns:
|
|
498
|
+
- '(?<![\\w.$])(?:eval|exec|Function)\\s*\\([^;\\n"''\`]{0,120}?\\[\\s*(?:\\d{2,3}\\s?,\\s?){100}'
|
|
499
|
+
- '(?<![\\w.$])(?:eval|exec)\\s*\\([^;\\n"''\`]{0,120}?\\(\\s*(?:\\d{2,3}\\s?,\\s?){100}'
|
|
500
|
+
|
|
501
|
+
- id: coded-text-evaluated
|
|
502
|
+
title:
|
|
503
|
+
en: Runs a long block of coded text
|
|
504
|
+
es: Ejecuta un bloque largo de texto codificado
|
|
505
|
+
severity: { script: high, command: high }
|
|
506
|
+
broad: true
|
|
507
|
+
patterns:
|
|
508
|
+
- '(?<![\\w.$])(?:eval|exec|new\\s+Function)\\s*\\((?!\\s*["''\`])[^;\\n]{0,100}?(?:Buffer\\.from|\\batob|b64decode|fromhex|unhexlify|fromCharCode)\\s*\\('
|
|
509
|
+
all:
|
|
510
|
+
- '["''\`](?:[0-9a-f]{2}){200}|["''\`](?:[A-Za-z0-9+/]{4}){250}'
|
|
511
|
+
|
|
512
|
+
- id: dns-payload
|
|
513
|
+
title:
|
|
514
|
+
en: Runs what it receives in a DNS answer
|
|
515
|
+
es: Ejecuta lo que recibe en una respuesta DNS
|
|
516
|
+
severity: high
|
|
517
|
+
broad: true
|
|
518
|
+
patterns:
|
|
519
|
+
- '\\b(?:dig|nslookup|host\\s+-t)\\b[^\\n]{0,80}\\bTXT\\b[\\s\\S]{0,300}?(?:(?<![\\w.$-])eval\\b|\\|\\s*(?:ba|z)?sh\\b)'
|
|
520
|
+
- '\\bResolve-DnsName\\b[\\s\\S]{0,300}?(?:\\biex\\b|\\bInvoke-Expression\\b)'
|
|
521
|
+
- '\\bresolveTxt\\s*\\([\\s\\S]{0,400}?(?:(?<![\\w.$])eval\\s*\\(|\\bnew\\s+Function\\s*\\(|\\bexecSync\\s*\\()'
|
|
522
|
+
|
|
523
|
+
- id: exposes-require
|
|
524
|
+
title:
|
|
525
|
+
en: Gives global access to load any module
|
|
526
|
+
es: Da acceso global para cargar cualquier m\xF3dulo
|
|
527
|
+
severity: { command: medium, script: medium }
|
|
528
|
+
patterns:
|
|
529
|
+
- '\\bglobal(?:This)?\\s*(?:\\[[^\\]\\n]{1,60}\\]|\\.\\w{1,40})\\s*=\\s*(?:require|module)\\s*[;,\\n]'
|
|
530
|
+
|
|
531
|
+
- id: windows-script
|
|
532
|
+
title:
|
|
533
|
+
en: Starts a Windows script
|
|
534
|
+
es: Inicia un script de Windows
|
|
535
|
+
severity: { command: high, script: low }
|
|
536
|
+
patterns:
|
|
537
|
+
- '\\b(?:cscript|wscript)(?:\\.exe)?\\b[^\\n]{0,200}\\.(?:vbs|vbe|js|jse|wsf)\\b'
|
|
538
|
+
|
|
539
|
+
- id: downloads-and-starts
|
|
540
|
+
title:
|
|
541
|
+
en: Downloads something and starts programs
|
|
542
|
+
es: Descarga algo e inicia programas
|
|
543
|
+
severity: { script: medium }
|
|
544
|
+
patterns:
|
|
545
|
+
- '\\b(?:urllib\\.request\\.(?:urlopen|urlretrieve)|requests\\.get|urlretrieve)\\s*\\('
|
|
546
|
+
all:
|
|
547
|
+
- '\\bsubprocess\\.(?:Popen|run|call|check_call)|\\bos\\.system\\s*\\(|\\bos\\.startfile\\s*\\('
|
|
548
|
+
|
|
445
549
|
- id: hidden-by-spaces
|
|
446
550
|
title:
|
|
447
551
|
en: Text pushed out of sight with spaces
|
|
448
552
|
es: Texto escondido detr\xE1s de muchos espacios
|
|
449
553
|
severity: { command: high, script: high, instructions: medium }
|
|
554
|
+
broad: true
|
|
450
555
|
patterns:
|
|
451
556
|
- '\\S[ \\t\\u{a0}\\u{3000}]{150,}(?:[^\\s|#/*\\\\-]|/[^/*\\s])'
|
|
557
|
+
- '\\n[ \\t]{300,}[^\\s]'
|
|
452
558
|
|
|
453
559
|
- id: hidden-characters
|
|
454
560
|
title:
|
|
@@ -495,6 +601,7 @@ signals:
|
|
|
495
601
|
en: Fetches code or orders from a blockchain
|
|
496
602
|
es: Obtiene c\xF3digo u \xF3rdenes desde una blockchain
|
|
497
603
|
severity: high
|
|
604
|
+
broad: true
|
|
498
605
|
patterns:
|
|
499
606
|
- '\\beth_getTransactionByHash\\b|\\beth_getTransactionReceipt\\b'
|
|
500
607
|
- '\\b(?:bsc-dataseed\\d{0,2}\\.(?:binance|bnbchain)\\.org|api\\.trongrid\\.io|fullnode\\.mainnet\\.aptoslabs\\.com|bsc-rpc\\.publicnode\\.com)\\b'
|
|
@@ -624,6 +731,35 @@ signals:
|
|
|
624
731
|
unless:
|
|
625
732
|
- 'prompt[ -]injection|\\battacks?\\b|\\bjailbreak|\\be\\.g\\.|\\bexample\\b|\\bejemplo\\b|["''\`\u201C]\\s*(?:ignore|disregard|forget|ignora|olvida)'
|
|
626
733
|
|
|
734
|
+
- id: works-in-silence
|
|
735
|
+
title:
|
|
736
|
+
en: Asks the agent to act without output or confirmation
|
|
737
|
+
es: Pide al agente que act\xFAe sin mostrar nada ni confirmar
|
|
738
|
+
severity: { instructions: medium }
|
|
739
|
+
patterns:
|
|
740
|
+
- '\\bsilently\\s+(?:run|execute|call|send|post|upload|install)\\b'
|
|
741
|
+
- '\\b(?:run|execute|ejecuta)\\b[^\\n]{0,160}\\b(?:with\\s+no\\s+output|without\\s+(?:any\\s+)?(?:output|confirmation|telling)|no\\s+output\\s+and\\b|sin\\s+confirmaci[o\xF3]n)'
|
|
742
|
+
- '\\bsuppress\\s+(?:all|any)\\s+(?:the\\s+)?output\\b'
|
|
743
|
+
|
|
744
|
+
- id: sends-data-away
|
|
745
|
+
title:
|
|
746
|
+
en: Asks the agent to send private data to an address
|
|
747
|
+
es: Pide al agente que env\xEDe datos privados a una direcci\xF3n
|
|
748
|
+
severity: { instructions: medium }
|
|
749
|
+
patterns:
|
|
750
|
+
- '\\b(?:send|post|upload|forward|transmit|exfiltrate|copy)\\w*\\b[^\\n]{0,200}(?:\\.env\\b|environment\\s+variables?|os\\.environ|process\\.env|api\\s+keys?|credentials?|secrets?|conversation|user(?:''s)?\\s+(?:message|prompt))[^\\n]{0,160}https?://(?!localhost|127\\.)'
|
|
751
|
+
- '(?:\\.env\\b|environment\\s+variables?|os\\.environ|process\\.env|api\\s+keys?|credentials?|\\bSECRET\\b|conversation|user(?:''s)?\\s+(?:message|prompt))[^\\n]{0,200}\\b(?:send|post|upload|forward|transmit|exfiltrate)s?\\b[^\\n]{0,120}https?://(?!localhost|127\\.)'
|
|
752
|
+
|
|
753
|
+
- id: changes-agent
|
|
754
|
+
title:
|
|
755
|
+
en: Asks the agent to change its own settings
|
|
756
|
+
es: Pide al agente que cambie sus propios ajustes
|
|
757
|
+
severity: { instructions: medium }
|
|
758
|
+
patterns:
|
|
759
|
+
- '\\b(?:write|add|set|update|edit|modify|append|change|put)\\b[^\\n]{0,160}~[\\\\/]\\.(?:codex[\\\\/]config|claude[\\\\/]settings|claude\\.json|gemini[\\\\/]settings|cursor[\\\\/](?:mcp|cli)|config[\\\\/]opencode[\\\\/]opencode)\\b'
|
|
760
|
+
- '\\b(?:write|add|set|export|put)\\b[^\\n]{0,60}\\b(?:ANTHROPIC|OPENAI|GEMINI)_(?:BASE_URL|API_BASE)\\b[^\\n]{0,60}https?://(?!localhost|127\\.)'
|
|
761
|
+
- '\\bset\\b[^\\n]{0,40}\\bapproval_policy\\b[^\\n]{0,20}\\bnever\\b'
|
|
762
|
+
|
|
627
763
|
- id: order-in-comment
|
|
628
764
|
title:
|
|
629
765
|
en: Orders inside a comment that people do not see
|
|
@@ -8051,7 +8187,8 @@ var TRIGGER_TEXT = {
|
|
|
8051
8187
|
git: { en: "On using git", es: "Al usar git" },
|
|
8052
8188
|
container: { en: "On opening in a container", es: "Al abrir en un contenedor" },
|
|
8053
8189
|
install: { en: "On installing dependencies", es: "Al instalar dependencias" },
|
|
8054
|
-
build: { en: "On building or testing", es: "Al compilar o probar" }
|
|
8190
|
+
build: { en: "On building or testing", es: "Al compilar o probar" },
|
|
8191
|
+
run: { en: "On running the project", es: "Al ejecutar el proyecto" }
|
|
8055
8192
|
};
|
|
8056
8193
|
var SEVERITY_TEXT = {
|
|
8057
8194
|
high: { en: "HIGH", es: "ALTO" },
|
|
@@ -8159,7 +8296,7 @@ init_define_BEFOREOPEN_RULES();
|
|
|
8159
8296
|
var SEVERITIES = ["info", "low", "medium", "high"];
|
|
8160
8297
|
var rank = (s) => SEVERITIES.indexOf(s);
|
|
8161
8298
|
var worst = (a, b) => rank(a) >= rank(b) ? a : b;
|
|
8162
|
-
var TRIGGERS = ["editor", "agent", "shell", "git", "container", "install", "build"];
|
|
8299
|
+
var TRIGGERS = ["editor", "agent", "shell", "git", "container", "install", "build", "run"];
|
|
8163
8300
|
|
|
8164
8301
|
// src/report/terminal.ts
|
|
8165
8302
|
init_define_BEFOREOPEN_RULES();
|
|
@@ -9334,7 +9471,7 @@ function parseRules(source, name) {
|
|
|
9334
9471
|
signals: list(root["signals"]).map((raw, i) => {
|
|
9335
9472
|
const o = object(raw, `signals[${i}]`);
|
|
9336
9473
|
const id = string(o["id"], `signals[${i}].id`);
|
|
9337
|
-
only(o, id, ["id", "title", "severity", "patterns", "unless", "flags"]);
|
|
9474
|
+
only(o, id, ["id", "title", "severity", "patterns", "all", "unless", "flags", "broad"]);
|
|
9338
9475
|
const flags = `${o["flags"] === void 0 ? "i" : String(o["flags"])}gu`;
|
|
9339
9476
|
const bySeverity = {};
|
|
9340
9477
|
if (typeof o["severity"] === "string") {
|
|
@@ -9352,13 +9489,16 @@ function parseRules(source, name) {
|
|
|
9352
9489
|
title: text(o["title"], `${id}.title`),
|
|
9353
9490
|
severity: bySeverity,
|
|
9354
9491
|
patterns,
|
|
9492
|
+
all: list(o["all"]).map((p, n) => regex(p, `${id}.all[${n}]`, flags.replace("g", ""))),
|
|
9493
|
+
broad: o["broad"] === true,
|
|
9355
9494
|
unless: list(o["unless"]).map((p, n) => regex(p, `${id}.unless[${n}]`, "iu"))
|
|
9356
9495
|
};
|
|
9357
9496
|
}),
|
|
9358
9497
|
points: list(root["points"]).map((raw, i) => {
|
|
9359
9498
|
const o = object(raw, `points[${i}]`);
|
|
9360
9499
|
const id = string(o["id"], `points[${i}].id`);
|
|
9361
|
-
only(o, id, ["id", "trigger", "severity", "title", "needs", "files", "exclude", "match", "sibling", "script"]);
|
|
9500
|
+
only(o, id, ["id", "trigger", "severity", "title", "needs", "files", "exclude", "match", "sibling", "script", "decode"]);
|
|
9501
|
+
if (o["decode"] !== void 0 && o["decode"] !== "xml") fail(`${id}.decode must be xml`);
|
|
9362
9502
|
const trigger = o["trigger"];
|
|
9363
9503
|
if (!TRIGGERS.includes(trigger)) fail(`${id}.trigger must be one of ${TRIGGERS.join(", ")}`);
|
|
9364
9504
|
const files = list(o["files"]).map((f, n) => string(f, `${id}.files[${n}]`));
|
|
@@ -9373,7 +9513,8 @@ function parseRules(source, name) {
|
|
|
9373
9513
|
exclude: list(o["exclude"]).map((f, n) => string(f, `${id}.exclude[${n}]`)),
|
|
9374
9514
|
...o["match"] !== void 0 && { match: regex(o["match"], `${id}.match`, "gimu") },
|
|
9375
9515
|
...o["sibling"] !== void 0 && { sibling: string(o["sibling"], `${id}.sibling`) },
|
|
9376
|
-
script: o["script"] === void 0 ? o["match"] === void 0 : o["script"] === true
|
|
9516
|
+
script: o["script"] === void 0 ? o["match"] === void 0 : o["script"] === true,
|
|
9517
|
+
...o["decode"] === "xml" && { decode: "xml" }
|
|
9377
9518
|
};
|
|
9378
9519
|
}),
|
|
9379
9520
|
known: list(root["known"]).map((raw, i) => {
|
|
@@ -9407,12 +9548,12 @@ function bundledRules() {
|
|
|
9407
9548
|
}
|
|
9408
9549
|
return loadRulesFrom(join(import.meta.dirname, "..", "rules"));
|
|
9409
9550
|
}
|
|
9410
|
-
function findSignals(rules, text, context, file, firstLine = 1) {
|
|
9551
|
+
function findSignals(rules, text, context, file, firstLine = 1, onlyBroad = false) {
|
|
9411
9552
|
const body = text;
|
|
9412
9553
|
const out = [];
|
|
9413
9554
|
for (const rule of rules.signals) {
|
|
9414
9555
|
const severity = rule.severity[context];
|
|
9415
|
-
if (!severity) continue;
|
|
9556
|
+
if (!severity || onlyBroad && !rule.broad || !rule.all.every((p) => p.test(body))) continue;
|
|
9416
9557
|
let found;
|
|
9417
9558
|
search: for (const pattern of rule.patterns) {
|
|
9418
9559
|
for (const m of body.matchAll(pattern)) {
|
|
@@ -9463,6 +9604,7 @@ function excerpt(text, index, length) {
|
|
|
9463
9604
|
const cut = piece.indexOf("\n", index - from + Math.min(length, 400));
|
|
9464
9605
|
return shorten((cut < 0 ? piece : piece.slice(0, cut)).trim(), 240);
|
|
9465
9606
|
}
|
|
9607
|
+
var broadSignals = (rules) => new Set(rules.signals.filter((r) => r.broad).map((r) => r.id));
|
|
9466
9608
|
var isKnown = (rules, command) => rules.known.some((k) => k.commands.test(command.trim()));
|
|
9467
9609
|
|
|
9468
9610
|
// src/scan.ts
|
|
@@ -9675,6 +9817,8 @@ function agentSettings(doc, file, agent) {
|
|
|
9675
9817
|
}
|
|
9676
9818
|
const all = at(root, "enableAllProjectMcpServers");
|
|
9677
9819
|
if (all && value(all) === true) add("agent/auto-approve", all, "enableAllProjectMcpServers", { en: "Approves every MCP server of the project", es: "Aprueba todos los servidores MCP del proyecto" }, "high", "enableAllProjectMcpServers: true");
|
|
9820
|
+
const named = at(root, "enabledMcpjsonServers");
|
|
9821
|
+
if (named && items(named).length > 0) add("agent/auto-approve", named, "enabledMcpjsonServers", { en: "Approves MCP servers of the project by name", es: "Aprueba servidores MCP del proyecto por su nombre" }, "medium", items(named).map(str).filter(Boolean).join(", "));
|
|
9678
9822
|
const mode = at(root, "permissions", "defaultMode");
|
|
9679
9823
|
if (mode && /^(bypassPermissions|dontAsk)$/.test(str(mode) ?? "")) add("agent/auto-approve", mode, "permissions.defaultMode", { en: "Removes permission prompts", es: "Elimina las preguntas de permiso" }, "high", `defaultMode: ${str(mode)}`);
|
|
9680
9824
|
for (const rule of items(at(root, "permissions", "allow"))) {
|
|
@@ -9717,6 +9861,7 @@ var agentConfig = {
|
|
|
9717
9861
|
"**/.kiro/hooks/*",
|
|
9718
9862
|
"**/.kiro/agents/*.json",
|
|
9719
9863
|
"**/.cursor/environment.json",
|
|
9864
|
+
"**/.cursor/cli.json",
|
|
9720
9865
|
"**/hooks/hooks.json"
|
|
9721
9866
|
],
|
|
9722
9867
|
async detect(view, file) {
|
|
@@ -9726,6 +9871,24 @@ var agentConfig = {
|
|
|
9726
9871
|
if (!doc) return text.trim() ? [malformed(file.path, "agent")] : [];
|
|
9727
9872
|
const agent = agentName(file.path);
|
|
9728
9873
|
if (/settings(\.local)?\.json$/.test(file.canon)) return agentSettings(doc, file.path, agent);
|
|
9874
|
+
if (/\/cli\.json$/.test(file.canon)) {
|
|
9875
|
+
return items(at(doc.root, "permissions", "allow")).flatMap((rule) => {
|
|
9876
|
+
const text2 = str(rule) ?? "";
|
|
9877
|
+
if (!/^(Shell|Mcp)\((\*|[^)]*:?\*|(ba|z)?sh|curl|wget|node|python3?|sudo|rm)\)$|^\*$/i.test(text2)) return [];
|
|
9878
|
+
return [{
|
|
9879
|
+
id: "agent/auto-approve",
|
|
9880
|
+
trigger: "agent",
|
|
9881
|
+
file: file.path,
|
|
9882
|
+
line: doc.line(rule),
|
|
9883
|
+
key: `allow.${text2}`,
|
|
9884
|
+
title: { en: "Lets the agent run commands without asking", es: "Permite al agente ejecutar comandos sin preguntar" },
|
|
9885
|
+
severity: "medium",
|
|
9886
|
+
command: text2,
|
|
9887
|
+
needs: TRUST,
|
|
9888
|
+
cwd: projectDir(file.path)
|
|
9889
|
+
}];
|
|
9890
|
+
});
|
|
9891
|
+
}
|
|
9729
9892
|
if (/environment\.json$/.test(file.canon)) {
|
|
9730
9893
|
return ["install", "start", "update"].flatMap((key) => {
|
|
9731
9894
|
const node2 = at(doc.root, key);
|
|
@@ -10208,8 +10371,9 @@ var MAX_DEPTH = 6;
|
|
|
10208
10371
|
var INTERPRETER = /^(?:node|nodejs|bun|deno|tsx|ts-node|python[\d.]*|py|ruby|perl|php|pwsh|powershell|bash|sh|zsh|dash|cmd|source|\.|call)(?:\.exe)?$/i;
|
|
10209
10372
|
var SCRIPT_EXTENSIONS = ["", ".js", ".cjs", ".mjs", ".ts", ".sh", ".py", ".ps1", ".cmd", ".bat", ".rb", "/index.js", "/index.cjs", "/index.mjs", "/index.ts", "/__main__.py", "/__init__.py"];
|
|
10210
10373
|
var BINARY = /\.(png|jpe?g|gif|webp|ico|pdf|zip|gz|tgz|mp[34]|mov|wasm|exe|dll|so|dylib|node|lock)$/i;
|
|
10211
|
-
var DATA = /\.(json[c5]?|md|mdx|ya?ml|toml|css|s[ac]ss|less|html?|txt|xml|csv|svg|map|lock|snap|d\.ts|woff2?|ttf|otf|eot)$/i;
|
|
10374
|
+
var DATA = /\.(json[c5]?|md|mdx|ya?ml|toml|css|s[ac]ss|less|html?|txt|xml|csv|svg|map|lock|snap|bin|dat|d\.ts|woff2?|ttf|otf|eot)$/i;
|
|
10212
10375
|
var JS = /\.(c|m)?[jt]sx?$/i;
|
|
10376
|
+
var RUBY = /(\.(rb|gemspec|rake)|(^|\/)(gemfile|rakefile|podfile))$/i;
|
|
10213
10377
|
var SHELL = /\.(sh|bash|zsh|ps1|cmd|bat|envrc)$/i;
|
|
10214
10378
|
async function follow(view, start) {
|
|
10215
10379
|
const files = [];
|
|
@@ -10233,10 +10397,13 @@ async function follow(view, start) {
|
|
|
10233
10397
|
if (text === null) return;
|
|
10234
10398
|
const dir = dirname(file.path);
|
|
10235
10399
|
const head = text.slice(0, 200);
|
|
10236
|
-
|
|
10400
|
+
const locals = localImports(file.path, head, text);
|
|
10401
|
+
if (locals.length > MAX_IMPORTS) partial = true;
|
|
10402
|
+
for (const local of locals.slice(0, MAX_IMPORTS)) {
|
|
10237
10403
|
const target = resolveFile(view, dir, local);
|
|
10238
10404
|
if (target) await visitFile(target, depth + 1);
|
|
10239
10405
|
}
|
|
10406
|
+
for (const command of launchedPrograms(file.path, head, text)) await visitCommand(command, dir, depth, file.path);
|
|
10240
10407
|
if (SHELL.test(file.path) || basename(file.path) === ".envrc" || /^#!.*\b(ba|z|da)?sh\b/.test(head)) {
|
|
10241
10408
|
for (const line of text.split(/\r?\n/).slice(0, MAX_LINES)) {
|
|
10242
10409
|
if (!/^\s*#/.test(line) && line.trim()) await visitCommand(line, dir, depth + 1, file.path);
|
|
@@ -10253,7 +10420,10 @@ async function follow(view, start) {
|
|
|
10253
10420
|
const previous = words[i - 1] ?? "";
|
|
10254
10421
|
if (/^(npm|pnpm|yarn|bun)(\.cmd)?$/i.test(word)) {
|
|
10255
10422
|
const script = scriptName(words.slice(i + 1));
|
|
10256
|
-
if (script
|
|
10423
|
+
if (script && !await visitScript(script, cwd, depth + 1)) {
|
|
10424
|
+
const target2 = resolveFile(view, cwd, script);
|
|
10425
|
+
if (target2) await visitFile(target2, depth + 1, true);
|
|
10426
|
+
}
|
|
10257
10427
|
continue;
|
|
10258
10428
|
}
|
|
10259
10429
|
if (word === "-m" && /^(python[\d.]*|py)$/i.test(previous) && words[i + 1]) {
|
|
@@ -10271,6 +10441,7 @@ async function follow(view, start) {
|
|
|
10271
10441
|
}
|
|
10272
10442
|
};
|
|
10273
10443
|
const visitScript = async (name, cwd, depth) => {
|
|
10444
|
+
let found = false;
|
|
10274
10445
|
for (let dir = cwd; ; dir = dirname(dir)) {
|
|
10275
10446
|
const path = dir ? `${dir}/package.json` : "package.json";
|
|
10276
10447
|
const text = view.find(path) ? await view.text(path) : null;
|
|
@@ -10279,13 +10450,15 @@ async function follow(view, start) {
|
|
|
10279
10450
|
for (const key of [`pre${name}`, name, `post${name}`]) {
|
|
10280
10451
|
const node2 = at(doc.root, "scripts", key);
|
|
10281
10452
|
const body = str(node2);
|
|
10282
|
-
if (!node2 || !body
|
|
10453
|
+
if (!node2 || !body) continue;
|
|
10454
|
+
found = true;
|
|
10455
|
+
if (seenCommands.has(`${dir}\0${body}`)) continue;
|
|
10283
10456
|
commands.push({ text: body, file: view.find(path).path, line: doc.line(node2) });
|
|
10284
10457
|
await visitCommand(body, dir, depth);
|
|
10285
10458
|
}
|
|
10286
|
-
return;
|
|
10459
|
+
return found;
|
|
10287
10460
|
}
|
|
10288
|
-
if (dir === "") return;
|
|
10461
|
+
if (dir === "") return false;
|
|
10289
10462
|
}
|
|
10290
10463
|
};
|
|
10291
10464
|
for (const path of start.runs ?? []) await visitFile(path, 0, true);
|
|
@@ -10309,18 +10482,35 @@ function localImports(path, head, text) {
|
|
|
10309
10482
|
const out = /* @__PURE__ */ new Set();
|
|
10310
10483
|
if (JS.test(path) || /^#!.*\b(node|bun|deno)\b/.test(head)) {
|
|
10311
10484
|
for (const m of text.matchAll(/["'`](\.{1,2}\/[^"'`\n$]{1,200})["'`]/g)) out.add(m[1]);
|
|
10485
|
+
addScripts(text, out);
|
|
10486
|
+
} else if (RUBY.test(path)) {
|
|
10487
|
+
addScripts(text, out);
|
|
10312
10488
|
} else if (/\.py$/i.test(path) || /^#!.*python/.test(head)) {
|
|
10489
|
+
addScripts(text, out);
|
|
10313
10490
|
for (const m of text.matchAll(/^[ \t]*(?:from|import)[ \t]+\.?([A-Za-z_][\w.]{0,100})/gm)) out.add(m[1].replace(/\./g, "/"));
|
|
10314
10491
|
}
|
|
10315
|
-
return [...out]
|
|
10492
|
+
return [...out];
|
|
10493
|
+
}
|
|
10494
|
+
function addScripts(text, out) {
|
|
10495
|
+
for (const m of text.matchAll(/["'`]([\w@./-]{1,120}\.(?:[cm]?js|ts|py|rb|sh|ps1|bat|cmd))["'`]/g)) out.add(m[1]);
|
|
10496
|
+
}
|
|
10497
|
+
function launchedPrograms(path, head, text) {
|
|
10498
|
+
if (!JS.test(path) && !RUBY.test(path) && !/\.py$/i.test(path) && !/^#!.*\b(node|bun|deno|python|ruby)/.test(head)) return [];
|
|
10499
|
+
const out = /* @__PURE__ */ new Set();
|
|
10500
|
+
for (const m of text.matchAll(/\b(?:system|exec|execSync|spawn|spawnSync|popen|Popen|run|call|check_call|check_output|IO\.popen)\s*\(?\s*["'`]([^"'`\n]{3,400})["'`]/g)) {
|
|
10501
|
+
if (/\s/.test(m[1])) out.add(m[1]);
|
|
10502
|
+
if (out.size >= MAX_IMPORTS) break;
|
|
10503
|
+
}
|
|
10504
|
+
return [...out];
|
|
10316
10505
|
}
|
|
10317
10506
|
function scriptName(rest) {
|
|
10318
10507
|
const words = rest.filter((w) => !w.startsWith("-"));
|
|
10319
10508
|
const [first, second] = words;
|
|
10320
10509
|
if (!first) return null;
|
|
10321
10510
|
if (/^(run|run-script|rum|urn)$/.test(first)) return second ?? null;
|
|
10511
|
+
if (/^(exec|x)$/.test(first)) return null;
|
|
10322
10512
|
if (/^(install|i|ci|add|exec|x|dlx|create|init|publish|pack|link|update|config|set|cache)$/.test(first)) return null;
|
|
10323
|
-
return /^[\w
|
|
10513
|
+
return /^[\w:./-]+$/.test(first) ? first : null;
|
|
10324
10514
|
}
|
|
10325
10515
|
function tokenize(command) {
|
|
10326
10516
|
const out = [];
|
|
@@ -10366,7 +10556,7 @@ var node = {
|
|
|
10366
10556
|
const compiles = !scripts.some((s) => s.key === "install" || s.key === "preinstall");
|
|
10367
10557
|
const gypText = compiles && view.find(gyp) ? await view.text(gyp) : null;
|
|
10368
10558
|
if (gypText !== null) {
|
|
10369
|
-
const shell = /<!@?\(
|
|
10559
|
+
const shell = [...gypText.matchAll(/<!@?\(([^)\n]{1,400})\)/g)].map((m) => m[1]);
|
|
10370
10560
|
out.push({
|
|
10371
10561
|
id: "npm/binding-gyp",
|
|
10372
10562
|
trigger: "install",
|
|
@@ -10377,8 +10567,8 @@ var node = {
|
|
|
10377
10567
|
en: "Native build that npm starts by itself",
|
|
10378
10568
|
es: "Compilaci\xF3n nativa que npm inicia por su cuenta"
|
|
10379
10569
|
},
|
|
10380
|
-
severity: shell ? "medium" : "low",
|
|
10381
|
-
command: "node-gyp rebuild",
|
|
10570
|
+
severity: shell.length > 0 ? "medium" : "low",
|
|
10571
|
+
command: shell.length > 0 ? shell.join(" && ") : "node-gyp rebuild",
|
|
10382
10572
|
runs: [view.find(gyp).path],
|
|
10383
10573
|
cwd
|
|
10384
10574
|
});
|
|
@@ -10399,7 +10589,8 @@ var node = {
|
|
|
10399
10589
|
en: `Dependency from outside the registry: ${key}`,
|
|
10400
10590
|
es: `Dependencia de fuera del registro: ${key}`
|
|
10401
10591
|
},
|
|
10402
|
-
|
|
10592
|
+
// A pinned commit of a fork is still reachable from the original repository.
|
|
10593
|
+
severity: /^http:/i.test(spec) ? "high" : plain || field === "optionalDependencies" ? "medium" : pinned ? "info" : "low",
|
|
10403
10594
|
command: `${key}@${spec}`
|
|
10404
10595
|
});
|
|
10405
10596
|
}
|
|
@@ -10450,7 +10641,8 @@ function folderOpenTasks(doc, holder, file, cwd) {
|
|
|
10450
10641
|
const always = str(at(holder, "runOptions", "runOn")) === "folderOpen";
|
|
10451
10642
|
const out = [];
|
|
10452
10643
|
tasks.forEach((task, index) => {
|
|
10453
|
-
|
|
10644
|
+
const runOn = str(at(task, "runOptions", "runOn")) ?? str(at(task, "runOn"));
|
|
10645
|
+
if (!always && runOn !== "folderOpen") return;
|
|
10454
10646
|
const label = labelOf(task) || `#${index + 1}`;
|
|
10455
10647
|
const commands = [];
|
|
10456
10648
|
const visit2 = (t2, seen) => {
|
|
@@ -10511,7 +10703,7 @@ function programSettings(doc, holder, file, cwd) {
|
|
|
10511
10703
|
line: doc.line(node2),
|
|
10512
10704
|
key,
|
|
10513
10705
|
title: grantsTrust ? { en: `Setting that loosens a protection: ${key}`, es: `Ajuste que relaja una protecci\xF3n: ${key}` } : { en: `Setting that chooses a program to run: ${key}`, es: `Ajuste que elige un programa que se ejecutar\xE1: ${key}` },
|
|
10514
|
-
severity: grantsTrust ? "medium" : local ? "low" : "info",
|
|
10706
|
+
severity: /^chat\.tools\.(global\.)?autoApprove$/i.test(key) ? "high" : grantsTrust ? "medium" : local ? "low" : "info",
|
|
10515
10707
|
command: text,
|
|
10516
10708
|
needs: NEEDS_FOLDER_TRUST,
|
|
10517
10709
|
cwd
|
|
@@ -10519,7 +10711,7 @@ function programSettings(doc, holder, file, cwd) {
|
|
|
10519
10711
|
});
|
|
10520
10712
|
}
|
|
10521
10713
|
var vscode = {
|
|
10522
|
-
files: ["**/.vscode/tasks.json", "**/.vscode/settings.json", "**/*.code-workspace"],
|
|
10714
|
+
files: ["**/.{vscode,cursor,windsurf}/tasks.json", "**/.vscode/settings.json", "**/*.code-workspace"],
|
|
10523
10715
|
async detect(view, file) {
|
|
10524
10716
|
const text = await view.text(file.path);
|
|
10525
10717
|
if (text === null) return [];
|
|
@@ -10541,6 +10733,14 @@ var vscode = {
|
|
|
10541
10733
|
|
|
10542
10734
|
// src/detectors/index.ts
|
|
10543
10735
|
var MAX_PER_FILE = 500;
|
|
10736
|
+
function decodeXml(text) {
|
|
10737
|
+
const names = { lt: "<", gt: ">", amp: "&", quot: '"', apos: "'" };
|
|
10738
|
+
return text.replace(/&(?:#x([0-9a-f]{1,6})|#(\d{1,7})|(\w{2,4}));/gi, (all, hex, dec, name) => {
|
|
10739
|
+
if (name) return names[name.toLowerCase()] ?? all;
|
|
10740
|
+
const code2 = hex ? parseInt(hex, 16) : Number(dec);
|
|
10741
|
+
return code2 <= 1114111 ? String.fromCodePoint(code2) : all;
|
|
10742
|
+
});
|
|
10743
|
+
}
|
|
10544
10744
|
function fromRule(rule) {
|
|
10545
10745
|
return {
|
|
10546
10746
|
files: rule.files,
|
|
@@ -10562,7 +10762,8 @@ function fromRule(rule) {
|
|
|
10562
10762
|
if (text === null) return [];
|
|
10563
10763
|
const out = [];
|
|
10564
10764
|
for (const m of text.matchAll(rule.match)) {
|
|
10565
|
-
const
|
|
10765
|
+
const written = (Object.values(m.groups ?? {}).find((g) => g !== void 0) ?? m[1] ?? m[0]).trim();
|
|
10766
|
+
const command = rule.decode === "xml" ? decodeXml(written) : written;
|
|
10566
10767
|
out.push({ ...base, line: lineAt(text, m.index + m[0].search(/\S|$/)), key: command, command, ...rule.script && { runs: [file.path] } });
|
|
10567
10768
|
if (out.length >= MAX_PER_FILE) {
|
|
10568
10769
|
view.gaps.push({ en: `Too many matches in ${file.path}`, es: `Demasiadas coincidencias en ${file.path}` });
|
|
@@ -10667,6 +10868,15 @@ var RepoView = class {
|
|
|
10667
10868
|
}
|
|
10668
10869
|
return text;
|
|
10669
10870
|
}
|
|
10871
|
+
/** Reads a file without keeping it and without reporting a problem. */
|
|
10872
|
+
async peek(path, maxBytes) {
|
|
10873
|
+
const file = this.find(path);
|
|
10874
|
+
if (!file) return null;
|
|
10875
|
+
const known = this.texts.get(file.real);
|
|
10876
|
+
if (known) return known;
|
|
10877
|
+
const bytes = await this.raw.read(file.real);
|
|
10878
|
+
return bytes === null || bytes.length > maxBytes ? null : decode(bytes);
|
|
10879
|
+
}
|
|
10670
10880
|
async load(file) {
|
|
10671
10881
|
const bytes = await this.raw.read(file.real);
|
|
10672
10882
|
if (bytes !== null) return decode(bytes);
|
|
@@ -10688,7 +10898,12 @@ function decode(bytes) {
|
|
|
10688
10898
|
}
|
|
10689
10899
|
|
|
10690
10900
|
// src/scan.ts
|
|
10691
|
-
|
|
10901
|
+
var SOURCE = /\.([cm]?[jt]sx?|py|pyw|rb|php|pl|lua|sh|bash|zsh|ps1|bat|cmd|vbs|go|rs|cs|vb)$/;
|
|
10902
|
+
var NOT_SOURCE = /(^|\/)(node_modules|\.git|\.yarn|\.pnp\.[cm]?js)(\/|$)/;
|
|
10903
|
+
var SAMPLES = /(^|\/)(tests?|__tests__|specs?|testdata|test-data|fixtures?|__fixtures__|baselines?|snapshots?|examples?|benchmarks?|vendor|third[_-]?party|external)\/|[._-](test|spec|bench)\.\w+$|(^|\/)test_[^/]+$/;
|
|
10904
|
+
var MAX_SOURCE_BYTES = 1024 * 1024;
|
|
10905
|
+
var READ_AHEAD = 128;
|
|
10906
|
+
async function scan(tree, rules, options = {}) {
|
|
10692
10907
|
const view = new RepoView(tree);
|
|
10693
10908
|
const raw = [];
|
|
10694
10909
|
const all = detectors(rules);
|
|
@@ -10711,6 +10926,18 @@ async function scan(tree, rules) {
|
|
|
10711
10926
|
command: link.target
|
|
10712
10927
|
});
|
|
10713
10928
|
}
|
|
10929
|
+
for (const file of view.files) {
|
|
10930
|
+
if (!/[\u{200e}\u{200f}\u{202a}-\u{202e}\u{2066}-\u{2069}]/u.test(file.path)) continue;
|
|
10931
|
+
raw.push({
|
|
10932
|
+
id: "disguised-name",
|
|
10933
|
+
trigger: "run",
|
|
10934
|
+
file: file.path,
|
|
10935
|
+
line: 1,
|
|
10936
|
+
key: "name",
|
|
10937
|
+
severity: "high",
|
|
10938
|
+
title: { en: "File name written to look like another one", es: "Nombre de archivo escrito para parecer otro" }
|
|
10939
|
+
});
|
|
10940
|
+
}
|
|
10714
10941
|
const points = [];
|
|
10715
10942
|
const scripts = /* @__PURE__ */ new Map();
|
|
10716
10943
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -10720,9 +10947,40 @@ async function scan(tree, rules) {
|
|
|
10720
10947
|
seen.add(id);
|
|
10721
10948
|
points.push(await evaluate(view, rules, point2, scripts));
|
|
10722
10949
|
}
|
|
10950
|
+
points.push(...await hiddenCode(view, rules, points, options));
|
|
10723
10951
|
points.sort((a, b) => TRIGGERS.indexOf(a.trigger) - TRIGGERS.indexOf(b.trigger) || rank(b.severity) - rank(a.severity) || a.file.split("/").length - b.file.split("/").length || (a.file < b.file ? -1 : a.file > b.file ? 1 : 0) || a.line - b.line);
|
|
10724
10952
|
return { target: view.label, points, filesListed: view.files.length, gaps: view.gaps };
|
|
10725
10953
|
}
|
|
10954
|
+
var SETTINGS = /* @__PURE__ */ new Set(["vscode/program-setting", "agent/auto-approve", "agent/plugins", "agent/redirect", "agent/inject"]);
|
|
10955
|
+
async function hiddenCode(view, rules, points, options) {
|
|
10956
|
+
const reported = new Set(points.filter((p) => rank(p.severity) >= rank("medium")).flatMap((p) => [p.file, ...p.follows]));
|
|
10957
|
+
const out = [];
|
|
10958
|
+
const sources = view.files.filter((file) => SOURCE.test(file.canon) && !NOT_SOURCE.test(file.canon) && !reported.has(file.path) && !options.unchanged?.(file.real));
|
|
10959
|
+
for (let i = 0; i < sources.length; i += READ_AHEAD) {
|
|
10960
|
+
const batch = sources.slice(i, i + READ_AHEAD);
|
|
10961
|
+
const texts = await Promise.all(batch.map((file) => view.peek(file.path, MAX_SOURCE_BYTES)));
|
|
10962
|
+
for (const [n, file] of batch.entries()) {
|
|
10963
|
+
const text = texts[n] ?? null;
|
|
10964
|
+
if (text === null) continue;
|
|
10965
|
+
const signals = findSignals(rules, text, "script", file.path, 1, true).filter((s) => rank(s.severity) >= rank("medium"));
|
|
10966
|
+
if (signals.length === 0) continue;
|
|
10967
|
+
out.push({
|
|
10968
|
+
id: "code/hidden",
|
|
10969
|
+
trigger: "run",
|
|
10970
|
+
file: file.path,
|
|
10971
|
+
line: signals[0].line,
|
|
10972
|
+
key: "hidden",
|
|
10973
|
+
title: { en: "Code that tries not to be seen", es: "C\xF3digo que intenta no ser visto" },
|
|
10974
|
+
severity: SAMPLES.test(file.canon) ? "low" : signals.reduce((s, x) => worst(s, x.severity), "medium"),
|
|
10975
|
+
signals,
|
|
10976
|
+
follows: [],
|
|
10977
|
+
partial: false,
|
|
10978
|
+
fingerprint: createHash("sha256").update(text).digest("hex").slice(0, 16)
|
|
10979
|
+
});
|
|
10980
|
+
}
|
|
10981
|
+
}
|
|
10982
|
+
return out;
|
|
10983
|
+
}
|
|
10726
10984
|
async function readScript(view, rules, file) {
|
|
10727
10985
|
const text = await view.text(file);
|
|
10728
10986
|
if (text === null) return { signals: [], digest: "unreadable" };
|
|
@@ -10756,11 +11014,27 @@ async function evaluate(view, rules, point2, scripts) {
|
|
|
10756
11014
|
if (!facts) scripts.set(file, facts = readScript(view, rules, file));
|
|
10757
11015
|
const { signals: found, digest } = await facts;
|
|
10758
11016
|
hash.update(`${file} ${digest}`);
|
|
10759
|
-
|
|
11017
|
+
const sample = point2.severity === "info" && SAMPLES.test(canonical(file));
|
|
11018
|
+
signals.push(...found.map((s) => sample && rank(s.severity) > rank("low") ? { ...s, severity: "low" } : s));
|
|
10760
11019
|
}
|
|
10761
11020
|
const partial = reached.partial && point2.severity !== "info";
|
|
11021
|
+
if (point2.instructions !== void 0) {
|
|
11022
|
+
const broad = broadSignals(rules);
|
|
11023
|
+
for (const command of writtenCommands(point2.instructions)) {
|
|
11024
|
+
const told = await follow(view, { command, cwd: projectOf(point2.file), maxDepth: 2 });
|
|
11025
|
+
for (const file of told.files) {
|
|
11026
|
+
let facts = scripts.get(file);
|
|
11027
|
+
if (!facts) scripts.set(file, facts = readScript(view, rules, file));
|
|
11028
|
+
const { signals: found, digest } = await facts;
|
|
11029
|
+
const strong = found.filter((s) => s.severity === "high" && broad.has(s.id));
|
|
11030
|
+
if (strong.length === 0) continue;
|
|
11031
|
+
hash.update(`${file} ${digest}`);
|
|
11032
|
+
signals.push(...strong);
|
|
11033
|
+
}
|
|
11034
|
+
}
|
|
11035
|
+
}
|
|
10762
11036
|
const unique = signals.filter((s, i) => signals.findIndex((o) => o.id === s.id && o.file === s.file) === i).sort((a, b) => rank(b.severity) - rank(a.severity));
|
|
10763
|
-
const base = point2.command && point2.severity === "medium" && isKnown(rules, point2.command) ? "low" : point2.severity;
|
|
11037
|
+
const base = point2.command && point2.severity === "medium" && !SETTINGS.has(point2.id) && isKnown(rules, point2.command) ? "low" : point2.severity;
|
|
10764
11038
|
const { cwd: _cwd, runs: _runs, instructions: _text, signals: _signals, ...rest } = point2;
|
|
10765
11039
|
return {
|
|
10766
11040
|
...rest,
|
|
@@ -10772,6 +11046,19 @@ async function evaluate(view, rules, point2, scripts) {
|
|
|
10772
11046
|
fingerprint: hash.digest("hex").slice(0, 16)
|
|
10773
11047
|
};
|
|
10774
11048
|
}
|
|
11049
|
+
function writtenCommands(text) {
|
|
11050
|
+
const out = /* @__PURE__ */ new Set();
|
|
11051
|
+
for (const m of text.matchAll(/`([^`\n]{3,300})`/g)) out.add(m[1]);
|
|
11052
|
+
for (const block of text.matchAll(/```[^\n]*\n([\s\S]{1,4000}?)```/g)) {
|
|
11053
|
+
for (const line of block[1].split(/\r?\n/)) if (line.trim()) out.add(line.trim().replace(/^\$ /, ""));
|
|
11054
|
+
}
|
|
11055
|
+
return [...out].filter((c) => /[\w./-]+\.\w{1,5}\b/.test(c)).slice(0, 100);
|
|
11056
|
+
}
|
|
11057
|
+
var projectOf = (path) => {
|
|
11058
|
+
const parts = path.split("/").slice(0, -1);
|
|
11059
|
+
const dot = parts.findIndex((p) => p.startsWith("."));
|
|
11060
|
+
return (dot < 0 ? parts : parts.slice(0, dot)).join("/");
|
|
11061
|
+
};
|
|
10775
11062
|
function compare(before, after) {
|
|
10776
11063
|
const identity = (p) => `${p.id}\0${p.file.toLowerCase()}\0${p.key}`;
|
|
10777
11064
|
const old = /* @__PURE__ */ new Map();
|
|
@@ -11063,6 +11350,7 @@ async function openTree(dir, sha, label, onClose) {
|
|
|
11063
11350
|
files: [...shas.keys()],
|
|
11064
11351
|
links,
|
|
11065
11352
|
gaps,
|
|
11353
|
+
id: (path) => shas.get(path),
|
|
11066
11354
|
read: async (path) => {
|
|
11067
11355
|
const id = shas.get(path);
|
|
11068
11356
|
return id ? objects.read(id) : null;
|
|
@@ -11227,7 +11515,7 @@ async function localTree(root) {
|
|
|
11227
11515
|
}
|
|
11228
11516
|
|
|
11229
11517
|
// src/cli.ts
|
|
11230
|
-
var VERSION = false ? "dev" : "0.1.
|
|
11518
|
+
var VERSION = false ? "dev" : "0.1.2";
|
|
11231
11519
|
var HELP = {
|
|
11232
11520
|
en: `beforeopen ${VERSION}
|
|
11233
11521
|
See what a repository will run on your machine before you open it.
|
|
@@ -11344,7 +11632,8 @@ async function main(argv) {
|
|
|
11344
11632
|
const [from, to] = [await git.resolve(base), await git.resolve(head)];
|
|
11345
11633
|
const before = await git.tree(from, base);
|
|
11346
11634
|
const after = await git.tree(to, head);
|
|
11347
|
-
const
|
|
11635
|
+
const same = { unchanged: (path) => before.id?.(path) !== void 0 && before.id(path) === after.id?.(path) };
|
|
11636
|
+
const [a, b] = [await scan(before, rules, same), await scan(after, rules, same)];
|
|
11348
11637
|
const changes = compare(a, b);
|
|
11349
11638
|
const title = `${base} \u2192 ${head}`;
|
|
11350
11639
|
process.stdout.write(
|