@tobi-or-not/quorum 0.5.0 → 0.6.0
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.md +2 -0
- package/dist/bench/fingerprint.d.ts +6 -5
- package/dist/bench/fingerprint.js +11 -5
- package/dist/bench/records.d.ts +100 -2
- package/dist/bench/records.js +80 -5
- package/dist/bench/runner.js +1 -1
- package/dist/cli/io.d.ts +5 -0
- package/dist/cli/main.d.ts +36 -13
- package/dist/cli/main.js +194 -44
- package/dist/cli/print-config.d.ts +5 -5
- package/dist/cli/print-config.js +10 -5
- package/dist/cli/render.d.ts +7 -1
- package/dist/cli/render.js +25 -3
- package/dist/config/claude-code.d.ts +2 -6
- package/dist/config/claude-code.js +6 -44
- package/dist/config/command.d.ts +10 -0
- package/dist/config/command.js +47 -0
- package/dist/config/from-config.js +8 -2
- package/dist/config/resolve.d.ts +4 -0
- package/dist/config/resolve.js +10 -0
- package/dist/config/schema.d.ts +13 -2
- package/dist/config/schema.js +36 -5
- package/dist/core/coverage.d.ts +38 -13
- package/dist/core/coverage.js +105 -28
- package/dist/core/diff.d.ts +77 -0
- package/dist/core/diff.js +122 -24
- package/dist/core/estimate.d.ts +45 -0
- package/dist/core/estimate.js +188 -0
- package/dist/core/flags.d.ts +14 -1
- package/dist/core/flags.js +56 -0
- package/dist/core/inputs.d.ts +38 -0
- package/dist/core/inputs.js +228 -0
- package/dist/core/limits.d.ts +5 -4
- package/dist/core/limits.js +11 -5
- package/dist/core/parts.d.ts +146 -0
- package/dist/core/parts.js +388 -0
- package/dist/core/ports.d.ts +10 -0
- package/dist/core/prompts.d.ts +22 -3
- package/dist/core/prompts.js +43 -7
- package/dist/core/quorum.d.ts +7 -5
- package/dist/core/quorum.js +164 -58
- package/dist/core/secrets.d.ts +98 -0
- package/dist/core/secrets.js +507 -0
- package/dist/core/stages/context.d.ts +16 -3
- package/dist/core/stages/context.js +44 -17
- package/dist/core/stages/panel.d.ts +8 -2
- package/dist/core/stages/panel.js +50 -9
- package/dist/core/stages/research.d.ts +107 -31
- package/dist/core/stages/research.js +290 -53
- package/dist/core/types.d.ts +217 -29
- package/dist/core/verify.d.ts +6 -0
- package/dist/core/verify.js +6 -3
- package/dist/git/run.d.ts +223 -0
- package/dist/git/run.js +608 -0
- package/dist/git/tree.d.ts +43 -0
- package/dist/git/tree.js +171 -0
- package/dist/index.d.ts +26 -2
- package/dist/index.js +34 -2
- package/dist/providers/anthropic.d.ts +2 -1
- package/dist/providers/anthropic.js +4 -2
- package/dist/providers/claude-code.d.ts +5 -0
- package/dist/providers/claude-code.js +11 -1
- package/dist/providers/gemini.d.ts +2 -1
- package/dist/providers/gemini.js +4 -2
- package/dist/providers/ollama.d.ts +2 -1
- package/dist/providers/ollama.js +4 -2
- package/dist/providers/openai-compatible.d.ts +2 -1
- package/dist/providers/openai-compatible.js +4 -2
- package/dist/providers/size.d.ts +9 -1
- package/dist/providers/size.js +18 -4
- package/dist/sources/added.d.ts +49 -0
- package/dist/sources/added.js +134 -0
- package/dist/sources/diff.d.ts +13 -0
- package/dist/sources/diff.js +63 -0
- package/dist/sources/local.d.ts +41 -0
- package/dist/sources/local.js +251 -0
- package/dist/sources/paths.d.ts +45 -0
- package/dist/sources/paths.js +230 -0
- package/dist/sources/range.d.ts +21 -0
- package/dist/sources/range.js +75 -0
- package/dist/sources/read.d.ts +69 -0
- package/dist/sources/read.js +37 -0
- package/dist/sources/repository.d.ts +9 -0
- package/dist/sources/repository.js +28 -0
- package/dist/sources/skips.d.ts +49 -0
- package/dist/sources/skips.js +126 -0
- package/package.json +1 -1
- package/schema/quorum.schema.json +15 -0
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* The credential rules below are gitleaks 8.30.1's, and the private-key markers are
|
|
3
|
+
* pre-commit-hooks v5.0.0's. Both are MIT licensed:
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2019 Zachary Rice
|
|
6
|
+
* Copyright (c) 2014 pre-commit dev team: Anthony Sottile, Ken Struys
|
|
7
|
+
*
|
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
* furnished to do so, subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
* copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
* SOFTWARE.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* What holds a file back from every review: its name, or a credential it holds. Pure functions over a
|
|
28
|
+
* path and a diff's text, which the sources and the review apply before any model is sent a line.
|
|
29
|
+
* Every check is generous (a hunk row that reads like a header names a path, a removed line holds a
|
|
30
|
+
* key as an added one does), so a doubtful file is held and never sent.
|
|
31
|
+
*
|
|
32
|
+
* @see ../../docs/20-using/15-sources.md#files-held-back-as-secrets for what a reader sees.
|
|
33
|
+
*/
|
|
34
|
+
import { headerNames, namedPaths, namesOldSide } from "./diff.js";
|
|
35
|
+
/** The names of files that hold a secret, matched whole against a path's last segment, in any case. */
|
|
36
|
+
export const SECRET_NAMES = Object.freeze([
|
|
37
|
+
'.env',
|
|
38
|
+
'.npmrc',
|
|
39
|
+
'.pypirc',
|
|
40
|
+
'.netrc',
|
|
41
|
+
'_netrc',
|
|
42
|
+
'.git-credentials',
|
|
43
|
+
'.pgpass',
|
|
44
|
+
'.htpasswd',
|
|
45
|
+
'id_rsa',
|
|
46
|
+
'id_dsa',
|
|
47
|
+
'id_ecdsa',
|
|
48
|
+
'id_ed25519',
|
|
49
|
+
'credentials',
|
|
50
|
+
'credentials.json',
|
|
51
|
+
'secrets.json',
|
|
52
|
+
'secrets.toml',
|
|
53
|
+
'secrets.yaml',
|
|
54
|
+
'secrets.yml',
|
|
55
|
+
]);
|
|
56
|
+
/** A name that starts with this is a secret's: `.env.local`, and `.env.defaults`, which a loader reads as values at run time. In any case. */
|
|
57
|
+
export const SECRET_PREFIX = '.env.';
|
|
58
|
+
/** What the name of a file that holds a secret ends with, in any case. */
|
|
59
|
+
export const SECRET_SUFFIXES = Object.freeze([
|
|
60
|
+
'.pem',
|
|
61
|
+
'.key',
|
|
62
|
+
'.p12',
|
|
63
|
+
'.pfx',
|
|
64
|
+
'.jks',
|
|
65
|
+
'.keystore',
|
|
66
|
+
'.ppk',
|
|
67
|
+
'.kdbx',
|
|
68
|
+
'.tfstate',
|
|
69
|
+
'.tfstate.backup',
|
|
70
|
+
]);
|
|
71
|
+
/** What ends the name of a template, after `SECRET_PREFIX`: `.env.example` is committed with no value in it, and is sent. In any case. */
|
|
72
|
+
export const TEMPLATE_SUFFIXES = Object.freeze([
|
|
73
|
+
'.example',
|
|
74
|
+
'.sample',
|
|
75
|
+
'.template',
|
|
76
|
+
'.dist',
|
|
77
|
+
]);
|
|
78
|
+
/** The directory of a Helm chart's templates: its `secrets.yaml` and `secrets.yml` are templates, not secrets. */
|
|
79
|
+
const HELM_TEMPLATES = 'templates';
|
|
80
|
+
const HELM_SECRET_TEMPLATES = ['secrets.yaml', 'secrets.yml'];
|
|
81
|
+
/** Every rule a file can be held by, in the order a reader lists them. */
|
|
82
|
+
export const SECRET_RULES = Object.freeze([
|
|
83
|
+
'name',
|
|
84
|
+
'private-key',
|
|
85
|
+
'aws-key',
|
|
86
|
+
'github-token',
|
|
87
|
+
'slack-token',
|
|
88
|
+
'google-key',
|
|
89
|
+
'stripe-key',
|
|
90
|
+
'anthropic-key',
|
|
91
|
+
'openai-key',
|
|
92
|
+
]);
|
|
93
|
+
/** What a kind of credential is called in a sentence, after "holds what reads as". */
|
|
94
|
+
export const CREDENTIAL_PHRASES = Object.freeze({
|
|
95
|
+
'private-key': 'a private key',
|
|
96
|
+
'aws-key': 'an AWS key',
|
|
97
|
+
'github-token': 'a GitHub token',
|
|
98
|
+
'slack-token': 'a Slack token or webhook',
|
|
99
|
+
'google-key': 'a Google API key',
|
|
100
|
+
'stripe-key': 'a Stripe key',
|
|
101
|
+
'anthropic-key': 'an Anthropic key',
|
|
102
|
+
'openai-key': 'an OpenAI key',
|
|
103
|
+
});
|
|
104
|
+
/* eslint-disable regexp/prefer-w, regexp/prefer-d, regexp/optimal-quantifier-concatenation -- gitleaks 8.30.1's patterns, kept as it ships them so they compare with its config */
|
|
105
|
+
/** The 21 rules of gitleaks 8.30.1 for AWS, GitHub, Slack, Google, Stripe, Anthropic and OpenAI, grouped by kind, in the order of `SECRET_RULES`. */
|
|
106
|
+
export const CREDENTIAL_RULES = Object.freeze([
|
|
107
|
+
{
|
|
108
|
+
kind: 'aws-key',
|
|
109
|
+
id: 'aws-access-token',
|
|
110
|
+
pattern: /\b((?:A3T[A-Z0-9]|AKIA|ASIA|ABIA|ACCA)[A-Z2-7]{16})\b/,
|
|
111
|
+
entropy: 3,
|
|
112
|
+
allow: /.+EXAMPLE$/,
|
|
113
|
+
keywords: ['a3t', 'akia', 'asia', 'abia', 'acca'],
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
kind: 'aws-key',
|
|
117
|
+
id: 'aws-amazon-bedrock-api-key-long-lived',
|
|
118
|
+
pattern: /\b(ABSK[A-Za-z0-9+/]{109,269}={0,2})(?:[\x60'"\s;]|\\[nr]|$)/,
|
|
119
|
+
entropy: 3,
|
|
120
|
+
keywords: ['absk'],
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
kind: 'github-token',
|
|
124
|
+
id: 'github-pat',
|
|
125
|
+
pattern: /ghp_[0-9a-zA-Z]{36}/,
|
|
126
|
+
entropy: 3,
|
|
127
|
+
keywords: ['ghp_'],
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
kind: 'github-token',
|
|
131
|
+
id: 'github-fine-grained-pat',
|
|
132
|
+
pattern: /github_pat_\w{82}/,
|
|
133
|
+
entropy: 3,
|
|
134
|
+
keywords: ['github_pat_'],
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
kind: 'github-token',
|
|
138
|
+
id: 'github-oauth',
|
|
139
|
+
pattern: /gho_[0-9a-zA-Z]{36}/,
|
|
140
|
+
entropy: 3,
|
|
141
|
+
keywords: ['gho_'],
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
kind: 'github-token',
|
|
145
|
+
id: 'github-app-token',
|
|
146
|
+
pattern: /(?:ghu|ghs)_[0-9a-zA-Z]{36}/,
|
|
147
|
+
entropy: 3,
|
|
148
|
+
keywords: ['ghu_', 'ghs_'],
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
kind: 'github-token',
|
|
152
|
+
id: 'github-refresh-token',
|
|
153
|
+
pattern: /ghr_[0-9a-zA-Z]{36}/,
|
|
154
|
+
entropy: 3,
|
|
155
|
+
keywords: ['ghr_'],
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
kind: 'slack-token',
|
|
159
|
+
id: 'slack-bot-token',
|
|
160
|
+
pattern: /xoxb-[0-9]{10,13}-[0-9]{10,13}[a-zA-Z0-9-]*/,
|
|
161
|
+
entropy: 3,
|
|
162
|
+
keywords: ['xoxb'],
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
kind: 'slack-token',
|
|
166
|
+
id: 'slack-user-token',
|
|
167
|
+
pattern: /xox[pe](?:-[0-9]{10,13}){3}-[a-zA-Z0-9-]{28,34}/,
|
|
168
|
+
entropy: 2,
|
|
169
|
+
keywords: ['xoxp-', 'xoxe-'],
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
kind: 'slack-token',
|
|
173
|
+
id: 'slack-app-token',
|
|
174
|
+
pattern: /xapp-\d-[A-Z0-9]+-\d+-[a-z0-9]+/i,
|
|
175
|
+
entropy: 2,
|
|
176
|
+
keywords: ['xapp'],
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
kind: 'slack-token',
|
|
180
|
+
id: 'slack-config-access-token',
|
|
181
|
+
pattern: /xoxe.xox[bp]-\d-[A-Z0-9]{163,166}/i,
|
|
182
|
+
entropy: 2,
|
|
183
|
+
keywords: ['xoxe.xoxb-', 'xoxe.xoxp-'],
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
kind: 'slack-token',
|
|
187
|
+
id: 'slack-config-refresh-token',
|
|
188
|
+
pattern: /xoxe-\d-[A-Z0-9]{146}/i,
|
|
189
|
+
entropy: 2,
|
|
190
|
+
keywords: ['xoxe-'],
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
kind: 'slack-token',
|
|
194
|
+
id: 'slack-legacy-bot-token',
|
|
195
|
+
pattern: /xoxb-[0-9]{8,14}-[a-zA-Z0-9]{18,26}/,
|
|
196
|
+
entropy: 2,
|
|
197
|
+
keywords: ['xoxb'],
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
kind: 'slack-token',
|
|
201
|
+
id: 'slack-legacy-token',
|
|
202
|
+
pattern: /xox[os]-\d+-\d+-\d+-[a-fA-F\d]+/,
|
|
203
|
+
entropy: 2,
|
|
204
|
+
keywords: ['xoxo', 'xoxs'],
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
kind: 'slack-token',
|
|
208
|
+
id: 'slack-legacy-workspace-token',
|
|
209
|
+
pattern: /xox[ar]-(?:\d-)?[0-9a-zA-Z]{8,48}/,
|
|
210
|
+
entropy: 2,
|
|
211
|
+
keywords: ['xoxa', 'xoxr'],
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
kind: 'slack-token',
|
|
215
|
+
id: 'slack-webhook-url',
|
|
216
|
+
pattern: /(?:https?:\/\/)?hooks.slack.com\/(?:services|workflows|triggers)\/[A-Za-z0-9+/]{43,56}/,
|
|
217
|
+
keywords: ['hooks.slack.com'],
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
kind: 'google-key',
|
|
221
|
+
id: 'gcp-api-key',
|
|
222
|
+
pattern: /\b(AIza[\w-]{35})(?:[\x60'"\s;]|\\[nr]|$)/,
|
|
223
|
+
entropy: 4,
|
|
224
|
+
keywords: ['aiza'],
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
kind: 'stripe-key',
|
|
228
|
+
id: 'stripe-access-token',
|
|
229
|
+
pattern: /\b((?:sk|rk)_(?:test|live|prod)_[a-zA-Z0-9]{10,99})(?:[\x60'"\s;]|\\[nr]|$)/,
|
|
230
|
+
entropy: 2,
|
|
231
|
+
keywords: [
|
|
232
|
+
'sk_test',
|
|
233
|
+
'sk_live',
|
|
234
|
+
'sk_prod',
|
|
235
|
+
'rk_test',
|
|
236
|
+
'rk_live',
|
|
237
|
+
'rk_prod',
|
|
238
|
+
],
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
kind: 'anthropic-key',
|
|
242
|
+
id: 'anthropic-api-key',
|
|
243
|
+
pattern: /\b(sk-ant-api03-[a-zA-Z0-9_\-]{93}AA)(?:[\x60'"\s;]|\\[nr]|$)/,
|
|
244
|
+
keywords: ['sk-ant-api03'],
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
kind: 'anthropic-key',
|
|
248
|
+
id: 'anthropic-admin-api-key',
|
|
249
|
+
pattern: /\b(sk-ant-admin01-[a-zA-Z0-9_\-]{93}AA)(?:[\x60'"\s;]|\\[nr]|$)/,
|
|
250
|
+
keywords: ['sk-ant-admin01'],
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
kind: 'openai-key',
|
|
254
|
+
id: 'openai-api-key',
|
|
255
|
+
pattern: /\b(sk-(?:proj|svcacct|admin)-(?:[A-Za-z0-9_-]{74}|[A-Za-z0-9_-]{58})T3BlbkFJ(?:[A-Za-z0-9_-]{74}|[A-Za-z0-9_-]{58})\b|sk-[a-zA-Z0-9]{20}T3BlbkFJ[a-zA-Z0-9]{20})(?:[\x60'"\s;]|\\[nr]|$)/,
|
|
256
|
+
entropy: 3,
|
|
257
|
+
keywords: ['t3blbkfj'],
|
|
258
|
+
},
|
|
259
|
+
]);
|
|
260
|
+
/* eslint-enable regexp/prefer-w, regexp/prefer-d, regexp/optimal-quantifier-concatenation */
|
|
261
|
+
/**
|
|
262
|
+
* The private-key markers of pre-commit-hooks v5.0.0, matched as substrings, case and all. A source
|
|
263
|
+
* that spells one holds itself, so each is built from pieces and none is contiguous here.
|
|
264
|
+
*/
|
|
265
|
+
const PRIVATE_KEY_MARKERS = Object.freeze([
|
|
266
|
+
...[
|
|
267
|
+
'RSA ',
|
|
268
|
+
'DSA ',
|
|
269
|
+
'EC ',
|
|
270
|
+
'OPENSSH ',
|
|
271
|
+
'',
|
|
272
|
+
'SSH2 ENCRYPTED ',
|
|
273
|
+
'ENCRYPTED ',
|
|
274
|
+
].map(kind => `BEGIN ${kind}PRIVATE KEY`),
|
|
275
|
+
['BEGIN PGP ', 'PRIVATE KEY BLOCK'].join(''),
|
|
276
|
+
['PuTTY-User-', 'Key-File-2'].join(''),
|
|
277
|
+
['BEGIN OpenVPN ', 'Static key V1'].join(''),
|
|
278
|
+
]);
|
|
279
|
+
/** A text as a pattern that matches only it: the dot of a keyword is a dot, as gitleaks takes it. */
|
|
280
|
+
const escapeLiteral = (text) => text.replaceAll(/[.*+?^${}()|[\]\\]/g, String.raw `\$&`);
|
|
281
|
+
/** The markers as one test. */
|
|
282
|
+
const MARKER = new RegExp(PRIVATE_KEY_MARKERS.map(escapeLiteral).join('|'));
|
|
283
|
+
/** How many lines after a marker one may hold the key's body. A PEM key's body follows its marker, and PuTTY's after three header lines. */
|
|
284
|
+
const BODY_REACH = 6;
|
|
285
|
+
/** The fewest characters of a body run: a PEM line is 64 of them, and OpenVPN's is 32 hex digits. */
|
|
286
|
+
const BODY_RUN = 32;
|
|
287
|
+
/** The keywords of every rule as one test, in any case: a line that holds none runs no rule, as gitleaks prefilters a fragment. */
|
|
288
|
+
const KEYWORDS = new RegExp([
|
|
289
|
+
...new Set(CREDENTIAL_RULES.flatMap(rule => rule.keywords)),
|
|
290
|
+
].map(escapeLiteral).join('|'), 'i');
|
|
291
|
+
/** Each rule's pattern with the `g` flag, to read every match of a line. */
|
|
292
|
+
const SCANNERS = CREDENTIAL_RULES.map(rule => ({
|
|
293
|
+
rule,
|
|
294
|
+
all: new RegExp(rule.pattern, `${rule.pattern.flags}g`),
|
|
295
|
+
}));
|
|
296
|
+
/** The last segment of a path, lower-cased, and the directory above it. */
|
|
297
|
+
function splitName(path) {
|
|
298
|
+
const cut = path.lastIndexOf('/');
|
|
299
|
+
const above = cut > 0
|
|
300
|
+
? path.lastIndexOf('/', cut - 1)
|
|
301
|
+
: -1;
|
|
302
|
+
return {
|
|
303
|
+
name: path.slice(cut + 1).toLowerCase(),
|
|
304
|
+
parent: cut > 0
|
|
305
|
+
? path.slice(above + 1, cut)
|
|
306
|
+
: '',
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
/** Whether a name is a template that holds no value: `.env.example` and its kind, or a Helm chart's `secrets.yaml`. */
|
|
310
|
+
function isTemplate(name, parent) {
|
|
311
|
+
if (name.startsWith(SECRET_PREFIX))
|
|
312
|
+
return TEMPLATE_SUFFIXES.some(suffix => name.endsWith(suffix));
|
|
313
|
+
return parent === HELM_TEMPLATES && HELM_SECRET_TEMPLATES.includes(name);
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Whether the name of a file is a secret's: its last segment is one of `SECRET_NAMES`, starts with
|
|
317
|
+
* `SECRET_PREFIX` or ends in one of `SECRET_SUFFIXES`, in any case, and is no template (a `.env.` name
|
|
318
|
+
* that ends in one of `TEMPLATE_SUFFIXES`, or a `secrets.yaml` or `secrets.yml` in a directory named
|
|
319
|
+
* `templates`). It reads a path as the diff writes it, so an `a/` or `b/` prefix changes nothing.
|
|
320
|
+
* Generous: only the name decides, never the directory, a template apart.
|
|
321
|
+
*/
|
|
322
|
+
export function isSecretName(path) {
|
|
323
|
+
const { name, parent } = splitName(path);
|
|
324
|
+
if (isTemplate(name, parent))
|
|
325
|
+
return false;
|
|
326
|
+
return SECRET_NAMES.includes(name) || name.startsWith(SECRET_PREFIX) || SECRET_SUFFIXES.some(suffix => name.endsWith(suffix));
|
|
327
|
+
}
|
|
328
|
+
/** Whether a character code is one of the base64 alphabet: `A`-`Z`, `a`-`z`, `0`-`9`, `+`, `/` and `=`. */
|
|
329
|
+
function isBase64(code) {
|
|
330
|
+
return (code >= 48 && code <= 57) || (code >= 65 && code <= 90) || (code >= 97 && code <= 122) || code === 43 || code === 47 || code === 61;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Whether a line holds a body run from `from` on: a maximal run of at least `BODY_RUN` characters of
|
|
334
|
+
* the base64 alphabet that holds a digit and a letter. Any other character ends a run (a space, a tab,
|
|
335
|
+
* a quote, a backslash, a comma, `\r`), so an indented, a quoted and a JSON-escaped body is read, and
|
|
336
|
+
* code and prose are not: spaces and punctuation break their runs, and a long identifier has no
|
|
337
|
+
* digit. One pass, each character looked at once.
|
|
338
|
+
*/
|
|
339
|
+
function holdsBodyRun(line, from = 0) {
|
|
340
|
+
let length = 0;
|
|
341
|
+
let digit = false;
|
|
342
|
+
let letter = false;
|
|
343
|
+
for (let at = from; at < line.length; at++) {
|
|
344
|
+
const code = line.charCodeAt(at);
|
|
345
|
+
if (!isBase64(code)) {
|
|
346
|
+
length = 0;
|
|
347
|
+
digit = false;
|
|
348
|
+
letter = false;
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
length++;
|
|
352
|
+
if (code >= 48 && code <= 57)
|
|
353
|
+
digit = true;
|
|
354
|
+
else if (code >= 65)
|
|
355
|
+
letter = true; // `+`, `/` and `=` sit below `A`, so what is left up here is a letter
|
|
356
|
+
if (length >= BODY_RUN && digit && letter)
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
/** Whether a line within `BODY_REACH` lines after `at` holds a body run, reading a line at most once in a window for all the markers of a text. */
|
|
362
|
+
function holdsBodyAfter(lines, at, search) {
|
|
363
|
+
const last = Math.min(at + BODY_REACH, lines.length - 1);
|
|
364
|
+
for (let next = Math.max(search.scanned, at) + 1; next <= last; next++) {
|
|
365
|
+
if (holdsBodyRun(lines[next] ?? ''))
|
|
366
|
+
search.lastBody = next;
|
|
367
|
+
search.scanned = next;
|
|
368
|
+
}
|
|
369
|
+
return search.lastBody > at;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Whether the line at `at` holds a marker with a body run after it: on its own line, read once from the
|
|
373
|
+
* end of its first marker, or on one of the next `BODY_REACH` lines.
|
|
374
|
+
*/
|
|
375
|
+
function isPrivateKeyAt(lines, at, search) {
|
|
376
|
+
const line = lines[at] ?? '';
|
|
377
|
+
const marker = MARKER.exec(line);
|
|
378
|
+
if (marker === null)
|
|
379
|
+
return false;
|
|
380
|
+
return holdsBodyRun(line, marker.index + marker[0].length) || holdsBodyAfter(lines, at, search);
|
|
381
|
+
}
|
|
382
|
+
/** The Shannon entropy of a text in bits per character, over its code points, as gitleaks measures a secret. */
|
|
383
|
+
function entropyOf(text) {
|
|
384
|
+
const counts = new Map();
|
|
385
|
+
let length = 0;
|
|
386
|
+
for (const character of text) {
|
|
387
|
+
counts.set(character, (counts.get(character) ?? 0) + 1);
|
|
388
|
+
length++;
|
|
389
|
+
}
|
|
390
|
+
let entropy = 0;
|
|
391
|
+
for (const count of counts.values()) {
|
|
392
|
+
const share = count / length;
|
|
393
|
+
entropy -= share * Math.log2(share);
|
|
394
|
+
}
|
|
395
|
+
return entropy;
|
|
396
|
+
}
|
|
397
|
+
/** The part of a match gitleaks judges: its first non-empty capture group, else the whole match. */
|
|
398
|
+
function secretOf(match) {
|
|
399
|
+
return match.slice(1).find(group => group !== undefined && group !== '') ?? match[0];
|
|
400
|
+
}
|
|
401
|
+
/** The kind of the first match on a line that a rule keeps: every match of every rule, in the table's order. */
|
|
402
|
+
function ruleHitOn(line) {
|
|
403
|
+
if (!KEYWORDS.test(line))
|
|
404
|
+
return undefined;
|
|
405
|
+
for (const { rule, all } of SCANNERS) {
|
|
406
|
+
for (const match of line.matchAll(all)) {
|
|
407
|
+
const secret = secretOf(match);
|
|
408
|
+
if (rule.entropy !== undefined && entropyOf(secret) <= rule.entropy)
|
|
409
|
+
continue;
|
|
410
|
+
if (rule.allow?.test(secret))
|
|
411
|
+
continue;
|
|
412
|
+
return rule.kind;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
return undefined;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* The kind of the first credential a text holds, read line by line as gitleaks reads a fragment, or
|
|
419
|
+
* undefined. A line is first tested for a private-key marker, which counts only when a body run
|
|
420
|
+
* follows it, on its own line or within `BODY_REACH` lines; then, when it holds a keyword of the rules, for each rule in
|
|
421
|
+
* the table's order and every match of it on the line, a match whose secret has an entropy at or below
|
|
422
|
+
* the rule's floor, or that the rule's own allowlist matches, being no hit. It reads every row alike
|
|
423
|
+
* (added, removed, context, or none), a line of any length and a line that ends with `\r`, and it is
|
|
424
|
+
* linear in the text. Generous: a removed line and a key in a comment hold as any other.
|
|
425
|
+
*/
|
|
426
|
+
export function credentialIn(text) {
|
|
427
|
+
const lines = text.split('\n');
|
|
428
|
+
const search = { scanned: -1, lastBody: -1 };
|
|
429
|
+
for (let at = 0; at < lines.length; at++) {
|
|
430
|
+
if (isPrivateKeyAt(lines, at, search))
|
|
431
|
+
return 'private-key';
|
|
432
|
+
const kind = ruleHitOn(lines[at] ?? '');
|
|
433
|
+
if (kind !== undefined)
|
|
434
|
+
return kind;
|
|
435
|
+
}
|
|
436
|
+
return undefined;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Why a section is held back, or undefined: `name` when its header's path (a non-empty one), a name
|
|
440
|
+
* its `diff --git` line holds (each word of it, so a header that cannot be read, or that is forged as
|
|
441
|
+
* `diff --git a/.env` or `diff --git a/.env b/.env c`, still names the `.env` it spells), or a path its
|
|
442
|
+
* own lines name is a secret's, else the kind of the first credential its text holds. The name is
|
|
443
|
+
* taken before the content, so a `.env` is held by its name whatever it holds. Generous: any one path
|
|
444
|
+
* the section names, a rename's old side included, holds it.
|
|
445
|
+
*/
|
|
446
|
+
export function secretRuleOf(section) {
|
|
447
|
+
const { path, text } = section;
|
|
448
|
+
const headerNamed = path !== undefined && path !== '' && isSecretName(path);
|
|
449
|
+
return headerNamed || headerNames(text).some(isSecretName) || namedPaths(text).some(named => isSecretName(named))
|
|
450
|
+
? 'name'
|
|
451
|
+
: credentialIn(text);
|
|
452
|
+
}
|
|
453
|
+
const GIT_HEADER = 'diff --git ';
|
|
454
|
+
const DELETED_MODE = 'deleted file mode ';
|
|
455
|
+
/** What opens the line that names the old side of a file. */
|
|
456
|
+
const OLD_SIDE = '--- ';
|
|
457
|
+
/** A hunk header whose new side is empty: the lines it counts are all removed. */
|
|
458
|
+
const EMPTIED_HUNK = /^@@ -\d+(?:,\d+)? \+0,0 @@/;
|
|
459
|
+
/** Whether a line, less its `\r`, is one git writes in the diff of a file it deletes whole, after the header. */
|
|
460
|
+
function isDeletionLine(line) {
|
|
461
|
+
return line.startsWith(DELETED_MODE)
|
|
462
|
+
|| line.startsWith('index ')
|
|
463
|
+
|| line.startsWith('-')
|
|
464
|
+
|| line === '+++ /dev/null'
|
|
465
|
+
|| line === '\'
|
|
466
|
+
|| (line.startsWith('Binary files ') && line.endsWith(' and /dev/null differ'))
|
|
467
|
+
|| EMPTIED_HUNK.test(line);
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Whether a section deletes its file whole: it starts with its `diff --git` header, holds a `deleted
|
|
471
|
+
* file mode` line, and every other line of it is one git writes for a deletion: `deleted file mode`,
|
|
472
|
+
* `index`, a `-` row (the `---` line is one), `+++ /dev/null`, `Binary files <path> and /dev/null
|
|
473
|
+
* differ`, a hunk header whose new side is `+0,0`, ``, and an empty last
|
|
474
|
+
* piece, each less a trailing `\r`. Any other line (a `+` or context row, a blank line in the
|
|
475
|
+
* middle, a mail's headers in a `format-patch` series, a `GIT binary patch`) makes it no whole
|
|
476
|
+
* deletion, so a forged or mixed section is a gap and never passes as one, and a file truncated to
|
|
477
|
+
* empty, which has no `deleted file mode`, is no deletion. Its first `--- ` line, when it has one (an
|
|
478
|
+
* empty or a binary file has none), also names the old side of a header that names one path on both
|
|
479
|
+
* sides (`namesOldSide`): a `.env` header over a `--- a/src/auth.ts` line is a forged section that
|
|
480
|
+
* would hide the removal of another file, so it is no deletion and a gap. Only the first such line
|
|
481
|
+
* counts: a later one is a removed row of the file.
|
|
482
|
+
*/
|
|
483
|
+
export function isWholeDeletion(text) {
|
|
484
|
+
const [header, ...rest] = text.split('\n');
|
|
485
|
+
if (!header?.startsWith(GIT_HEADER))
|
|
486
|
+
return false;
|
|
487
|
+
let deletesFile = false;
|
|
488
|
+
let oldSideChecked = false;
|
|
489
|
+
for (const [at, raw] of rest.entries()) {
|
|
490
|
+
const line = raw.endsWith('\r')
|
|
491
|
+
? raw.slice(0, -1)
|
|
492
|
+
: raw;
|
|
493
|
+
const allowed = line === ''
|
|
494
|
+
? at === rest.length - 1
|
|
495
|
+
: isDeletionLine(line);
|
|
496
|
+
if (!allowed)
|
|
497
|
+
return false;
|
|
498
|
+
if (line.startsWith(DELETED_MODE))
|
|
499
|
+
deletesFile = true;
|
|
500
|
+
if (!oldSideChecked && line.startsWith(OLD_SIDE)) {
|
|
501
|
+
if (!namesOldSide(header, line))
|
|
502
|
+
return false;
|
|
503
|
+
oldSideChecked = true;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
return deletesFile;
|
|
507
|
+
}
|
|
@@ -6,8 +6,8 @@ import type { CompletionRequest, EventSink, Provider } from '../ports.ts';
|
|
|
6
6
|
import type { ProviderRef, StageName, Thresholds, Usage } from '../types.ts';
|
|
7
7
|
/**
|
|
8
8
|
* A provider as a compiled profile holds it: the object it calls, the ref captured at creation that
|
|
9
|
-
* events and meta report, the deadline of each of its attempts, the retries of a call and the worst case
|
|
10
|
-
* it states.
|
|
9
|
+
* events and meta report, the deadline of each of its attempts, the retries of a call, and the worst case
|
|
10
|
+
* and the room it states.
|
|
11
11
|
*/
|
|
12
12
|
export interface Target {
|
|
13
13
|
readonly provider: Provider;
|
|
@@ -18,6 +18,8 @@ export interface Target {
|
|
|
18
18
|
readonly retries: number;
|
|
19
19
|
/** The worst case of one attempt the provider stated when the quorum was created, when it is a function; `reservationOf` reads its result. */
|
|
20
20
|
readonly worstCase: ((request: CompletionRequest) => unknown) | undefined;
|
|
21
|
+
/** The room the provider stated when the quorum was created, when it is a function; `roomOf` reads its result. */
|
|
22
|
+
readonly room: ((request: CompletionRequest) => unknown) | undefined;
|
|
21
23
|
}
|
|
22
24
|
/** One lens of a compiled profile: its vote instructions, rendered once, and its own provider. */
|
|
23
25
|
export interface LensRun extends Target {
|
|
@@ -82,6 +84,8 @@ export interface RunContext {
|
|
|
82
84
|
readonly fail: (error: unknown) => void;
|
|
83
85
|
/** How many findings of a research reply each profile sends to the panel. */
|
|
84
86
|
readonly maxFindings: number;
|
|
87
|
+
/** The review's concurrency: how many parts of its research one profile has in flight at once. */
|
|
88
|
+
readonly concurrency: number;
|
|
85
89
|
/** The time and the randomness the call path reads: the system's, unless a spec injects its own. */
|
|
86
90
|
readonly clock: Clock;
|
|
87
91
|
}
|
|
@@ -133,7 +137,8 @@ export interface Requester {
|
|
|
133
137
|
* default: 600000 ms and no retry. The quorum's checks ran first, so a plain object's values are the
|
|
134
138
|
* ones they passed; a proxy that answers the check and this read differently still gets an in-range
|
|
135
139
|
* deadline and no retry, never an unbounded one. The worst case it states is its own data value when
|
|
136
|
-
* that is a function, else none: a getter is never run, and an inherited method
|
|
140
|
+
* that is a function, else none, and so is the room it states: a getter is never run, and an inherited method
|
|
141
|
+
* states nothing.
|
|
137
142
|
*/
|
|
138
143
|
export declare function targetOf(provider: Provider): Target;
|
|
139
144
|
/**
|
|
@@ -145,6 +150,14 @@ export declare function targetOf(provider: Provider): Target;
|
|
|
145
150
|
* misbehaves never reserves nothing. It never throws.
|
|
146
151
|
*/
|
|
147
152
|
export declare function reservationOf(target: Target, request: CompletionRequest): number;
|
|
153
|
+
/**
|
|
154
|
+
* The room the provider states for `request`: how many more tokens of text it could hold and still fit the
|
|
155
|
+
* provider's window, called once with the request and the provider as `this`, when it returns a safe integer,
|
|
156
|
+
* 0 and a negative one included. A provider that states none, a result that is anything else (a promise
|
|
157
|
+
* included, whose rejection is marked handled) and a throw all state nothing, which is `undefined`, and the
|
|
158
|
+
* caller then reviews as it does for a provider that states no room. It never throws.
|
|
159
|
+
*/
|
|
160
|
+
export declare function roomOf(target: Target, request: CompletionRequest): number | undefined;
|
|
148
161
|
/** Whole milliseconds since `started`, a `performance.now()` reading. */
|
|
149
162
|
export declare function elapsed(started: number): number;
|
|
150
163
|
/**
|
|
@@ -89,12 +89,14 @@ export function failureUsage(error) {
|
|
|
89
89
|
* default: 600000 ms and no retry. The quorum's checks ran first, so a plain object's values are the
|
|
90
90
|
* ones they passed; a proxy that answers the check and this read differently still gets an in-range
|
|
91
91
|
* deadline and no retry, never an unbounded one. The worst case it states is its own data value when
|
|
92
|
-
* that is a function, else none: a getter is never run, and an inherited method
|
|
92
|
+
* that is a function, else none, and so is the room it states: a getter is never run, and an inherited method
|
|
93
|
+
* states nothing.
|
|
93
94
|
*/
|
|
94
95
|
export function targetOf(provider) {
|
|
95
96
|
const timeoutMs = ownData(provider, 'timeoutMs');
|
|
96
97
|
const retries = ownData(provider, 'retries');
|
|
97
98
|
const worstCase = ownData(provider, 'worstCase');
|
|
99
|
+
const room = ownData(provider, 'room');
|
|
98
100
|
return {
|
|
99
101
|
provider,
|
|
100
102
|
ref: Object.freeze({ id: provider.id, model: provider.model }),
|
|
@@ -107,8 +109,31 @@ export function targetOf(provider) {
|
|
|
107
109
|
worstCase: typeof worstCase === 'function'
|
|
108
110
|
? worstCase
|
|
109
111
|
: undefined,
|
|
112
|
+
room: typeof room === 'function'
|
|
113
|
+
? room
|
|
114
|
+
: undefined,
|
|
110
115
|
};
|
|
111
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* The safe integer a provider's stated function returns for `request`, called once, synchronously, with the
|
|
119
|
+
* request and the provider as `this`: undefined for anything else. A result that is not a safe integer (a
|
|
120
|
+
* promise included, whose rejection is marked handled) and a throw state nothing. It never throws.
|
|
121
|
+
*/
|
|
122
|
+
function statedInteger(stating, provider, request) {
|
|
123
|
+
try {
|
|
124
|
+
const stated = Reflect.apply(stating, provider, [request]);
|
|
125
|
+
if (typeof stated === 'number' && Number.isSafeInteger(stated))
|
|
126
|
+
return stated;
|
|
127
|
+
// It is called synchronously: a promise states nothing, and a rejected one must not crash the process.
|
|
128
|
+
if ((typeof stated === 'object' && stated !== null) || typeof stated === 'function') {
|
|
129
|
+
Promise.resolve(stated).then(undefined, () => { });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
// A function that throws states nothing.
|
|
134
|
+
}
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
112
137
|
/**
|
|
113
138
|
* The tokens one attempt of `request` is reserved: the worst case the provider states, called once with the
|
|
114
139
|
* request and the provider as `this`, when it returns a safe integer of at least 1. A provider that states
|
|
@@ -118,22 +143,24 @@ export function targetOf(provider) {
|
|
|
118
143
|
* misbehaves never reserves nothing. It never throws.
|
|
119
144
|
*/
|
|
120
145
|
export function reservationOf(target, request) {
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return
|
|
146
|
+
const stated = target.worstCase === undefined
|
|
147
|
+
? undefined
|
|
148
|
+
: statedInteger(target.worstCase, target.provider, request);
|
|
149
|
+
return stated !== undefined && stated >= 1
|
|
150
|
+
? stated
|
|
151
|
+
: requestTokens(request) + TEMPLATE_TOKENS + DEFAULT_REPLY_TOKENS;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The room the provider states for `request`: how many more tokens of text it could hold and still fit the
|
|
155
|
+
* provider's window, called once with the request and the provider as `this`, when it returns a safe integer,
|
|
156
|
+
* 0 and a negative one included. A provider that states none, a result that is anything else (a promise
|
|
157
|
+
* included, whose rejection is marked handled) and a throw all state nothing, which is `undefined`, and the
|
|
158
|
+
* caller then reviews as it does for a provider that states no room. It never throws.
|
|
159
|
+
*/
|
|
160
|
+
export function roomOf(target, request) {
|
|
161
|
+
return target.room === undefined
|
|
162
|
+
? undefined
|
|
163
|
+
: statedInteger(target.room, target.provider, request);
|
|
137
164
|
}
|
|
138
165
|
/** Whole milliseconds since `started`, a `performance.now()` reading. */
|
|
139
166
|
export function elapsed(started) {
|
|
@@ -11,8 +11,14 @@ export interface PanelOutcome {
|
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* The panel stage of one profile: every finding goes to every lens, each vote to the lens's own
|
|
14
|
-
* provider, and the quorum verdict is computed in code.
|
|
15
|
-
* file its finding cites.
|
|
14
|
+
* provider, and the quorum verdict is computed in code. A vote's context is the diff section of the
|
|
15
|
+
* file its finding cites, the whole diff when the file has no section of its own. It is partial only
|
|
16
|
+
* for a voter that states a room (`Provider.room`) the section does not fit: that voter receives the
|
|
17
|
+
* section's header and the hunks nearest the cited line that fit its room, the cited hunk first (see
|
|
18
|
+
* `nearestHunks`), and its diff block says so. A voter that states no room, or whose room holds the
|
|
19
|
+
* section, receives the section as before, and so does one whose room does not hold the cited hunk
|
|
20
|
+
* alone, which its provider then refuses as too large. The context is chosen when the vote's request
|
|
21
|
+
* is built, inside the vote's slot.
|
|
16
22
|
*
|
|
17
23
|
* A voter never sees the other votes or their reasoning - independence is the point, not an
|
|
18
24
|
* oversight. Letting verifiers see each other's reasoning measurably converges results toward
|