@hoshinotatsuya/committed-secrets 0.6.3 → 0.7.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/CHANGELOG.md +12 -0
- package/README.md +3 -3
- package/README.ru.md +2 -2
- package/bin/committed-secrets.cjs +3 -3
- package/dist/scanner/auth-header-value.constant.d.ts +4 -4
- package/dist/scanner/auth-header-value.constant.js +4 -4
- package/dist/scanner/base64-credentials.d.ts +16 -16
- package/dist/scanner/base64-credentials.d.ts.map +1 -1
- package/dist/scanner/base64-credentials.js +20 -20
- package/dist/scanner/base64-credentials.js.map +1 -1
- package/dist/scanner/baseline.d.ts +7 -7
- package/dist/scanner/baseline.d.ts.map +1 -1
- package/dist/scanner/baseline.js +9 -9
- package/dist/scanner/baseline.js.map +1 -1
- package/dist/scanner/cli.js +1 -1
- package/dist/scanner/cli.js.map +1 -1
- package/dist/scanner/code-fallbacks.d.ts +13 -13
- package/dist/scanner/code-fallbacks.d.ts.map +1 -1
- package/dist/scanner/code-fallbacks.js +16 -16
- package/dist/scanner/code-fallbacks.js.map +1 -1
- package/dist/scanner/code-points.d.ts +1 -1
- package/dist/scanner/code-points.js +1 -1
- package/dist/scanner/command-rules.d.ts +21 -21
- package/dist/scanner/command-rules.d.ts.map +1 -1
- package/dist/scanner/command-rules.js +24 -24
- package/dist/scanner/command-rules.js.map +1 -1
- package/dist/scanner/config-source.d.ts +7 -7
- package/dist/scanner/config-source.d.ts.map +1 -1
- package/dist/scanner/config-source.js +9 -9
- package/dist/scanner/config-source.js.map +1 -1
- package/dist/scanner/credential-value.d.ts +3 -3
- package/dist/scanner/credential-value.js +3 -3
- package/dist/scanner/data-file-name.constant.d.ts +6 -6
- package/dist/scanner/data-file-name.constant.js +6 -6
- package/dist/scanner/documented-example-secrets.constant.d.ts +3 -3
- package/dist/scanner/documented-example-secrets.constant.js +3 -3
- package/dist/scanner/exit-code.constant.d.ts +1 -1
- package/dist/scanner/exit-code.constant.d.ts.map +1 -1
- package/dist/scanner/exit-code.constant.js +1 -1
- package/dist/scanner/exit-code.constant.js.map +1 -1
- package/dist/scanner/expression-extent.d.ts +5 -5
- package/dist/scanner/expression-extent.js +5 -5
- package/dist/scanner/file-kind.type.d.ts +5 -5
- package/dist/scanner/file-kind.type.d.ts.map +1 -1
- package/dist/scanner/file-kinds.d.ts +2 -2
- package/dist/scanner/file-kinds.d.ts.map +1 -1
- package/dist/scanner/file-kinds.js +3 -3
- package/dist/scanner/file-kinds.js.map +1 -1
- package/dist/scanner/finding.type.d.ts +7 -7
- package/dist/scanner/finding.type.d.ts.map +1 -1
- package/dist/scanner/fingerprint.d.ts +5 -5
- package/dist/scanner/fingerprint.js +5 -5
- package/dist/scanner/fixture-entry.type.d.ts +1 -1
- package/dist/scanner/fixture-entry.type.d.ts.map +1 -1
- package/dist/scanner/fixture-list.d.ts +8 -8
- package/dist/scanner/fixture-list.d.ts.map +1 -1
- package/dist/scanner/fixture-list.js +17 -17
- package/dist/scanner/fixture-list.js.map +1 -1
- package/dist/scanner/flag-rule.type.d.ts +9 -9
- package/dist/scanner/flag-rule.type.d.ts.map +1 -1
- package/dist/scanner/gate-broken.error.d.ts +1 -1
- package/dist/scanner/gate-broken.error.d.ts.map +1 -1
- package/dist/scanner/gate-broken.error.js +1 -1
- package/dist/scanner/gate-broken.error.js.map +1 -1
- package/dist/scanner/gate-config.type.d.ts +3 -3
- package/dist/scanner/gate-config.type.d.ts.map +1 -1
- package/dist/scanner/gate-files.d.ts +3 -3
- package/dist/scanner/gate-files.js +9 -9
- package/dist/scanner/gate-files.js.map +1 -1
- package/dist/scanner/gate-options.type.d.ts +5 -5
- package/dist/scanner/gate-options.type.d.ts.map +1 -1
- package/dist/scanner/gate-report.type.d.ts +2 -2
- package/dist/scanner/gate-report.type.d.ts.map +1 -1
- package/dist/scanner/git.d.ts +13 -13
- package/dist/scanner/git.d.ts.map +1 -1
- package/dist/scanner/git.js +24 -24
- package/dist/scanner/git.js.map +1 -1
- package/dist/scanner/index-entry.type.d.ts +1 -1
- package/dist/scanner/index-entry.type.d.ts.map +1 -1
- package/dist/scanner/known-token-shapes.constant.d.ts +8 -8
- package/dist/scanner/known-token-shapes.constant.d.ts.map +1 -1
- package/dist/scanner/known-token-shapes.constant.js +11 -11
- package/dist/scanner/known-token-shapes.constant.js.map +1 -1
- package/dist/scanner/line-forms.d.ts +8 -8
- package/dist/scanner/line-forms.d.ts.map +1 -1
- package/dist/scanner/line-forms.js +8 -8
- package/dist/scanner/line-forms.js.map +1 -1
- package/dist/scanner/line-sink.d.ts +5 -5
- package/dist/scanner/line-sink.d.ts.map +1 -1
- package/dist/scanner/line-sink.js +6 -6
- package/dist/scanner/line-sink.js.map +1 -1
- package/dist/scanner/load-config.d.ts +3 -3
- package/dist/scanner/load-config.js +13 -13
- package/dist/scanner/load-config.js.map +1 -1
- package/dist/scanner/markdown-code-languages.constant.d.ts +4 -4
- package/dist/scanner/markdown-code-languages.constant.js +4 -4
- package/dist/scanner/parse-gate-options.d.ts +3 -3
- package/dist/scanner/parse-gate-options.js +10 -10
- package/dist/scanner/parse-gate-options.js.map +1 -1
- package/dist/scanner/path-suffix.d.ts +1 -1
- package/dist/scanner/path-suffix.d.ts.map +1 -1
- package/dist/scanner/path-suffix.js +1 -1
- package/dist/scanner/path-suffix.js.map +1 -1
- package/dist/scanner/read-json.d.ts +1 -1
- package/dist/scanner/read-json.d.ts.map +1 -1
- package/dist/scanner/read-json.js +3 -3
- package/dist/scanner/read-json.js.map +1 -1
- package/dist/scanner/report-formats.d.ts +6 -6
- package/dist/scanner/report-formats.d.ts.map +1 -1
- package/dist/scanner/report-formats.js +7 -7
- package/dist/scanner/report-formats.js.map +1 -1
- package/dist/scanner/reported-finding.type.d.ts +2 -2
- package/dist/scanner/reported-finding.type.d.ts.map +1 -1
- package/dist/scanner/repository-files.d.ts +1 -1
- package/dist/scanner/repository-files.d.ts.map +1 -1
- package/dist/scanner/repository-source.d.ts +16 -16
- package/dist/scanner/repository-source.d.ts.map +1 -1
- package/dist/scanner/repository-source.js +23 -23
- package/dist/scanner/repository-source.js.map +1 -1
- package/dist/scanner/rule-catalog.constant.d.ts +1 -1
- package/dist/scanner/rule-catalog.constant.d.ts.map +1 -1
- package/dist/scanner/rule-catalog.constant.js +8 -8
- package/dist/scanner/rule-catalog.constant.js.map +1 -1
- package/dist/scanner/run-gate.d.ts +6 -6
- package/dist/scanner/run-gate.d.ts.map +1 -1
- package/dist/scanner/run-gate.js +29 -29
- package/dist/scanner/run-gate.js.map +1 -1
- package/dist/scanner/scan-text.d.ts +1 -1
- package/dist/scanner/scan-text.d.ts.map +1 -1
- package/dist/scanner/scan-text.js +1 -1
- package/dist/scanner/scan-text.js.map +1 -1
- package/dist/scanner/secret-key.d.ts +7 -7
- package/dist/scanner/secret-key.d.ts.map +1 -1
- package/dist/scanner/secret-key.js +7 -7
- package/dist/scanner/secret-key.js.map +1 -1
- package/dist/scanner/secret-rules.d.ts +12 -12
- package/dist/scanner/secret-rules.d.ts.map +1 -1
- package/dist/scanner/secret-rules.js +24 -24
- package/dist/scanner/secret-rules.js.map +1 -1
- package/dist/scanner/secret-value.d.ts +6 -6
- package/dist/scanner/secret-value.js +15 -15
- package/dist/scanner/secret-value.js.map +1 -1
- package/dist/scanner/shell-token.type.d.ts +1 -1
- package/dist/scanner/shell-token.type.d.ts.map +1 -1
- package/dist/scanner/shell-words.d.ts +13 -13
- package/dist/scanner/shell-words.d.ts.map +1 -1
- package/dist/scanner/shell-words.js +13 -13
- package/dist/scanner/shell-words.js.map +1 -1
- package/dist/scanner/text-of.d.ts +3 -3
- package/dist/scanner/text-of.js +5 -5
- package/dist/scanner/text-of.js.map +1 -1
- package/dist/scanner/text-scanner.d.ts +49 -49
- package/dist/scanner/text-scanner.d.ts.map +1 -1
- package/dist/scanner/text-scanner.js +80 -80
- package/dist/scanner/text-scanner.js.map +1 -1
- package/dist/scanner/value-text.d.ts +6 -6
- package/dist/scanner/value-text.js +7 -7
- package/dist/scanner/value-text.js.map +1 -1
- package/dist/scanner/volume-mode.constant.d.ts +1 -1
- package/dist/scanner/volume-mode.constant.d.ts.map +1 -1
- package/dist/scanner/volume-mode.constant.js +1 -1
- package/dist/scanner/volume-mode.constant.js.map +1 -1
- package/package.json +10 -8
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,18 @@ All notable changes to this package are documented here. The format follows
|
|
|
5
5
|
[Semantic Versioning](https://semver.org/) with the pre-1.0 rule that a breaking change or a change of
|
|
6
6
|
verdicts bumps the minor.
|
|
7
7
|
|
|
8
|
+
## [0.7.0] — 2026-11-29
|
|
9
|
+
|
|
10
|
+
> Minor version: all texts are now English, and two finding keys that users write into the fixture list and the baseline changed (see Migration).
|
|
11
|
+
|
|
12
|
+
### Changed (breaking)
|
|
13
|
+
- All messages, log lines, error texts, report texts (the text report, SARIF `rules` and GitLab `identifiers` descriptions), comments and test names are now in English, for example `REFUSED: literal secrets in committed files.` and `POSTGRES_PASSWORD: a literal of length 13`. This is breaking for anyone matching message text; exit codes, the JSON/SARIF/GitLab structure and rule identifiers are unchanged, so match those instead.
|
|
14
|
+
- Finding keys that were Russian words are English: a password in a URL is `url` (was the Russian word for "address"), a token by shape is `token <kind>`, for example `token GitHub` (was the Russian word for "token" followed by the kind). Keys of other findings (the key name, `PEM`, `PGP`, a command flag) are unchanged.
|
|
15
|
+
|
|
16
|
+
### Migration
|
|
17
|
+
- Fixture list (`fixturesPath`): replace the old keys in `keys` with `url` and `token <kind>`. An entry with an old key no longer matches its finding: the finding is reported again and the entry is stale.
|
|
18
|
+
- Baseline (`baselinePath`): the fingerprint is salted with the file and the key, so accepted findings under these two keys no longer match. Re-run `committed-secrets --write-baseline` after upgrading (and review the diff: only entries with these keys change).
|
|
19
|
+
|
|
8
20
|
## [0.6.3] — 2026-11-21
|
|
9
21
|
|
|
10
22
|
First public release as `@hoshinotatsuya/committed-secrets`, MIT; documentation in English and Russian;
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@hoshinotatsuya/committed-secrets)
|
|
4
4
|
[](https://github.com/HoshinoTatsuya/committed-secrets/actions/workflows/ci.yml)
|
|
5
5
|
|
|
6
|
-
[
|
|
6
|
+
[Russian version](README.ru.md) · [Changelog](CHANGELOG.md)
|
|
7
7
|
|
|
8
8
|
A gate that keeps **literal secrets out of committed files**. A value that reached git is in every clone
|
|
9
9
|
and every CI checkout, and editing the file does not clean the history — the secret is compromised from
|
|
@@ -137,7 +137,7 @@ gate when they were committed, and CI does the full scan. A change to the gate's
|
|
|
137
137
|
list, baseline) in the index switches to a full index scan. Run from a monorepo subdirectory, `--staged`
|
|
138
138
|
and `--history` cover that directory with paths relative to it, like `git ls-files`.
|
|
139
139
|
|
|
140
|
-
Text messages are in
|
|
140
|
+
Text messages are in English; exit codes and the JSON/SARIF/GitLab structure are stable. Finding keys are stable within a release line; 0.7.0 renamed two of them (see the [changelog](./CHANGELOG.md)).
|
|
141
141
|
|
|
142
142
|
## Fixture list
|
|
143
143
|
|
|
@@ -145,7 +145,7 @@ Text messages are in Russian; exit codes, the JSON/SARIF/GitLab structure and fi
|
|
|
145
145
|
An entry exempts `count` findings of EACH key in the file (default one): a second secret under the same key
|
|
146
146
|
is a finding again. A delivery file (`deliveryPattern`) and service code outside `testCodePatterns` are
|
|
147
147
|
never exempted; an entry that matches fewer findings than it exempts is a refusal (remove stale entries).
|
|
148
|
-
Finding keys: the key name,
|
|
148
|
+
Finding keys: the key name, `url` (a password in a URL), `PEM`, `PGP`, `token <kind>`, a command flag
|
|
149
149
|
(`redis-cli -a`, `--requirepass`).
|
|
150
150
|
|
|
151
151
|
## Baseline
|
package/README.ru.md
CHANGED
|
@@ -115,7 +115,7 @@ MR в GitLab: `--format gitlab --output gl-secret-detection-report.json` и от
|
|
|
115
115
|
|
|
116
116
|
Из подкаталога монорепозитория `--staged` и `--history` судят каталог запуска и печатают пути от него, как `git ls-files`.
|
|
117
117
|
|
|
118
|
-
Тексты сообщений — на
|
|
118
|
+
Тексты сообщений — на английском; коды выхода и структура JSON/SARIF/GitLab стабильны. Ключи находок стабильны в пределах линии выпусков; в 0.7.0 два ключа переименованы (см. [changelog](./CHANGELOG.md)).
|
|
119
119
|
|
|
120
120
|
`--staged` судит индекс мерилом ИЗ ИНДЕКСА: конфигурация, перечень фикстур и базовая линия берутся из индекса, а не с диска — запись фикстуры, добавленная на диск и не добавленная в коммит, его не освобождает. Читаются только изменённые блобы (потоком, `git cat-file --batch`); неизменённое уже прошло гейт при своём коммите, полный скан — в CI. Правка самого гейта (конфигурации, перечня, линии) в индексе включает полный скан индекса; файлы перечня фикстур читаются всегда. Порог выборки в этом режиме считается по записям индекса.
|
|
121
121
|
|
|
@@ -123,7 +123,7 @@ MR в GitLab: `--format gitlab --output gl-secret-detection-report.json` и от
|
|
|
123
123
|
|
|
124
124
|
## Перечень фикстур
|
|
125
125
|
|
|
126
|
-
`fixturesPath` — `[{ file, keys, reason, count? }]`: одноразовые пароли тестовых контейнеров и т.п. Запись освобождает `count` находок КАЖДОГО ключа в файле (по умолчанию одну): второй секрет под тем же ключом — снова находка. Файл поставки (`deliveryPattern`) и код сервиса вне `testCodePatterns` записью не освобождаются; запись, которой соответствует меньше находок, чем она освобождает, — отказ. Ключи находок: имя ключа,
|
|
126
|
+
`fixturesPath` — `[{ file, keys, reason, count? }]`: одноразовые пароли тестовых контейнеров и т.п. Запись освобождает `count` находок КАЖДОГО ключа в файле (по умолчанию одну): второй секрет под тем же ключом — снова находка. Файл поставки (`deliveryPattern`) и код сервиса вне `testCodePatterns` записью не освобождаются; запись, которой соответствует меньше находок, чем она освобождает, — отказ. Ключи находок: имя ключа, `url` (пароль в адресе), `PEM`, `PGP`, `token <вид>`, флаг команды (`redis-cli -a`, `--requirepass`).
|
|
127
127
|
|
|
128
128
|
## Базовая линия
|
|
129
129
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* `committed-secrets.json`).
|
|
6
|
-
*
|
|
4
|
+
* Runs the secrets gate. The launch directory is the project root (where
|
|
5
|
+
* `committed-secrets.json` is). Exit code: 0 clean, 1 findings, 2 the gate could
|
|
6
|
+
* not check.
|
|
7
7
|
*/
|
|
8
8
|
require('../dist/scanner/cli.js');
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* `ApiKey …`, `HMAC …`, `SSWS …`,
|
|
5
|
-
* realm=…`
|
|
2
|
+
* An authorization header value of ANY scheme: an optional scheme as a word and
|
|
3
|
+
* the credentials as one word without `=` and `,` inside (except base64 padding):
|
|
4
|
+
* `ApiKey …`, `HMAC …`, `SSWS …`, a raw token without a scheme. `Digest username="…",
|
|
5
|
+
* realm=…` is a parameter list, not one value: it does not fit.
|
|
6
6
|
*/
|
|
7
7
|
export declare const AUTH_HEADER_VALUE: RegExp;
|
|
8
8
|
//# sourceMappingURL=auth-header-value.constant.d.ts.map
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AUTH_HEADER_VALUE = void 0;
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* `ApiKey …`, `HMAC …`, `SSWS …`,
|
|
8
|
-
* realm=…`
|
|
5
|
+
* An authorization header value of ANY scheme: an optional scheme as a word and
|
|
6
|
+
* the credentials as one word without `=` and `,` inside (except base64 padding):
|
|
7
|
+
* `ApiKey …`, `HMAC …`, `SSWS …`, a raw token without a scheme. `Digest username="…",
|
|
8
|
+
* realm=…` is a parameter list, not one value: it does not fit.
|
|
9
9
|
*/
|
|
10
10
|
exports.AUTH_HEADER_VALUE = /^(?:(?<scheme>[A-Za-z][\w-]*)\s+)?(?<credential>[^\s,=]+={0,2})$/u;
|
|
11
11
|
//# sourceMappingURL=auth-header-value.constant.js.map
|
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
import type { LineSink } from './line-sink';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* `Basic
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
3
|
+
* A secret in base64: `auth` of Docker `config.json`, `*-data` of kubeconfig, the
|
|
4
|
+
* `Basic` scheme. By entropy base64 cannot be told from a hash, so the value
|
|
5
|
+
* is decoded and judged by the content: a PEM private key or
|
|
6
|
+
* "login:password" with a password that is not a placeholder. The value does not get into the report
|
|
7
|
+
* in any form, neither base64 nor decoded.
|
|
8
8
|
*/
|
|
9
9
|
export declare class Base64Credentials {
|
|
10
10
|
private static readonly BASE64;
|
|
11
|
-
/** base64
|
|
11
|
+
/** base64 of a `-----BEGIN` line: a PEM private key without a key next to it. */
|
|
12
12
|
private static readonly PEM_BASE64;
|
|
13
|
-
/**
|
|
13
|
+
/** A key whose value is base64 of credentials, not arbitrary data. */
|
|
14
14
|
static appliesTo(key: string): boolean;
|
|
15
|
-
/**
|
|
15
|
+
/** base64 content: a private key, the password from "login:password", or nothing. */
|
|
16
16
|
static decode(value: string): {
|
|
17
17
|
readonly pem: true;
|
|
18
18
|
} | {
|
|
19
19
|
readonly password: string;
|
|
20
20
|
} | null;
|
|
21
|
-
/**
|
|
21
|
+
/** The value of an `auth`/`*-data` key: a finding if there is a key or a password inside. */
|
|
22
22
|
static judgeKey(key: string, value: string, sink: LineSink, placeholders: ReadonlySet<string>): void;
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* `HMAC`, `SSWS`)
|
|
28
|
-
*
|
|
29
|
-
* `authorization` (`required`, `disabled`)
|
|
24
|
+
* An authorization header value with a scheme. `Basic` is decoded: a placeholder
|
|
25
|
+
* in the password (`user:password`) is not a finding; not "login:password" means it is judged as
|
|
26
|
+
* a literal. Other schemes: the token after the scheme. A scheme outside the list (`ApiKey`,
|
|
27
|
+
* `HMAC`, `SSWS`) and a raw token without a scheme (since 0.6.0): the credentials are judged
|
|
28
|
+
* if they look like a token (letters and digits): one word without digits under the key
|
|
29
|
+
* `authorization` (`required`, `disabled`) is a setting, not a secret.
|
|
30
30
|
*/
|
|
31
31
|
static judgeAuthorization(key: string, value: string, sink: LineSink, placeholders: ReadonlySet<string>): void;
|
|
32
|
-
/** `LS0tLS1CRUdJTi…`
|
|
32
|
+
/** `LS0tLS1CRUdJTi…` anywhere: base64 of a PEM private key. */
|
|
33
33
|
static pemShapes(line: string, sink: LineSink): void;
|
|
34
34
|
private static reportPair;
|
|
35
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64-credentials.d.ts","sourceRoot":"","sources":["../../src/scanner/base64-credentials.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAI5C;;;;;;GAMG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAkC;IAEhE,
|
|
1
|
+
{"version":3,"file":"base64-credentials.d.ts","sourceRoot":"","sources":["../../src/scanner/base64-credentials.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAI5C;;;;;;GAMG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAkC;IAEhE,iFAAiF;IACjF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAgD;IAElF,sEAAsE;WACxD,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAI7C,qFAAqF;WACvE,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG;QAAE,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAA;KAAE,GAAG;QAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IAgBlG,6FAA6F;WAC/E,QAAQ,CACpB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,QAAQ,EACd,YAAY,EAAE,WAAW,CAAC,MAAM,CAAC,GAChC,IAAI;IAYP;;;;;;;OAOG;WACW,kBAAkB,CAC9B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,QAAQ,EACd,YAAY,EAAE,WAAW,CAAC,MAAM,CAAC,GAChC,IAAI;IAgCP,+DAA+D;WACjD,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,IAAI;IAY3D,OAAO,CAAC,MAAM,CAAC,UAAU;CAQ1B"}
|
|
@@ -8,21 +8,21 @@ const known_token_shapes_constant_1 = require("./known-token-shapes.constant");
|
|
|
8
8
|
const secret_rules_1 = require("./secret-rules");
|
|
9
9
|
const secret_value_1 = require("./secret-value");
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
* `Basic
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
11
|
+
* A secret in base64: `auth` of Docker `config.json`, `*-data` of kubeconfig, the
|
|
12
|
+
* `Basic` scheme. By entropy base64 cannot be told from a hash, so the value
|
|
13
|
+
* is decoded and judged by the content: a PEM private key or
|
|
14
|
+
* "login:password" with a password that is not a placeholder. The value does not get into the report
|
|
15
|
+
* in any form, neither base64 nor decoded.
|
|
16
16
|
*/
|
|
17
17
|
class Base64Credentials {
|
|
18
18
|
static BASE64 = /^[A-Za-z0-9+/_-]{8,}={0,2}$/u;
|
|
19
|
-
/** base64
|
|
19
|
+
/** base64 of a `-----BEGIN` line: a PEM private key without a key next to it. */
|
|
20
20
|
static PEM_BASE64 = /\bLS0tLS1CRUdJTi[A-Za-z0-9+/]{16,}={0,2}/gu;
|
|
21
|
-
/**
|
|
21
|
+
/** A key whose value is base64 of credentials, not arbitrary data. */
|
|
22
22
|
static appliesTo(key) {
|
|
23
23
|
return key.toLowerCase() === 'auth' || /[-_]data$/iu.test(key) || /[a-z]Data$/u.test(key);
|
|
24
24
|
}
|
|
25
|
-
/**
|
|
25
|
+
/** base64 content: a private key, the password from "login:password", or nothing. */
|
|
26
26
|
static decode(value) {
|
|
27
27
|
if (!Base64Credentials.BASE64.test(value)) {
|
|
28
28
|
return null;
|
|
@@ -31,33 +31,33 @@ class Base64Credentials {
|
|
|
31
31
|
if (secret_rules_1.PEM_PRIVATE.test(text)) {
|
|
32
32
|
return { pem: true };
|
|
33
33
|
}
|
|
34
|
-
// biome-ignore lint/suspicious/noControlCharactersInRegex:
|
|
34
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: control characters are a sign of binary data, not text
|
|
35
35
|
if (text.includes('�') || /[\x00-\x08\x0e-\x1f]/u.test(text)) {
|
|
36
36
|
return null;
|
|
37
37
|
}
|
|
38
38
|
const pair = /^([^:\s]{1,256}):(\S+)$/su.exec(text);
|
|
39
39
|
return pair === null ? null : { password: pair[2] };
|
|
40
40
|
}
|
|
41
|
-
/**
|
|
41
|
+
/** The value of an `auth`/`*-data` key: a finding if there is a key or a password inside. */
|
|
42
42
|
static judgeKey(key, value, sink, placeholders) {
|
|
43
43
|
const decoded = Base64Credentials.decode(value);
|
|
44
44
|
if (decoded === null) {
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
47
|
if ('pem' in decoded) {
|
|
48
|
-
sink.add(key, 'base64-private-key', `${key}
|
|
48
|
+
sink.add(key, 'base64-private-key', `${key}: a PEM private key in base64`, value);
|
|
49
49
|
}
|
|
50
50
|
else if ((0, credential_value_1.isCredential)(decoded.password, placeholders)) {
|
|
51
51
|
Base64Credentials.reportPair(key, value, decoded.password, sink);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* `HMAC`, `SSWS`)
|
|
59
|
-
*
|
|
60
|
-
* `authorization` (`required`, `disabled`)
|
|
55
|
+
* An authorization header value with a scheme. `Basic` is decoded: a placeholder
|
|
56
|
+
* in the password (`user:password`) is not a finding; not "login:password" means it is judged as
|
|
57
|
+
* a literal. Other schemes: the token after the scheme. A scheme outside the list (`ApiKey`,
|
|
58
|
+
* `HMAC`, `SSWS`) and a raw token without a scheme (since 0.6.0): the credentials are judged
|
|
59
|
+
* if they look like a token (letters and digits): one word without digits under the key
|
|
60
|
+
* `authorization` (`required`, `disabled`) is a setting, not a secret.
|
|
61
61
|
*/
|
|
62
62
|
static judgeAuthorization(key, value, sink, placeholders) {
|
|
63
63
|
const scheme = known_token_shapes_constant_1.AUTH_SCHEME_VALUE.exec(value);
|
|
@@ -88,7 +88,7 @@ class Base64Credentials {
|
|
|
88
88
|
sink.literal(key, 'key-literal', credential);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
-
/** `LS0tLS1CRUdJTi…`
|
|
91
|
+
/** `LS0tLS1CRUdJTi…` anywhere: base64 of a PEM private key. */
|
|
92
92
|
static pemShapes(line, sink) {
|
|
93
93
|
if (!line.includes('LS0tLS1CRUdJTi')) {
|
|
94
94
|
return;
|
|
@@ -96,12 +96,12 @@ class Base64Credentials {
|
|
|
96
96
|
for (const match of line.matchAll(Base64Credentials.PEM_BASE64)) {
|
|
97
97
|
const decoded = Base64Credentials.decode(match[0]);
|
|
98
98
|
if (decoded !== null && 'pem' in decoded) {
|
|
99
|
-
sink.add('PEM', 'base64-private-key', '
|
|
99
|
+
sink.add('PEM', 'base64-private-key', 'a PEM private key in base64', match[0]);
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
static reportPair(key, encoded, password, sink) {
|
|
104
|
-
sink.add(key, 'base64-credentials', `${key}
|
|
104
|
+
sink.add(key, 'base64-credentials', `${key}: base64 "login:password", a password of length ${(0, code_points_1.codePoints)(password)}`, encoded);
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
exports.Base64Credentials = Base64Credentials;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64-credentials.js","sourceRoot":"","sources":["../../src/scanner/base64-credentials.ts"],"names":[],"mappings":";;;AAAA,6EAAiE;AACjE,+CAA2C;AAC3C,yDAAkD;AAClD,+EAAkE;AAElE,iDAA6C;AAC7C,iDAA+D;AAE/D;;;;;;GAMG;AACH,MAAa,iBAAiB;IACpB,MAAM,CAAU,MAAM,GAAG,8BAA8B,CAAC;IAEhE,
|
|
1
|
+
{"version":3,"file":"base64-credentials.js","sourceRoot":"","sources":["../../src/scanner/base64-credentials.ts"],"names":[],"mappings":";;;AAAA,6EAAiE;AACjE,+CAA2C;AAC3C,yDAAkD;AAClD,+EAAkE;AAElE,iDAA6C;AAC7C,iDAA+D;AAE/D;;;;;;GAMG;AACH,MAAa,iBAAiB;IACpB,MAAM,CAAU,MAAM,GAAG,8BAA8B,CAAC;IAEhE,iFAAiF;IACzE,MAAM,CAAU,UAAU,GAAG,4CAA4C,CAAC;IAElF,sEAAsE;IAC/D,MAAM,CAAC,SAAS,CAAC,GAAW;QACjC,OAAO,GAAG,CAAC,WAAW,EAAE,KAAK,MAAM,IAAI,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC5F,CAAC;IAED,qFAAqF;IAC9E,MAAM,CAAC,MAAM,CAAC,KAAa;QAChC,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1C,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC3D,IAAI,0BAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;QACvB,CAAC;QACD,kHAAkH;QAClH,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,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iBAAiB,CAAC,UAAU,CAAC,EAAE,CAAC;YAChE,MAAM,OAAO,GAAG,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACnD,IAAI,OAAO,KAAK,IAAI,IAAI,KAAK,IAAI,OAAO,EAAE,CAAC;gBACzC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,oBAAoB,EAAE,6BAA6B,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACjF,CAAC;QACH,CAAC;IACH,CAAC;IAEO,MAAM,CAAC,UAAU,CAAC,GAAW,EAAE,OAAe,EAAE,QAAgB,EAAE,IAAc;QACtF,IAAI,CAAC,GAAG,CACN,GAAG,EACH,oBAAoB,EACpB,GAAG,GAAG,mDAAmD,IAAA,wBAAU,EAAC,QAAQ,CAAC,EAAE,EAC/E,OAAO,CACR,CAAC;IACJ,CAAC;;AA/GH,8CAgHC"}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import type { ConfigSource } from './config-source';
|
|
2
2
|
import type { ReportedFinding } from './reported-finding.type';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* The baseline is accepted findings as FINGERPRINTS (file, key, fingerprint of the
|
|
5
|
+
* value): the gate is enabled in a repository with history and fails only on
|
|
6
|
+
* NEW findings. There are no values in the file. An entry without a finding is not a refusal (the baseline
|
|
7
|
+
* exists to shrink), but it is mentioned.
|
|
8
8
|
*/
|
|
9
9
|
export declare class Baseline {
|
|
10
10
|
static readonly VERSION = 1;
|
|
11
|
-
/**
|
|
11
|
+
/** The entry key: file, finding key, fingerprint. */
|
|
12
12
|
static keyOf(file: string, key: string, fingerprint: string): string;
|
|
13
|
-
/**
|
|
13
|
+
/** Baseline entries with a count (identical values under one key are several entries). */
|
|
14
14
|
static load(source: ConfigSource, path: string): Map<string, number>;
|
|
15
|
-
/**
|
|
15
|
+
/** The baseline file text: entries are sorted, so a diff of a baseline edit is readable. */
|
|
16
16
|
static serialize(findings: readonly ReportedFinding[]): string;
|
|
17
17
|
}
|
|
18
18
|
//# sourceMappingURL=baseline.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseline.d.ts","sourceRoot":"","sources":["../../src/scanner/baseline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE/D;;;;;GAKG;AACH,qBAAa,QAAQ;IACnB,gBAAuB,OAAO,KAAK;IAEnC,
|
|
1
|
+
{"version":3,"file":"baseline.d.ts","sourceRoot":"","sources":["../../src/scanner/baseline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE/D;;;;;GAKG;AACH,qBAAa,QAAQ;IACnB,gBAAuB,OAAO,KAAK;IAEnC,qDAAqD;WACvC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM;IAI3E,0FAA0F;WAC5E,IAAI,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IA8B3E,4FAA4F;WAC9E,SAAS,CAAC,QAAQ,EAAE,SAAS,eAAe,EAAE,GAAG,MAAM;CAQtE"}
|
package/dist/scanner/baseline.js
CHANGED
|
@@ -4,18 +4,18 @@ exports.Baseline = void 0;
|
|
|
4
4
|
const gate_broken_error_1 = require("./gate-broken.error");
|
|
5
5
|
const read_json_1 = require("./read-json");
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* The baseline is accepted findings as FINGERPRINTS (file, key, fingerprint of the
|
|
8
|
+
* value): the gate is enabled in a repository with history and fails only on
|
|
9
|
+
* NEW findings. There are no values in the file. An entry without a finding is not a refusal (the baseline
|
|
10
|
+
* exists to shrink), but it is mentioned.
|
|
11
11
|
*/
|
|
12
12
|
class Baseline {
|
|
13
13
|
static VERSION = 1;
|
|
14
|
-
/**
|
|
14
|
+
/** The entry key: file, finding key, fingerprint. */
|
|
15
15
|
static keyOf(file, key, fingerprint) {
|
|
16
16
|
return `${file}\0${key}\0${fingerprint}`;
|
|
17
17
|
}
|
|
18
|
-
/**
|
|
18
|
+
/** Baseline entries with a count (identical values under one key are several entries). */
|
|
19
19
|
static load(source, path) {
|
|
20
20
|
const document = (0, read_json_1.readJson)(source, path);
|
|
21
21
|
const findings = document?.findings;
|
|
@@ -23,7 +23,7 @@ class Baseline {
|
|
|
23
23
|
document === null ||
|
|
24
24
|
document.version !== Baseline.VERSION ||
|
|
25
25
|
!Array.isArray(findings)) {
|
|
26
|
-
throw new gate_broken_error_1.GateBrokenError(`${path}:
|
|
26
|
+
throw new gate_broken_error_1.GateBrokenError(`${path}: expected a baseline { "version": ${Baseline.VERSION}, "findings": [...] }`);
|
|
27
27
|
}
|
|
28
28
|
const entries = new Map();
|
|
29
29
|
findings.forEach((entry, index) => {
|
|
@@ -32,14 +32,14 @@ class Baseline {
|
|
|
32
32
|
typeof record.key !== 'string' ||
|
|
33
33
|
typeof record.fingerprint !== 'string' ||
|
|
34
34
|
!/^[0-9a-f]{32}$/u.test(record.fingerprint)) {
|
|
35
|
-
throw new gate_broken_error_1.GateBrokenError(`${path}:
|
|
35
|
+
throw new gate_broken_error_1.GateBrokenError(`${path}: entry #${index} is not { file, key, fingerprint }`);
|
|
36
36
|
}
|
|
37
37
|
const key = Baseline.keyOf(record.file, record.key, record.fingerprint);
|
|
38
38
|
entries.set(key, (entries.get(key) ?? 0) + 1);
|
|
39
39
|
});
|
|
40
40
|
return entries;
|
|
41
41
|
}
|
|
42
|
-
/**
|
|
42
|
+
/** The baseline file text: entries are sorted, so a diff of a baseline edit is readable. */
|
|
43
43
|
static serialize(findings) {
|
|
44
44
|
const entries = findings
|
|
45
45
|
.map(({ file, key, fingerprint }) => ({ file, key, fingerprint }))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseline.js","sourceRoot":"","sources":["../../src/scanner/baseline.ts"],"names":[],"mappings":";;;AACA,2DAAsD;AACtD,2CAAuC;AAGvC;;;;;GAKG;AACH,MAAa,QAAQ;IACZ,MAAM,CAAU,OAAO,GAAG,CAAC,CAAC;IAEnC,
|
|
1
|
+
{"version":3,"file":"baseline.js","sourceRoot":"","sources":["../../src/scanner/baseline.ts"],"names":[],"mappings":";;;AACA,2DAAsD;AACtD,2CAAuC;AAGvC;;;;;GAKG;AACH,MAAa,QAAQ;IACZ,MAAM,CAAU,OAAO,GAAG,CAAC,CAAC;IAEnC,qDAAqD;IAC9C,MAAM,CAAC,KAAK,CAAC,IAAY,EAAE,GAAW,EAAE,WAAmB;QAChE,OAAO,GAAG,IAAI,KAAK,GAAG,KAAK,WAAW,EAAE,CAAC;IAC3C,CAAC;IAED,0FAA0F;IACnF,MAAM,CAAC,IAAI,CAAC,MAAoB,EAAE,IAAY;QACnD,MAAM,QAAQ,GAAG,IAAA,oBAAQ,EAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACxC,MAAM,QAAQ,GAAI,QAA6D,EAAE,QAAQ,CAAC;QAC1F,IACE,OAAO,QAAQ,KAAK,QAAQ;YAC5B,QAAQ,KAAK,IAAI;YAChB,QAAkC,CAAC,OAAO,KAAK,QAAQ,CAAC,OAAO;YAChE,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EACxB,CAAC;YACD,MAAM,IAAI,mCAAe,CACvB,GAAG,IAAI,sCAAsC,QAAQ,CAAC,OAAO,uBAAuB,CACrF,CAAC;QACJ,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;QAC1C,QAA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AC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;aACpE,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;QAC7B,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;IAC1F,CAAC;;AA/CH,4BAgDC"}
|
package/dist/scanner/cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const run_gate_1 = require("./run-gate");
|
|
5
|
-
//
|
|
5
|
+
// The launch directory is the project root (where committed-secrets.json is).
|
|
6
6
|
void (0, run_gate_1.runGate)(process.argv.slice(2), process.cwd(), {
|
|
7
7
|
out: (line) => process.stdout.write(`${line}\n`),
|
|
8
8
|
err: (line) => process.stderr.write(`${line}\n`),
|
package/dist/scanner/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/scanner/cli.ts"],"names":[],"mappings":";;;AACA,yCAAqC;AAErC,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/scanner/cli.ts"],"names":[],"mappings":";;;AACA,yCAAqC;AAErC,8EAA8E;AAC9E,KAAK,IAAA,kBAAO,EAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE;IACjD,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC;IAChD,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC;CACjD,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;IACf,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;AAC1B,CAAC,CAAC,CAAC"}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import type { LineSink } from './line-sink';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* `config.get('KEY', '
|
|
6
|
-
*
|
|
3
|
+
* A default literal in code: the value under a secret key is an expression, but
|
|
4
|
+
* it has a literal for the "not set" case (`process.env.X ?? 'literal'`,
|
|
5
|
+
* `config.get('KEY', 'literal')`, `.default('literal')`, `Buffer.from('…')`).
|
|
6
|
+
* Such a literal goes to production as soon as somebody forgets to set the variable.
|
|
7
7
|
*/
|
|
8
8
|
export declare class CodeFallbacks {
|
|
9
|
-
/**
|
|
9
|
+
/** A backtick: in `u` mode it cannot be escaped in a regex. */
|
|
10
10
|
private static readonly BT;
|
|
11
11
|
private static readonly QUOTED;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
13
|
+
* The key, the operator and the expression up to the end of the statement. The expression is in a LOOKAHEAD:
|
|
14
|
+
* previously the match consumed the line to the end, and a key to the right of the first
|
|
15
|
+
* assignment (`const c = { apiKey: … }`) was not considered at all. The value
|
|
16
|
+
* boundary is `expressionExtent`.
|
|
17
17
|
*/
|
|
18
18
|
private static readonly ASSIGNMENT;
|
|
19
19
|
private static readonly GETTER;
|
|
20
|
-
/**
|
|
20
|
+
/** Default literal forms in an expression under a secret key. */
|
|
21
21
|
private static readonly FORMS;
|
|
22
|
-
/**
|
|
22
|
+
/** An environment variable with a secret name and a default literal, under any key. */
|
|
23
23
|
private static readonly ENV_DEFAULT;
|
|
24
|
-
/**
|
|
24
|
+
/** Reading a setting with a secret name and a default literal: `get('DB_PASSWORD', '…')`. */
|
|
25
25
|
private static readonly NAMED_GETTER;
|
|
26
|
-
/**
|
|
26
|
+
/** A cheap cutoff: without these substrings there are no forms in the line. */
|
|
27
27
|
private static readonly HINT;
|
|
28
28
|
static scan(line: string, sink: LineSink, placeholders: ReadonlySet<string>): void;
|
|
29
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-fallbacks.d.ts","sourceRoot":"","sources":["../../src/scanner/code-fallbacks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAI5C;;;;;GAKG;AACH,qBAAa,aAAa;IACxB
|
|
1
|
+
{"version":3,"file":"code-fallbacks.d.ts","sourceRoot":"","sources":["../../src/scanner/code-fallbacks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAI5C;;;;;GAKG;AACH,qBAAa,aAAa;IACxB,+DAA+D;IAC/D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAO;IAEjC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CACsE;IAEpG;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAGhC;IAEF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAC0F;IAExH,iEAAiE;IACjE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAc3B;IAEF,uFAAuF;IACvF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAGjC;IAEF,6FAA6F;IAC7F,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAGlC;IAEF,+EAA+E;IAC/E,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CACsE;WAEpF,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,IAAI;CA2C1F"}
|
|
@@ -5,51 +5,51 @@ const expression_extent_1 = require("./expression-extent");
|
|
|
5
5
|
const secret_key_1 = require("./secret-key");
|
|
6
6
|
const secret_value_1 = require("./secret-value");
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* `config.get('KEY', '
|
|
11
|
-
*
|
|
8
|
+
* A default literal in code: the value under a secret key is an expression, but
|
|
9
|
+
* it has a literal for the "not set" case (`process.env.X ?? 'literal'`,
|
|
10
|
+
* `config.get('KEY', 'literal')`, `.default('literal')`, `Buffer.from('…')`).
|
|
11
|
+
* Such a literal goes to production as soon as somebody forgets to set the variable.
|
|
12
12
|
*/
|
|
13
13
|
class CodeFallbacks {
|
|
14
|
-
/**
|
|
14
|
+
/** A backtick: in `u` mode it cannot be escaped in a regex. */
|
|
15
15
|
static BT = '`';
|
|
16
16
|
static QUOTED = String.raw `("[^"\n]*"|'[^'\n]*'|${CodeFallbacks.BT}[^${CodeFallbacks.BT}\n]*${CodeFallbacks.BT})`;
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
18
|
+
* The key, the operator and the expression up to the end of the statement. The expression is in a LOOKAHEAD:
|
|
19
|
+
* previously the match consumed the line to the end, and a key to the right of the first
|
|
20
|
+
* assignment (`const c = { apiKey: … }`) was not considered at all. The value
|
|
21
|
+
* boundary is `expressionExtent`.
|
|
22
22
|
*/
|
|
23
23
|
static ASSIGNMENT = new RegExp(String.raw `(?<kq>["'${CodeFallbacks.BT}]?)(?<![\p{L}\p{N}\p{M}_$.-])(?<key>[A-Za-z_][A-Za-z0-9_]*)\k<kq>\s*(?::\s*[A-Za-z_][\w.<>\[\]|, ]*?\s*=|:=|=>|:|=)(?!=)\s*(?=(?<expr>[^;\n]*))`, 'gu');
|
|
24
24
|
static GETTER = String.raw `\b(?:get|getenv|getEnv|get_env|getOrDefault|getString|getValue|fetch|env|config)\s*(?:<[^<>()\n]*>)?\s*\(`;
|
|
25
|
-
/**
|
|
25
|
+
/** Default literal forms in an expression under a secret key. */
|
|
26
26
|
static FORMS = [
|
|
27
27
|
new RegExp(String.raw `(?:\?\?|\|\||\bor\b|\?:)\s*${CodeFallbacks.QUOTED}`, 'gu'),
|
|
28
28
|
new RegExp(String.raw `\.(?:default|defaultValue|withDefault|unwrap_or|unwrapOr|getOrElse|orElse|getOrDefault)\s*\(\s*${CodeFallbacks.QUOTED}`, 'gu'),
|
|
29
29
|
new RegExp(String.raw `${CodeFallbacks.GETTER}\s*${CodeFallbacks.QUOTED}\s*,\s*${CodeFallbacks.QUOTED}`, 'gu'),
|
|
30
30
|
new RegExp(String.raw `\b(?:Buffer\.from|bytes\.fromhex|bytes\.fromHex|hex\.DecodeString|atob|b64decode|decode64)\s*\(\s*${CodeFallbacks.QUOTED}`, 'gu'),
|
|
31
31
|
];
|
|
32
|
-
/**
|
|
32
|
+
/** An environment variable with a secret name and a default literal, under any key. */
|
|
33
33
|
static ENV_DEFAULT = new RegExp(String.raw `(?:process\.env|import\.meta\.env|Deno\.env|os\.environ|\bENV|\benv)(?:\.([A-Za-z_]\w*)|\[\s*["']([^"'\n]+)["']\s*\])\s*(?:\?\?|\|\||\bor\b)\s*${CodeFallbacks.QUOTED}`, 'gu');
|
|
34
|
-
/**
|
|
34
|
+
/** Reading a setting with a secret name and a default literal: `get('DB_PASSWORD', '…')`. */
|
|
35
35
|
static NAMED_GETTER = new RegExp(String.raw `${CodeFallbacks.GETTER}\s*${CodeFallbacks.QUOTED}\s*,\s*${CodeFallbacks.QUOTED}`, 'gu');
|
|
36
|
-
/**
|
|
36
|
+
/** A cheap cutoff: without these substrings there are no forms in the line. */
|
|
37
37
|
static HINT = /\?\?|\|\||\bor\b|\?:|default|get|env|fetch|config|unwrap|orElse|Buffer|bytes|hex|atob|decode/u;
|
|
38
38
|
static scan(line, sink, placeholders) {
|
|
39
39
|
if (!CodeFallbacks.HINT.test(line)) {
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
42
|
const report = (key, quoted) => {
|
|
43
|
-
//
|
|
43
|
+
// A substitution inside a template (`'${…}'`) is an expression, not a literal: the same parts as for a key.
|
|
44
44
|
for (const value of (0, secret_value_1.literalParts)((quoted ?? '').slice(1, -1))) {
|
|
45
45
|
if ((0, secret_value_1.isLiteralSecret)(value, placeholders)) {
|
|
46
|
-
sink.add(key, 'fallback-literal', `${key}
|
|
46
|
+
sink.add(key, 'fallback-literal', `${key}: a default literal of length ${[...value].length}`, value);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
50
|
for (const match of line.matchAll(CodeFallbacks.ASSIGNMENT)) {
|
|
51
51
|
const key = match.groups?.key ?? '';
|
|
52
|
-
//
|
|
52
|
+
// A ternary operator (`flag ? 'token' : 'modifier'`) is not a key–value pair.
|
|
53
53
|
if (!(0, secret_key_1.isSecretKey)(key) || line.slice(0, match.index).trimEnd().endsWith('?')) {
|
|
54
54
|
continue;
|
|
55
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-fallbacks.js","sourceRoot":"","sources":["../../src/scanner/code-fallbacks.ts"],"names":[],"mappings":";;;AAAA,2DAAuD;AAEvD,6CAA2C;AAC3C,iDAA+D;AAE/D;;;;;GAKG;AACH,MAAa,aAAa;IACxB
|
|
1
|
+
{"version":3,"file":"code-fallbacks.js","sourceRoot":"","sources":["../../src/scanner/code-fallbacks.ts"],"names":[],"mappings":";;;AAAA,2DAAuD;AAEvD,6CAA2C;AAC3C,iDAA+D;AAE/D;;;;;GAKG;AACH,MAAa,aAAa;IACxB,+DAA+D;IACvD,MAAM,CAAU,EAAE,GAAG,GAAG,CAAC;IAEzB,MAAM,CAAU,MAAM,GAC5B,MAAM,CAAC,GAAG,CAAA,wBAAwB,aAAa,CAAC,EAAE,KAAK,aAAa,CAAC,EAAE,OAAO,aAAa,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CAAC;gBAC5B,CAAC;YACH,CAAC;QACH,CAAC;QACD,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC;YAC7D,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YACxC,IAAI,IAAA,wBAAW,EAAC,IAAI,CAAC,EAAE,CAAC;gBACtB,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;QACD,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;YAC9D,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YAC3C,IAAI,IAAA,wBAAW,EAAC,IAAI,CAAC,EAAE,CAAC;gBACtB,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;IACH,CAAC;;AAhGH,sCAiGC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** The number of characters as Python counts it (`len`): code points, not UTF-16 units. */
|
|
2
2
|
export declare const codePoints: (text: string) => number;
|
|
3
3
|
//# sourceMappingURL=code-points.d.ts.map
|