flare-redact 1.10.4 → 1.12.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 +144 -3
- package/README.md +40 -3
- package/SECURITY.md +1 -1
- package/dist/audit.d.ts +82 -0
- package/dist/audit.d.ts.map +1 -0
- package/dist/audit.js +146 -0
- package/dist/audit.js.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +20 -3
- package/dist/cli.js.map +1 -1
- package/dist/db.d.ts +67 -0
- package/dist/db.d.ts.map +1 -0
- package/dist/db.js +402 -0
- package/dist/db.js.map +1 -0
- package/dist/detectors.d.ts +1 -2
- package/dist/detectors.d.ts.map +1 -1
- package/dist/detectors.js +8 -4
- package/dist/detectors.js.map +1 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +24 -6
- package/dist/engine.js.map +1 -1
- package/dist/extra.d.ts.map +1 -1
- package/dist/extra.js +3 -1
- package/dist/extra.js.map +1 -1
- package/dist/fold.d.ts +22 -0
- package/dist/fold.d.ts.map +1 -0
- package/dist/fold.js +140 -0
- package/dist/fold.js.map +1 -0
- package/dist/help.d.ts +1 -1
- package/dist/help.d.ts.map +1 -1
- package/dist/help.js +15 -9
- package/dist/help.js.map +1 -1
- package/dist/i18n.d.ts +10 -0
- package/dist/i18n.d.ts.map +1 -1
- package/dist/i18n.js +18 -1
- package/dist/i18n.js.map +1 -1
- package/dist/pack.d.ts +2 -2
- package/dist/pack.d.ts.map +1 -1
- package/dist/pack.js +9 -7
- package/dist/pack.js.map +1 -1
- package/dist/recording.d.ts +82 -0
- package/dist/recording.d.ts.map +1 -0
- package/dist/recording.js +195 -0
- package/dist/recording.js.map +1 -0
- package/dist/register.d.ts +22 -4
- package/dist/register.d.ts.map +1 -1
- package/dist/register.js +51 -4
- package/dist/register.js.map +1 -1
- package/dist/replay.d.ts +54 -0
- package/dist/replay.d.ts.map +1 -0
- package/dist/replay.js +87 -0
- package/dist/replay.js.map +1 -0
- package/dist/snapshot.d.ts +25 -0
- package/dist/snapshot.d.ts.map +1 -0
- package/dist/snapshot.js +49 -0
- package/dist/snapshot.js.map +1 -0
- package/dist/terms.d.ts +4 -4
- package/dist/terms.d.ts.map +1 -1
- package/dist/terms.js +22 -13
- package/dist/terms.js.map +1 -1
- package/docs/guide.md +318 -16
- package/package.json +21 -1
- package/spec/SPEC.md +142 -51
- package/spec/conformance/README.md +7 -4
- package/spec/conformance/cases.json +22 -0
- package/spec/conformance/expected.json +378 -0
- package/spec/detectors.json +4 -4
- package/spec/detectors.schema.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,149 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.12.0 (2026-11-25)
|
|
4
|
+
|
|
5
|
+
### Added: Java and .NET engines
|
|
6
|
+
|
|
7
|
+
- `sdk/java`: a Java 11+ engine with no dependencies, published to Maven
|
|
8
|
+
Central as `io.github.flare-collection:flare-redact`. Kotlin, Scala and
|
|
9
|
+
other JVM languages use the same jar.
|
|
10
|
+
- `flare-redact-logback` adds a `%redact(...)` pattern converter and an
|
|
11
|
+
encoder that wraps any other encoder, JSON ones included.
|
|
12
|
+
`flare-redact-log4j2` adds a `%redact{...}` pattern converter and a
|
|
13
|
+
`<FlareRedact/>` rewrite policy that redacts messages (a `MapMessage` field
|
|
14
|
+
by field) and context data before any appender sees the event.
|
|
15
|
+
- `sdk/dotnet`: an engine for `netstandard2.0` and `net8.0` with no
|
|
16
|
+
dependencies, published to NuGet as `FlareRedact`. On .NET 8 the detector
|
|
17
|
+
patterns compile to IL, and `JsonNode` and `JsonElement` come back as the
|
|
18
|
+
same kind.
|
|
19
|
+
- `FlareRedact.Extensions.Logging` adds `AddFlareRedact()`, which wraps every
|
|
20
|
+
logger provider so each one receives the redacted message, redacted
|
|
21
|
+
structured values, the template with its literal text redacted, redacted
|
|
22
|
+
scopes and a redacted exception. `FlareRedact.Serilog` adds a wrapping sink
|
|
23
|
+
and an enricher.
|
|
24
|
+
- Both engines run the whole conformance corpus, read the same JSON options
|
|
25
|
+
and packs as the other engines, and cover policies, vaults with streaming
|
|
26
|
+
restore (JSON-aware for tool-call arguments), all five replacement modes,
|
|
27
|
+
terms and custom packs. Case-insensitive matching uses a bundled Unicode 17
|
|
28
|
+
case table, so results do not change with the JVM or .NET version. Logging
|
|
29
|
+
never throws because of redaction: text over a limit is written as a fixed
|
|
30
|
+
notice, never as the original.
|
|
31
|
+
- CI tests Java 11, 17 and 21 and .NET 8 and 10 (plus the `netstandard2.0`
|
|
32
|
+
build), and publishes to Maven Central and NuGet when the version changes.
|
|
33
|
+
|
|
34
|
+
### Fixed: the engines agree in more places
|
|
35
|
+
|
|
36
|
+
From a full audit of all the engines. Each item has a conformance case or a
|
|
37
|
+
test.
|
|
38
|
+
|
|
39
|
+
- Keywords match under Unicode case folding with i, I, İ and ı as one letter,
|
|
40
|
+
so `ŞİFRE:`, `MƏXFİ=`, `şıfre:` and identifiers upper-cased under a Turkish
|
|
41
|
+
locale (`APİ_KEY=`) are caught, and so are `PAſſWORD=`, the Kelvin sign and
|
|
42
|
+
Greek final sigma (`ΚΩΔΙΚΌΣ:`).
|
|
43
|
+
- Sensitive key names are compared in one normalised form everywhere,
|
|
44
|
+
including the names passed in `redactKeys`, so `GİZLİ`, `ŞİFRE` and
|
|
45
|
+
`ΚΩΔΙΚΌΣ` keys are masked whole. Keys themselves are never rewritten.
|
|
46
|
+
- A detector's prefilter follows the pattern's own case rules, so it can no
|
|
47
|
+
longer skip a detector that would have matched (`aws_ſecret_access_key`).
|
|
48
|
+
- The assignment mask stops at the first separator, so `secret=key:value:more`
|
|
49
|
+
becomes `secret=***` instead of keeping part of the value.
|
|
50
|
+
- SWIFT/BIC codes need a real country code in letters five and six, so
|
|
51
|
+
`PASSWORD`, `REDACTED` and `QWERTY12345` are no longer read as bank codes.
|
|
52
|
+
- Terms: a combining mark counts as part of a word (`राज` no longer matches
|
|
53
|
+
inside `राजा`), longer terms win by characters with ties kept in your
|
|
54
|
+
order, the replacement comes from the term that matched, a failed boundary
|
|
55
|
+
moves the search on by one character, and dotted i folds as in keywords.
|
|
56
|
+
- Context windows and the confidence model's windows are measured the same
|
|
57
|
+
way in every engine, and the model's context words use ASCII boundaries and
|
|
58
|
+
ASCII case folding.
|
|
59
|
+
- A bare `.` in a custom pack now means the same in Python, Go and Rust as in
|
|
60
|
+
JavaScript: it no longer matches `\r`, U+2028 or U+2029.
|
|
61
|
+
- The JavaScript `entropy` pack validator counts code points in its total as
|
|
62
|
+
well as in each symbol's count, as the other engines do. An emoji had been
|
|
63
|
+
counted twice.
|
|
64
|
+
|
|
65
|
+
## 1.11.0 (2026-11-23)
|
|
66
|
+
|
|
67
|
+
### Added: clean test recordings and snapshots
|
|
68
|
+
|
|
69
|
+
- `flare-redact/recording`: `redactHar()`, `redactHarEntry()` and
|
|
70
|
+
`pollyBeforePersist()` clean recorded HTTP traffic. Credential headers are
|
|
71
|
+
recognised with or without an `x-` prefix (`X-Api-Key`, `Set-Cookie`,
|
|
72
|
+
`Proxy-Authorization`, `X-Amz-Security-Token`), cookies are always masked,
|
|
73
|
+
query strings and form bodies are masked one field at a time, and JSON,
|
|
74
|
+
form and base64 text bodies keep their field names. A body that needs no
|
|
75
|
+
change keeps its exact bytes; `Content-Length` and `size` follow a change.
|
|
76
|
+
- `flare-redact --har` and `python -m flare_redact --har` clean a HAR file from
|
|
77
|
+
the command line, with the same output from both engines.
|
|
78
|
+
- Python: `flare_redact.recording.vcr_config()` for vcrpy and
|
|
79
|
+
pytest-recording. Requests are masked the same way when recorded and when
|
|
80
|
+
matched, so playback keeps working; gzip bodies are stored decompressed so
|
|
81
|
+
they can be cleaned.
|
|
82
|
+
- `flare-redact/snapshot`: a Vitest and Jest snapshot serializer that masks
|
|
83
|
+
only values that need it and keeps the usual snapshot format.
|
|
84
|
+
|
|
85
|
+
### Added: pandas, Polars and DuckDB
|
|
86
|
+
|
|
87
|
+
- Python `flare_redact.frames`: `redact_frame()` and `redact_series()` clean
|
|
88
|
+
the text columns of a pandas or Polars data frame (Polars lazy frames too),
|
|
89
|
+
and `scan_frame()` counts findings per column and detector without
|
|
90
|
+
including any value.
|
|
91
|
+
- `frames.register()` adds a `.flare` namespace to pandas `DataFrame` and
|
|
92
|
+
`Series` and to Polars `DataFrame`, `LazyFrame`, `Series` and `Expr`, so
|
|
93
|
+
`pl.col("note").flare.redact()` works inside a query.
|
|
94
|
+
- `frames.register_duckdb(con)` adds the SQL functions `redact(text)`,
|
|
95
|
+
`redact_field(name, value)` and `redact_is_clean(text)`.
|
|
96
|
+
- A column name counts as a field name, so a `password` column is masked
|
|
97
|
+
whole. Each distinct value is redacted once. None of the three libraries
|
|
98
|
+
becomes a dependency.
|
|
99
|
+
|
|
100
|
+
### Added: session replay masking
|
|
101
|
+
|
|
102
|
+
- `flare-redact/replay`: `replayMaskFn()` for rrweb's `maskTextFn` and
|
|
103
|
+
`maskInputFn` and Sentry Session Replay's `maskFn`, and `rrwebMasking()` for
|
|
104
|
+
rrweb `record()` and PostHog `session_recording`. Sensitive text is masked
|
|
105
|
+
and the rest of the replay stays readable.
|
|
106
|
+
- Masked characters become `*` with spaces kept, so the replay layout does not
|
|
107
|
+
shift. Password, one-time code and card fields, and fields named like a
|
|
108
|
+
credential, are masked whole. Browser-safe, with no Node built-ins.
|
|
109
|
+
|
|
110
|
+
### Added: a Fluent Bit WASM filter
|
|
111
|
+
|
|
112
|
+
- `sdk/fluent-bit`: the Rust engine as a Fluent Bit WASM filter, so logs are
|
|
113
|
+
redacted on the node before they are shipped. `Function_Name` picks a
|
|
114
|
+
policy (`flare_redact`, `flare_redact_pii`, `flare_redact_label`), and an
|
|
115
|
+
optional `flare-redact.json` takes the usual options.
|
|
116
|
+
- It fails closed: an invalid config, or a record that cannot be redacted,
|
|
117
|
+
gives `{"flare_redact_error": "..."}` instead of the original record.
|
|
118
|
+
- CI runs the filter in the official Fluent Bit 5.2.0 image, and each release
|
|
119
|
+
gets `flare-redact-fluent-bit.wasm` with its SHA-256.
|
|
120
|
+
|
|
121
|
+
### Added: shadow mode
|
|
122
|
+
|
|
123
|
+
- `FLARE_REDACT_MODE=shadow` with `--import flare-redact/register` leaves the
|
|
124
|
+
console output alone and reports what would have been redacted, by detector
|
|
125
|
+
and field, on stderr at exit (and every `FLARE_REDACT_REPORT_EVERY`
|
|
126
|
+
seconds). `audit` redacts and reports. An unknown mode stops startup.
|
|
127
|
+
- `flare-redact/audit`: `createAudit()` counts findings by detector, risk,
|
|
128
|
+
source and field path, never keeping a matched value, and can feed an
|
|
129
|
+
OpenTelemetry meter (`flare_redact.findings`, `flare_redact.scanned`).
|
|
130
|
+
`shadowConsole()` counts console output.
|
|
131
|
+
- Python: `flare_redact.audit.Audit` with the same counts and counter names,
|
|
132
|
+
and `AuditFilter` for `logging`.
|
|
133
|
+
|
|
134
|
+
### Added: database query logs
|
|
135
|
+
|
|
136
|
+
- `flare-redact/db`: `redactQuery(sql, params)` matches each placeholder and
|
|
137
|
+
literal to its column (`col = ?`, `col IN (...)`, qualified names, `INSERT`
|
|
138
|
+
rows), so a value bound to `password`, `token` or `api_key` is masked by
|
|
139
|
+
name, and checks everything else with the usual detectors.
|
|
140
|
+
- Hooks for Prisma (`$on('query')`), Drizzle (`logger`), TypeORM (wraps any
|
|
141
|
+
logger), Knex (`on('query')`) and Sequelize (`logging`, with or without
|
|
142
|
+
`logQueryParameters`).
|
|
143
|
+
|
|
3
144
|
## 1.10.4 (2026-11-22)
|
|
4
145
|
|
|
5
|
-
### Security: password-only connection strings were not redacted (GHSA-
|
|
146
|
+
### Security: password-only connection strings were not redacted (GHSA-h8xg-cv97-3pfp)
|
|
6
147
|
|
|
7
148
|
- `url_credentials` required a username before `:password@`, so a URL with an
|
|
8
149
|
empty username, the usual form for Redis and Valkey and also used by
|
|
@@ -14,8 +155,8 @@
|
|
|
14
155
|
masked: `postgres://user:pa:ss@db` became `postgres://user:pa:***@db`. The
|
|
15
156
|
whole password is masked now, as the Python, Go and Rust engines already did.
|
|
16
157
|
- The JavaScript, Python, Go and Rust engines change together, and the
|
|
17
|
-
conformance corpus has both cases. Reported
|
|
18
|
-
|
|
158
|
+
conformance corpus has both cases. Reported by Pranshu Raghav
|
|
159
|
+
([@Zureno](https://github.com/Zureno)).
|
|
19
160
|
|
|
20
161
|
## 1.10.3 (2026-11-20)
|
|
21
162
|
|
package/README.md
CHANGED
|
@@ -64,8 +64,8 @@ redact({ user: 'bob@corp.com', password: 'hunter2', note: 'my key is AKIAIOSFODN
|
|
|
64
64
|
- 🌍 **International by default: 24 languages** of secret vocabulary and
|
|
65
65
|
national ID formats.
|
|
66
66
|
- 🪶 **Zero dependencies.** Node 20+, browsers, edge runtimes, Bun and Deno.
|
|
67
|
-
- 🐍 **Python, Go and
|
|
68
|
-
the same conformance suite.
|
|
67
|
+
- 🐍 **Python, Go, Rust, Java and .NET** engines that run the same detector
|
|
68
|
+
spec and pass the same conformance suite.
|
|
69
69
|
|
|
70
70
|
<p align="center">
|
|
71
71
|
🇬🇧 🇨🇳 🇮🇳 🇪🇸 🇸🇦 🇫🇷 🇵🇹 🇷🇺 🇯🇵 🇩🇪 🇰🇷 🇹🇷 🇮🇹 🇮🇷 🇵🇱 🇺🇦 🇳🇱 🇻🇳 🇮🇩 🇹🇭 🇬🇷 🇮🇱 🇦🇿 🇷🇴
|
|
@@ -96,6 +96,10 @@ Want more than the defaults? Choose a goal instead of a detector list:
|
|
|
96
96
|
|
|
97
97
|
### Logs
|
|
98
98
|
|
|
99
|
+
ORM query logs too: Prisma, Drizzle, TypeORM, Knex and Sequelize hooks from
|
|
100
|
+
`flare-redact/db` mask bound parameters by the column they go into, so the
|
|
101
|
+
password in `["ada@example.com", "hunter2"]` is caught ([details](docs/guide.md#database-query-logs)).
|
|
102
|
+
|
|
99
103
|
```js
|
|
100
104
|
import pino from 'pino';
|
|
101
105
|
import { pinoRedact } from 'flare-redact/pino';
|
|
@@ -108,6 +112,10 @@ log.info({ user: 'bob@corp.com', token: 'ghp_…' }, 'login');
|
|
|
108
112
|
winston has `winstonRedact()` from `flare-redact/winston`, and plain `console`
|
|
109
113
|
has `wrapConsole()` or the `--import` flag above.
|
|
110
114
|
|
|
115
|
+
Not sure what turning it on would hide? Run in shadow mode first:
|
|
116
|
+
`FLARE_REDACT_MODE=shadow` leaves the output as it is and prints what would have
|
|
117
|
+
been redacted, by detector and field, when the process exits ([details](docs/guide.md#measure-before-you-enforce)).
|
|
118
|
+
|
|
111
119
|
### LLM prompts
|
|
112
120
|
|
|
113
121
|
```js
|
|
@@ -142,6 +150,10 @@ Events, spans, logs and breadcrumbs are redacted in your process, before they
|
|
|
142
150
|
leave it. Sentry's own ids, release and stack frames stay intact, so grouping
|
|
143
151
|
and source maps keep working. [Details and limits](docs/guide.md#one-policy-everywhere).
|
|
144
152
|
|
|
153
|
+
For Session Replay, `Sentry.replayIntegration({ maskFn: replayMaskFn() })` from
|
|
154
|
+
`flare-redact/replay` masks only what is sensitive and keeps the rest of the
|
|
155
|
+
replay readable. rrweb and PostHog work the same way ([details](docs/guide.md#mask-session-replays)).
|
|
156
|
+
|
|
145
157
|
### Commits and CI
|
|
146
158
|
|
|
147
159
|
On GitHub, `uses: flare-collection/flare-redact@v1` annotates each finding on the pull request ([inputs](docs/guide.md#fail-a-build-when-a-secret-sneaks-in)).
|
|
@@ -153,11 +165,33 @@ npx flare-redact --scan . --sarif # CI: exits 1 on a finding, never prints th
|
|
|
153
165
|
|
|
154
166
|
Using [pre-commit](https://pre-commit.com)? Add `repo: https://github.com/flare-collection/flare-redact` with `id: flare-redact` ([setup](docs/guide.md#fail-a-build-when-a-secret-sneaks-in)).
|
|
155
167
|
|
|
168
|
+
### Test recordings and snapshots
|
|
169
|
+
|
|
170
|
+
Cassettes, HAR files and snapshots are committed with the code. Clean them
|
|
171
|
+
before they are written, without breaking replay ([details](docs/guide.md#clean-test-recordings-and-snapshots)):
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
from flare_redact.recording import vcr_config as flare_vcr_config
|
|
175
|
+
|
|
176
|
+
@pytest.fixture(scope="module")
|
|
177
|
+
def vcr_config():
|
|
178
|
+
return flare_vcr_config() # vcrpy and pytest-recording
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
```js
|
|
182
|
+
export default { test: { snapshotSerializers: ['flare-redact/snapshot'] } }; // Vitest
|
|
183
|
+
polly.server.any().on('beforePersist', pollyBeforePersist()); // Polly.js
|
|
184
|
+
// npx flare-redact --har < session.har > session.safe.har // any HAR file
|
|
185
|
+
```
|
|
186
|
+
|
|
156
187
|
### No Node in the stack?
|
|
157
188
|
|
|
189
|
+
Collecting logs with Fluent Bit? The [WASM filter](docs/guide.md#fluent-bit)
|
|
190
|
+
redacts every record on the node, with no change to the services.
|
|
191
|
+
|
|
158
192
|
Point any service at the [sidecar gateway](docs/guide.md#the-sidecar-gateway)
|
|
159
193
|
and it redacts request bodies on the way to OpenAI or Anthropic, with no code
|
|
160
|
-
change. Or use the [Python, Go and
|
|
194
|
+
change. Or use the [Python, Go, Rust, Java and .NET](docs/guide.md#python-go-rust-java-and-net) engines:
|
|
161
195
|
|
|
162
196
|
```python
|
|
163
197
|
from flare_redact import create_session
|
|
@@ -166,6 +200,9 @@ session = create_session(enable=["pii"])
|
|
|
166
200
|
safe = session.redact("Email the invoice to ada@example.com")
|
|
167
201
|
```
|
|
168
202
|
|
|
203
|
+
Data frames and SQL tables too: `frames.redact_frame(df)` for pandas and
|
|
204
|
+
Polars, and `redact(note)` in DuckDB ([details](docs/guide.md#clean-data-frames-and-sql-tables)).
|
|
205
|
+
|
|
169
206
|
## How it compares
|
|
170
207
|
|
|
171
208
|
| Tool | What it does well | What flare-redact adds |
|
package/SECURITY.md
CHANGED
|
@@ -66,7 +66,7 @@ about an upstream you did not configure.
|
|
|
66
66
|
|
|
67
67
|
## Other language engines
|
|
68
68
|
|
|
69
|
-
The Python, Go and
|
|
69
|
+
The Python, Go, Rust, Java and .NET engines implement the FRS-1 subset, which is deliberately
|
|
70
70
|
narrower than the Node detector set — `spec/SPEC.md` §14 lists every difference.
|
|
71
71
|
A pack that uses a construct an engine cannot execute exactly fails to load
|
|
72
72
|
rather than loading with the check skipped. Report a divergence between engines
|
package/dist/audit.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shadow mode: measure what a policy would redact before it is enforced.
|
|
3
|
+
*
|
|
4
|
+
* Turning redaction on in production is a leap of faith: nobody knows how many
|
|
5
|
+
* log lines carry an email, which detector would fire most, or whether a field
|
|
6
|
+
* the team needs would be masked. An audit counts findings by detector, risk,
|
|
7
|
+
* source and field path while the data passes through unchanged, so the
|
|
8
|
+
* decision to enforce rests on numbers. It never stores a matched value.
|
|
9
|
+
*
|
|
10
|
+
* node --import flare-redact/register app.js with FLARE_REDACT_MODE=shadow
|
|
11
|
+
*
|
|
12
|
+
* const audit = createAudit({ preset: 'gdpr', meter }); // meter: OpenTelemetry, optional
|
|
13
|
+
* audit.observe(event, 'webhook'); // unchanged, counted
|
|
14
|
+
* audit.report(); // counts only, safe to log
|
|
15
|
+
*/
|
|
16
|
+
import { type RedactOptions } from './index.js';
|
|
17
|
+
/** The parts of an OpenTelemetry `Meter` an audit uses. */
|
|
18
|
+
export interface MeterLike {
|
|
19
|
+
createCounter(name: string, options?: {
|
|
20
|
+
description?: string;
|
|
21
|
+
unit?: string;
|
|
22
|
+
}): {
|
|
23
|
+
add(value: number, attributes?: Record<string, string>): void;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** One finding as an audit reports it: no value, no offsets. */
|
|
27
|
+
export interface AuditEvent {
|
|
28
|
+
detector: string;
|
|
29
|
+
risk: string;
|
|
30
|
+
source: string;
|
|
31
|
+
path?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface AuditOptions extends RedactOptions {
|
|
34
|
+
/** An OpenTelemetry meter: `flare_redact.findings` and `flare_redact.scanned` counters are added. */
|
|
35
|
+
meter?: MeterLike;
|
|
36
|
+
/** Called for each finding, with counts-safe fields only. */
|
|
37
|
+
onFinding?: (event: AuditEvent) => void;
|
|
38
|
+
/** Distinct field paths kept in the report; the rest count under `(other)`. Default 500. */
|
|
39
|
+
maxPaths?: number;
|
|
40
|
+
}
|
|
41
|
+
export interface AuditReport {
|
|
42
|
+
/** When counting started (ISO 8601). */
|
|
43
|
+
since: string;
|
|
44
|
+
/** Values observed. */
|
|
45
|
+
scanned: number;
|
|
46
|
+
/** Values that held at least one finding. */
|
|
47
|
+
withFindings: number;
|
|
48
|
+
/** Findings in all. */
|
|
49
|
+
total: number;
|
|
50
|
+
byDetector: Record<string, number>;
|
|
51
|
+
byRisk: Record<string, number>;
|
|
52
|
+
bySource: Record<string, {
|
|
53
|
+
scanned: number;
|
|
54
|
+
total: number;
|
|
55
|
+
byDetector: Record<string, number>;
|
|
56
|
+
}>;
|
|
57
|
+
/** Findings per field path, array indices folded to `[]`, most frequent first. */
|
|
58
|
+
byPath: Record<string, number>;
|
|
59
|
+
}
|
|
60
|
+
export interface Audit {
|
|
61
|
+
/** Count what `value` would have redacted and return it unchanged. */
|
|
62
|
+
observe<T>(value: T, source?: string): T;
|
|
63
|
+
/** Redact `value` and count what was redacted: enforcement with the same numbers. */
|
|
64
|
+
redact<T>(value: T, source?: string): T;
|
|
65
|
+
/** The counts so far. Safe to log: no values. */
|
|
66
|
+
report(): AuditReport;
|
|
67
|
+
/** The report as a short table for a terminal or a log line per row. */
|
|
68
|
+
format(): string;
|
|
69
|
+
/** Start counting again. */
|
|
70
|
+
reset(): void;
|
|
71
|
+
}
|
|
72
|
+
export declare function createAudit(opts?: AuditOptions): Audit;
|
|
73
|
+
/**
|
|
74
|
+
* Count what `console.*` would redact without changing what it prints. Each
|
|
75
|
+
* method is its own source (`console.error`). With `enforce: true` the output
|
|
76
|
+
* is redacted as well, and still counted. Returns a function that puts the
|
|
77
|
+
* console back.
|
|
78
|
+
*/
|
|
79
|
+
export declare function shadowConsole(audit: Audit, target?: Console, { enforce }?: {
|
|
80
|
+
enforce?: boolean;
|
|
81
|
+
}): () => void;
|
|
82
|
+
//# sourceMappingURL=audit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAG/D,2DAA2D;AAC3D,MAAM,WAAW,SAAS;IACxB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG;QAC9E,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;KAC/D,CAAC;CACH;AAED,gEAAgE;AAChE,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,YAAa,SAAQ,aAAa;IACjD,qGAAqG;IACrG,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,6DAA6D;IAC7D,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;IACxC,4FAA4F;IAC5F,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,uBAAuB;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,6CAA6C;IAC7C,YAAY,EAAE,MAAM,CAAC;IACrB,uBAAuB;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC,CAAC;IACjG,kFAAkF;IAClF,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC;AAYD,MAAM,WAAW,KAAK;IACpB,sEAAsE;IACtE,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC;IACzC,qFAAqF;IACrF,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC;IACxC,iDAAiD;IACjD,MAAM,IAAI,WAAW,CAAC;IACtB,wEAAwE;IACxE,MAAM,IAAI,MAAM,CAAC;IACjB,4BAA4B;IAC5B,KAAK,IAAI,IAAI,CAAC;CACf;AAED,wBAAgB,WAAW,CAAC,IAAI,GAAE,YAAiB,GAAG,KAAK,CA4F1D;AAID;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,KAAK,EACZ,MAAM,GAAE,OAAiB,EACzB,EAAE,OAAe,EAAE,GAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAO,GAC9C,MAAM,IAAI,CAqBZ"}
|
package/dist/audit.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shadow mode: measure what a policy would redact before it is enforced.
|
|
3
|
+
*
|
|
4
|
+
* Turning redaction on in production is a leap of faith: nobody knows how many
|
|
5
|
+
* log lines carry an email, which detector would fire most, or whether a field
|
|
6
|
+
* the team needs would be masked. An audit counts findings by detector, risk,
|
|
7
|
+
* source and field path while the data passes through unchanged, so the
|
|
8
|
+
* decision to enforce rests on numbers. It never stores a matched value.
|
|
9
|
+
*
|
|
10
|
+
* node --import flare-redact/register app.js with FLARE_REDACT_MODE=shadow
|
|
11
|
+
*
|
|
12
|
+
* const audit = createAudit({ preset: 'gdpr', meter }); // meter: OpenTelemetry, optional
|
|
13
|
+
* audit.observe(event, 'webhook'); // unchanged, counted
|
|
14
|
+
* audit.report(); // counts only, safe to log
|
|
15
|
+
*/
|
|
16
|
+
import { compilePolicy } from './index.js';
|
|
17
|
+
const bump = (counts, key, by = 1) => {
|
|
18
|
+
counts[key] = (counts[key] ?? 0) + by;
|
|
19
|
+
};
|
|
20
|
+
const sortDesc = (counts) => Object.fromEntries(Object.entries(counts).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])));
|
|
21
|
+
/** `users[3].email` and `users[7].email` are the same field. */
|
|
22
|
+
const foldPath = (path) => path.replace(/\[\d+\]/g, '[]');
|
|
23
|
+
export function createAudit(opts = {}) {
|
|
24
|
+
const { meter, onFinding, maxPaths = 500, ...redactOptions } = opts;
|
|
25
|
+
// An audit must never keep a matched value, whatever the caller passed.
|
|
26
|
+
const policy = compilePolicy({ ...redactOptions, includeValues: false });
|
|
27
|
+
const findingsCounter = meter?.createCounter('flare_redact.findings', {
|
|
28
|
+
description: 'Values flare-redact found, by detector, risk and source',
|
|
29
|
+
unit: '{finding}',
|
|
30
|
+
});
|
|
31
|
+
const scannedCounter = meter?.createCounter('flare_redact.scanned', {
|
|
32
|
+
description: 'Values flare-redact checked, by source',
|
|
33
|
+
unit: '{value}',
|
|
34
|
+
});
|
|
35
|
+
let state = fresh();
|
|
36
|
+
function fresh() {
|
|
37
|
+
return {
|
|
38
|
+
since: new Date().toISOString(),
|
|
39
|
+
scanned: 0,
|
|
40
|
+
withFindings: 0,
|
|
41
|
+
total: 0,
|
|
42
|
+
byDetector: {},
|
|
43
|
+
byRisk: {},
|
|
44
|
+
bySource: {},
|
|
45
|
+
byPath: {},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const record = (findings, source) => {
|
|
49
|
+
state.scanned += 1;
|
|
50
|
+
const perSource = (state.bySource[source] ??= { scanned: 0, total: 0, byDetector: {} });
|
|
51
|
+
perSource.scanned += 1;
|
|
52
|
+
scannedCounter?.add(1, { source });
|
|
53
|
+
if (!findings.length)
|
|
54
|
+
return;
|
|
55
|
+
state.withFindings += 1;
|
|
56
|
+
for (const finding of findings) {
|
|
57
|
+
state.total += 1;
|
|
58
|
+
perSource.total += 1;
|
|
59
|
+
bump(state.byDetector, finding.detector);
|
|
60
|
+
bump(state.byRisk, finding.risk);
|
|
61
|
+
bump(perSource.byDetector, finding.detector);
|
|
62
|
+
if (finding.path) {
|
|
63
|
+
const path = foldPath(finding.path);
|
|
64
|
+
if (path in state.byPath || Object.keys(state.byPath).length < maxPaths)
|
|
65
|
+
bump(state.byPath, path);
|
|
66
|
+
else
|
|
67
|
+
bump(state.byPath, '(other)');
|
|
68
|
+
}
|
|
69
|
+
findingsCounter?.add(1, { detector: finding.detector, risk: finding.risk, source });
|
|
70
|
+
onFinding?.({
|
|
71
|
+
detector: finding.detector,
|
|
72
|
+
risk: finding.risk,
|
|
73
|
+
source,
|
|
74
|
+
...(finding.path ? { path: foldPath(finding.path) } : {}),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const report = () => ({
|
|
79
|
+
since: state.since,
|
|
80
|
+
scanned: state.scanned,
|
|
81
|
+
withFindings: state.withFindings,
|
|
82
|
+
total: state.total,
|
|
83
|
+
byDetector: sortDesc(state.byDetector),
|
|
84
|
+
byRisk: sortDesc(state.byRisk),
|
|
85
|
+
bySource: Object.fromEntries(Object.entries(state.bySource).map(([name, s]) => [name, { ...s, byDetector: sortDesc(s.byDetector) }])),
|
|
86
|
+
byPath: sortDesc(state.byPath),
|
|
87
|
+
});
|
|
88
|
+
return {
|
|
89
|
+
observe(value, source = 'default') {
|
|
90
|
+
record(policy.scan(value), source);
|
|
91
|
+
return value;
|
|
92
|
+
},
|
|
93
|
+
redact(value, source = 'default') {
|
|
94
|
+
record(policy.scan(value), source);
|
|
95
|
+
return policy.redact(value);
|
|
96
|
+
},
|
|
97
|
+
report,
|
|
98
|
+
format() {
|
|
99
|
+
const r = report();
|
|
100
|
+
const share = r.scanned ? ` (${((r.withFindings / r.scanned) * 100).toFixed(1)}%)` : '';
|
|
101
|
+
const findings = `${r.total} ${r.total === 1 ? 'finding' : 'findings'}`;
|
|
102
|
+
const lines = [`${findings} in ${r.withFindings} of ${r.scanned} values${share} since ${r.since}`];
|
|
103
|
+
for (const [detector, count] of Object.entries(r.byDetector))
|
|
104
|
+
lines.push(` ${detector.padEnd(24)} ${count}`);
|
|
105
|
+
const paths = Object.entries(r.byPath).slice(0, 10);
|
|
106
|
+
if (paths.length)
|
|
107
|
+
lines.push(' top fields:', ...paths.map(([path, count]) => ` ${path.padEnd(22)} ${count}`));
|
|
108
|
+
return lines.join('\n');
|
|
109
|
+
},
|
|
110
|
+
reset() {
|
|
111
|
+
state = fresh();
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Count what `console.*` would redact without changing what it prints. Each
|
|
117
|
+
* method is its own source (`console.error`). With `enforce: true` the output
|
|
118
|
+
* is redacted as well, and still counted. Returns a function that puts the
|
|
119
|
+
* console back.
|
|
120
|
+
*/
|
|
121
|
+
export function shadowConsole(audit, target = console, { enforce = false } = {}) {
|
|
122
|
+
const sink = target;
|
|
123
|
+
const original = new Map();
|
|
124
|
+
for (const name of ['log', 'info', 'warn', 'error', 'debug']) {
|
|
125
|
+
const fn = sink[name].bind(target);
|
|
126
|
+
original.set(name, fn);
|
|
127
|
+
const source = `console.${name}`;
|
|
128
|
+
sink[name] = enforce
|
|
129
|
+
? (...args) => fn(...args.map((arg) => audit.redact(arg, source)))
|
|
130
|
+
: (...args) => {
|
|
131
|
+
try {
|
|
132
|
+
for (const arg of args)
|
|
133
|
+
audit.observe(arg, source);
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
// Counting must never break logging.
|
|
137
|
+
}
|
|
138
|
+
fn(...args);
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
return () => {
|
|
142
|
+
for (const [name, fn] of original)
|
|
143
|
+
sink[name] = fn;
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=audit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.js","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,aAAa,EAAsB,MAAM,YAAY,CAAC;AA2C/D,MAAM,IAAI,GAAG,CAAC,MAA8B,EAAE,GAAW,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE;IACnE,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC;AACxC,CAAC,CAAC;AAEF,MAAM,QAAQ,GAAG,CAAC,MAA8B,EAA0B,EAAE,CAC1E,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAErG,gEAAgE;AAChE,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AAe1E,MAAM,UAAU,WAAW,CAAC,OAAqB,EAAE;IACjD,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,GAAG,GAAG,EAAE,GAAG,aAAa,EAAE,GA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,MAAM,EAAE,OAAO,EAAE,OAAO,CAAoB,EAAE,CAAC;QAChF,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACnC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACvB,MAAM,MAAM,GAAG,WAAW,IAAI,EAAE,CAAC;QACjC,IAAI,CAAC,IAAI,CAAC,GAAG,OAAO;YAClB,CAAC,CAAC,CAAC,GAAG,IAAe,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC;YAC7E,CAAC,CAAC,CAAC,GAAG,IAAe,EAAE,EAAE;gBACrB,IAAI,CAAC;oBACH,KAAK,MAAM,GAAG,IAAI,IAAI;wBAAE,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;gBACrD,CAAC;gBAAC,MAAM,CAAC;oBACP,qCAAqC;gBACvC,CAAC;gBACD,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;YACd,CAAC,CAAC;IACR,CAAC;IACD,OAAO,GAAG,EAAE;QACV,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,QAAQ;YAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;IACrD,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAyWA,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CA+J1D"}
|
package/dist/cli.js
CHANGED
|
@@ -4,6 +4,7 @@ import { readStagedChanges } from './staged.js';
|
|
|
4
4
|
import { withoutCodeAssignments } from './code-reference.js';
|
|
5
5
|
import { redact, summary, compilePolicy, createVault, restore, sealVault, openVault, isSealedVault, DETECTORS, } from './index.js';
|
|
6
6
|
import { redactCsv } from './csv.js';
|
|
7
|
+
import { redactHar } from './recording.js';
|
|
7
8
|
import { HELP, renderHelp } from './help.js';
|
|
8
9
|
const VERSION = (() => {
|
|
9
10
|
try {
|
|
@@ -25,6 +26,7 @@ function parseArgs(argv) {
|
|
|
25
26
|
let summaryMode = false;
|
|
26
27
|
let jsonMode = false;
|
|
27
28
|
let csvMode = false;
|
|
29
|
+
let harMode = false;
|
|
28
30
|
let showHelp = false;
|
|
29
31
|
let showVersion = false;
|
|
30
32
|
let listMode = false;
|
|
@@ -68,6 +70,9 @@ function parseArgs(argv) {
|
|
|
68
70
|
case '--csv':
|
|
69
71
|
csvMode = true;
|
|
70
72
|
break;
|
|
73
|
+
case '--har':
|
|
74
|
+
harMode = true;
|
|
75
|
+
break;
|
|
71
76
|
case '--list':
|
|
72
77
|
listMode = true;
|
|
73
78
|
break;
|
|
@@ -162,8 +167,8 @@ function parseArgs(argv) {
|
|
|
162
167
|
opts.terms = terms;
|
|
163
168
|
if (staged && files.length)
|
|
164
169
|
throw new Error('--staged reads the git index; it takes no file arguments');
|
|
165
|
-
if (staged && (summaryMode || jsonMode || csvMode || vaultFile || restoreFile)) {
|
|
166
|
-
throw new Error('--staged only scans; it cannot be combined with --summary, --json, --csv, --vault or --restore');
|
|
170
|
+
if (staged && (summaryMode || jsonMode || csvMode || harMode || vaultFile || restoreFile)) {
|
|
171
|
+
throw new Error('--staged only scans; it cannot be combined with --summary, --json, --csv, --har, --vault or --restore');
|
|
167
172
|
}
|
|
168
173
|
return {
|
|
169
174
|
opts,
|
|
@@ -173,6 +178,7 @@ function parseArgs(argv) {
|
|
|
173
178
|
summaryMode,
|
|
174
179
|
jsonMode,
|
|
175
180
|
csvMode,
|
|
181
|
+
harMode,
|
|
176
182
|
showHelp,
|
|
177
183
|
showVersion,
|
|
178
184
|
listMode,
|
|
@@ -390,7 +396,7 @@ export async function main(argv) {
|
|
|
390
396
|
process.stderr.write(`${e.message}\n\n${HELP}`);
|
|
391
397
|
return 2;
|
|
392
398
|
}
|
|
393
|
-
const { opts, files, scanMode, scanFormat, summaryMode, jsonMode, csvMode, showHelp, showVersion, listMode, vaultFile, restoreFile, secretEnv, vaultPasswordEnv, allowPlaintextVault, excludes, maxFileSize, defaultExcludes, staged, codeFilter, } = parsed;
|
|
399
|
+
const { opts, files, scanMode, scanFormat, summaryMode, jsonMode, csvMode, harMode, showHelp, showVersion, listMode, vaultFile, restoreFile, secretEnv, vaultPasswordEnv, allowPlaintextVault, excludes, maxFileSize, defaultExcludes, staged, codeFilter, } = parsed;
|
|
394
400
|
if (!opts.transformSecret && process.env[secretEnv])
|
|
395
401
|
opts.transformSecret = process.env[secretEnv];
|
|
396
402
|
if (opts.mode === 'fpe') {
|
|
@@ -421,6 +427,17 @@ export async function main(argv) {
|
|
|
421
427
|
process.stderr.write(`${e.message}\n`);
|
|
422
428
|
return 2;
|
|
423
429
|
}
|
|
430
|
+
if (harMode) {
|
|
431
|
+
const har = tryParse(raw);
|
|
432
|
+
if (har === PARSE_ERROR)
|
|
433
|
+
return 2;
|
|
434
|
+
if (!har || typeof har !== 'object' || typeof har.log !== 'object') {
|
|
435
|
+
process.stderr.write('--har expects a HAR document with a top-level "log" object\n');
|
|
436
|
+
return 2;
|
|
437
|
+
}
|
|
438
|
+
process.stdout.write(JSON.stringify(redactHar(har, opts), null, 2) + '\n');
|
|
439
|
+
return 0;
|
|
440
|
+
}
|
|
424
441
|
const data = jsonMode ? tryParse(raw) : raw;
|
|
425
442
|
if (jsonMode && data === PARSE_ERROR)
|
|
426
443
|
return 2;
|