flare-redact 1.10.4 → 1.11.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 +82 -3
- package/README.md +37 -0
- 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/help.d.ts +1 -1
- package/dist/help.d.ts.map +1 -1
- package/dist/help.js +4 -2
- package/dist/help.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/docs/guide.md +290 -6
- package/package.json +21 -1
- package/spec/detectors.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../src/snapshot.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,aAAa,EAAsB,MAAM,YAAY,CAAC;AAS/D;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,OAAsB,EAAE;IAC/D,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IACnC,0EAA0E;IAC1E,qEAAqE;IACrE,MAAM,MAAM,GAAG,IAAI,OAAO,EAAU,CAAC;IACrC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAU,CAAC;IACrC,OAAO;QACL,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE;YACd,IAAI,OAAO,KAAK,KAAK,QAAQ;gBAAE,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACvF,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC;gBAAE,OAAO,KAAK,CAAC;YACnF,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAChC,CAAC;QACD,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE;YAC9D,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACjC,IAAI,OAAO,GAAG,KAAK,QAAQ;gBAAE,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;iBAC5C,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI;gBAAE,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAClE,IAAI,CAAC;gBACH,OAAO,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;YACxD,CAAC;oBAAS,CAAC;gBACT,IAAI,OAAO,GAAG,KAAK,QAAQ;oBAAE,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACtD,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,GAAG,wBAAwB,EAAE,CAAC;AAE9C,MAAM,CAAC,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;AACpC,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC;AAC9C,eAAe,UAAU,CAAC"}
|
package/docs/guide.md
CHANGED
|
@@ -11,6 +11,7 @@ version. Coding assistants can read the same API in condensed form at
|
|
|
11
11
|
- [Practical guides](https://flare-collection.github.io/flare-redact/guides/)
|
|
12
12
|
- [Runnable examples](#runnable-examples)
|
|
13
13
|
- [Python, Go, and Rust](#python-go-and-rust)
|
|
14
|
+
- [Fluent Bit](#fluent-bit)
|
|
14
15
|
- [The sidecar gateway](#the-sidecar-gateway)
|
|
15
16
|
- [Redact anything](#redact-anything)
|
|
16
17
|
- [Integrate any SDK or framework](#integrate-any-sdk-or-framework)
|
|
@@ -25,10 +26,15 @@ version. Coding assistants can read the same API in condensed form at
|
|
|
25
26
|
- [Protect tool calls and MCP loops](#protect-tool-calls-and-mcp-loops)
|
|
26
27
|
- [Your own words](#your-own-words)
|
|
27
28
|
- [See what leaks, and why](#see-what-leaks-and-why)
|
|
29
|
+
- [Measure before you enforce](#measure-before-you-enforce)
|
|
28
30
|
- [Guard your logger in one line](#guard-your-logger-in-one-line)
|
|
31
|
+
- [Database query logs](#database-query-logs)
|
|
29
32
|
- [One policy, everywhere](#one-policy-everywhere)
|
|
30
33
|
- [Anonymize a dataset for staging](#anonymize-a-dataset-for-staging)
|
|
34
|
+
- [Clean test recordings and snapshots](#clean-test-recordings-and-snapshots)
|
|
35
|
+
- [Clean data frames and SQL tables](#clean-data-frames-and-sql-tables)
|
|
31
36
|
- [Guard what leaves your app](#guard-what-leaves-your-app)
|
|
37
|
+
- [Mask session replays](#mask-session-replays)
|
|
32
38
|
- [Streams](#streams)
|
|
33
39
|
- [Fail a build when a secret sneaks in](#fail-a-build-when-a-secret-sneaks-in)
|
|
34
40
|
- [CLI](#cli)
|
|
@@ -177,11 +183,11 @@ first release after 1.9.1. Until it lands, or to pin a tag, install them from
|
|
|
177
183
|
this repository:
|
|
178
184
|
|
|
179
185
|
```bash
|
|
180
|
-
pip install "flare-redact @ git+https://github.com/flare-collection/flare-redact@v1.
|
|
186
|
+
pip install "flare-redact @ git+https://github.com/flare-collection/flare-redact@v1.11.0#subdirectory=sdk/python"
|
|
181
187
|
```
|
|
182
188
|
|
|
183
189
|
```toml
|
|
184
|
-
flare-redact = { git = "https://github.com/flare-collection/flare-redact", tag = "v1.
|
|
190
|
+
flare-redact = { git = "https://github.com/flare-collection/flare-redact", tag = "v1.11.0" }
|
|
185
191
|
```
|
|
186
192
|
|
|
187
193
|
```python
|
|
@@ -206,8 +212,9 @@ Each SDK is dependency-light on purpose (Python is standard library only, Go is
|
|
|
206
212
|
standard library only, Rust is `regex` plus `serde`) because a redaction library
|
|
207
213
|
that expands your dependency tree is a security library that widened your attack
|
|
208
214
|
surface. Each also ships the integrations its ecosystem actually uses: a
|
|
209
|
-
`logging` filter and formatter
|
|
210
|
-
|
|
215
|
+
`logging` filter and formatter, OpenAI/Anthropic client wrappers and
|
|
216
|
+
[pandas, Polars and DuckDB](#clean-data-frames-and-sql-tables) helpers in
|
|
217
|
+
Python, an `slog.Handler` and an `http.RoundTripper` in Go.
|
|
211
218
|
|
|
212
219
|
Drift is the reason this is a specification and not three ports. Detection logic
|
|
213
220
|
maintained in four hand-written copies diverges within a release or two, and a
|
|
@@ -227,6 +234,32 @@ A pack that uses a construct an engine cannot execute exactly (a lookahead, a
|
|
|
227
234
|
`\d` whose meaning differs between languages, a checksum it does not implement)
|
|
228
235
|
fails to load. Failing open is how a redactor leaks.
|
|
229
236
|
|
|
237
|
+
## Fluent Bit
|
|
238
|
+
|
|
239
|
+
When logs are collected by Fluent Bit, redact them on the node with the WASM
|
|
240
|
+
filter, before they reach Loki, Elasticsearch, Datadog or S3. It is the Rust
|
|
241
|
+
engine compiled to WebAssembly, so it catches what the other engines catch.
|
|
242
|
+
|
|
243
|
+
```text
|
|
244
|
+
[FILTER]
|
|
245
|
+
Name wasm
|
|
246
|
+
Match *
|
|
247
|
+
WASM_Path /etc/fluent-bit/flare-redact-fluent-bit.wasm
|
|
248
|
+
Function_Name flare_redact
|
|
249
|
+
Accessible_Paths /etc/flare-redact
|
|
250
|
+
WASM_Stack_Size 2M
|
|
251
|
+
WASM_Heap_Size 8M
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Keep the two size lines: Fluent Bit's 8 KB defaults are too small to compile
|
|
255
|
+
the detectors, and the heap bounds the largest record. `Function_Name` picks the policy: `flare_redact` (defaults), `flare_redact_pii`
|
|
256
|
+
(phone numbers too) or `flare_redact_label` (`[REDACTED:email]`). Anything else
|
|
257
|
+
goes in a `flare-redact.json` in an accessible path, with the same option names
|
|
258
|
+
as everywhere else. An invalid file, or a record that cannot be redacted, makes
|
|
259
|
+
the filter replace the record with `{"flare_redact_error": "..."}` instead of
|
|
260
|
+
passing it on. The `.wasm` is attached to every GitHub Release;
|
|
261
|
+
[sdk/fluent-bit](../sdk/fluent-bit) has the build steps and every option.
|
|
262
|
+
|
|
230
263
|
## The sidecar gateway
|
|
231
264
|
|
|
232
265
|
Sometimes the right amount of integration is none. The gateway is a reverse
|
|
@@ -866,6 +899,57 @@ isClean(payload); // → false
|
|
|
866
899
|
summary(payload); // → { total: 3, byDetector: { email: 1, github_token: 1, sensitive_key: 1 } }
|
|
867
900
|
```
|
|
868
901
|
|
|
902
|
+
## Measure before you enforce
|
|
903
|
+
|
|
904
|
+
Turning redaction on in production is a leap of faith: nobody knows how many
|
|
905
|
+
log lines carry an email, which detector fires most, or whether a field the
|
|
906
|
+
team needs would be masked. Shadow mode counts what a policy would redact while
|
|
907
|
+
the data passes through unchanged, so the decision rests on numbers. It never
|
|
908
|
+
keeps a matched value.
|
|
909
|
+
|
|
910
|
+
```bash
|
|
911
|
+
FLARE_REDACT_MODE=shadow node --import flare-redact/register app.js
|
|
912
|
+
```
|
|
913
|
+
|
|
914
|
+
```
|
|
915
|
+
[flare-redact shadow] 2184 findings in 1940 of 52310 values (3.7%) since 2026-11-23T09:00:00.000Z
|
|
916
|
+
email 1602
|
|
917
|
+
jwt 410
|
|
918
|
+
sensitive_key 172
|
|
919
|
+
top fields:
|
|
920
|
+
user.email 1544
|
|
921
|
+
headers.authorization 410
|
|
922
|
+
```
|
|
923
|
+
|
|
924
|
+
`FLARE_REDACT_MODE` is `enforce` (the default), `shadow` (count only) or
|
|
925
|
+
`audit` (redact and count). The report goes to stderr when the process exits,
|
|
926
|
+
and every `FLARE_REDACT_REPORT_EVERY` seconds when that is set. An unknown mode
|
|
927
|
+
stops the process at startup, like an unknown preset.
|
|
928
|
+
|
|
929
|
+
In code, an audit observes any value and can feed OpenTelemetry, so the counts
|
|
930
|
+
land on the dashboards you already have:
|
|
931
|
+
|
|
932
|
+
```js
|
|
933
|
+
import { createAudit, shadowConsole } from 'flare-redact/audit';
|
|
934
|
+
|
|
935
|
+
const audit = createAudit({ preset: 'gdpr', meter: metrics.getMeter('app') });
|
|
936
|
+
audit.observe(webhookBody, 'webhook'); // returned unchanged, counted
|
|
937
|
+
audit.redact(event, 'events'); // enforced, still counted
|
|
938
|
+
shadowConsole(audit); // count console output
|
|
939
|
+
audit.report(); // { total, byDetector, byRisk, bySource, byPath }
|
|
940
|
+
```
|
|
941
|
+
|
|
942
|
+
The meter gets `flare_redact.findings` (by detector, risk and source) and
|
|
943
|
+
`flare_redact.scanned` (by source). Field paths fold array indices, so
|
|
944
|
+
`users[3].email` and `users[7].email` count as `users[].email`, and at most 500
|
|
945
|
+
distinct paths are kept. Python has the same `Audit` and a logging filter:
|
|
946
|
+
|
|
947
|
+
```python
|
|
948
|
+
from flare_redact.audit import Audit, AuditFilter
|
|
949
|
+
|
|
950
|
+
logging.getLogger().addFilter(AuditFilter(Audit(preset="gdpr"))) # enforce=True to redact too
|
|
951
|
+
```
|
|
952
|
+
|
|
869
953
|
## Guard your logger in one line
|
|
870
954
|
|
|
871
955
|
`wrapConsole` patches `console.*` so every argument is redacted on the way out,
|
|
@@ -969,6 +1053,39 @@ span. Keep personal data out of span names, as Sentry itself advises, and leave
|
|
|
969
1053
|
Same `policy` object flows into `flare-redact/llm`, `wrapConsole`, `createVault`,
|
|
970
1054
|
and `redactStream` too.
|
|
971
1055
|
|
|
1056
|
+
## Database query logs
|
|
1057
|
+
|
|
1058
|
+
Query logging is turned on to debug a slow page and left on. ORMs log the SQL
|
|
1059
|
+
and its bound parameters, and a parameter list is the hardest place to see a
|
|
1060
|
+
secret: in `["ada@example.com", "hunter2"]` the password has no shape a
|
|
1061
|
+
detector could recognise. `flare-redact/db` matches each placeholder and
|
|
1062
|
+
literal to the column it is compared with or inserted into, so a value bound to
|
|
1063
|
+
`password`, `token` or `api_key` is masked by name, and the rest is checked by
|
|
1064
|
+
the usual detectors.
|
|
1065
|
+
|
|
1066
|
+
```
|
|
1067
|
+
insert into "users" ("email", "password", "api_key") values ($1, $2, $3) -- params: ["ada@example.com","hunter2","k-7c1e0f2a9b"]
|
|
1068
|
+
insert into "users" ("email", "password", "api_key") values ($1, $2, $3) -- params: ["a***@***","***","***"]
|
|
1069
|
+
```
|
|
1070
|
+
|
|
1071
|
+
```js
|
|
1072
|
+
import { prismaQueryLogger, drizzleLogger, typeormLogger, knexQueryLogger, sequelizeLogging } from 'flare-redact/db';
|
|
1073
|
+
|
|
1074
|
+
prisma.$on('query', prismaQueryLogger(logger.info)); // log: [{ emit: 'event', level: 'query' }]
|
|
1075
|
+
drizzle(client, { logger: drizzleLogger() });
|
|
1076
|
+
new DataSource({ ...config, logger: typeormLogger(new SimpleConsoleLogger()) });
|
|
1077
|
+
knex.on('query', knexQueryLogger(logger.debug));
|
|
1078
|
+
new Sequelize(url, { logging: sequelizeLogging(logger.debug) }); // logQueryParameters too
|
|
1079
|
+
```
|
|
1080
|
+
|
|
1081
|
+
`redactQuery(sql, params)` does the same for any other client and returns
|
|
1082
|
+
`{ sql, params }`; positional (`$1`, `?`) and named (`:name`, `@name`)
|
|
1083
|
+
parameters are both understood. A column is found from `col = ?`,
|
|
1084
|
+
`col IN (?, ?)`, a qualified `"t"."col"` and `INSERT INTO t (a, b) VALUES ...`
|
|
1085
|
+
rows. Checked against Prisma 7, Drizzle on PGlite, TypeORM on sql.js, Knex on
|
|
1086
|
+
better-sqlite3 and Sequelize on SQLite: none of them leaked an email, password
|
|
1087
|
+
or API key into their logs.
|
|
1088
|
+
|
|
972
1089
|
## Streams
|
|
973
1090
|
|
|
974
1091
|
Pipe any log stream through it. Secrets may be split across chunks, and bounded
|
|
@@ -1001,6 +1118,118 @@ Alice,alice@corp.com,4242 4242 4242 4242 Alice,user_93a78c61e204@example.in
|
|
|
1001
1118
|
`redactCsv(text, opts)` is available from `flare-redact/csv` for the same thing
|
|
1002
1119
|
in code.
|
|
1003
1120
|
|
|
1121
|
+
## Clean test recordings and snapshots
|
|
1122
|
+
|
|
1123
|
+
Test suites write real traffic to disk and commit it: vcrpy and
|
|
1124
|
+
pytest-recording cassettes, Polly.js and Playwright HAR files, Jest and Vitest
|
|
1125
|
+
snapshots. A recording leaks where a log line does not: `X-Api-Key` and
|
|
1126
|
+
`Set-Cookie` headers, opaque session cookies, `?access_token=` in a URL, and
|
|
1127
|
+
bodies stored as JSON text, form text or base64. These hooks clean each of
|
|
1128
|
+
them before the file is written, and leave everything a test matches on alone.
|
|
1129
|
+
|
|
1130
|
+
**pytest-recording and vcrpy.** Requests are masked the same way when they are
|
|
1131
|
+
recorded and when they are matched, so playback still works with a token in the
|
|
1132
|
+
query string. Gzip bodies are stored decompressed so they can be read and
|
|
1133
|
+
cleaned; binary bodies are left as they are.
|
|
1134
|
+
|
|
1135
|
+
```python
|
|
1136
|
+
import pytest
|
|
1137
|
+
from flare_redact.recording import vcr_config as flare_vcr_config
|
|
1138
|
+
|
|
1139
|
+
@pytest.fixture(scope="module")
|
|
1140
|
+
def vcr_config():
|
|
1141
|
+
return flare_vcr_config() # or vcr.VCR(**flare_vcr_config())
|
|
1142
|
+
```
|
|
1143
|
+
|
|
1144
|
+
**Polly.js.** Polly matches a replayed request by a hash it took of the live
|
|
1145
|
+
request, so the recording on disk can be masked without breaking replay.
|
|
1146
|
+
|
|
1147
|
+
```js
|
|
1148
|
+
import { pollyBeforePersist } from 'flare-redact/recording';
|
|
1149
|
+
|
|
1150
|
+
polly.server.any().on('beforePersist', pollyBeforePersist());
|
|
1151
|
+
```
|
|
1152
|
+
|
|
1153
|
+
**Any HAR file** (devtools export, Playwright `recordHar`): clean it in place
|
|
1154
|
+
before it is committed or attached to a ticket. Headers, cookies, query
|
|
1155
|
+
parameters and bodies are masked; timings, status codes and every other field
|
|
1156
|
+
stay as they were, and `Content-Length` and `size` are updated.
|
|
1157
|
+
|
|
1158
|
+
```bash
|
|
1159
|
+
flare-redact --har < session.har > session.safe.har
|
|
1160
|
+
python -m flare_redact --har < session.har > session.safe.har
|
|
1161
|
+
```
|
|
1162
|
+
|
|
1163
|
+
`redactHar(har, opts)` and `redactHarEntry(entry, opts)` do the same in code;
|
|
1164
|
+
the JavaScript and Python engines give the same output for the same file.
|
|
1165
|
+
|
|
1166
|
+
**Vitest and Jest snapshots.** The serializer takes over only values that need
|
|
1167
|
+
masking and hands the masked copy back to the usual printer, so clean snapshots
|
|
1168
|
+
do not change.
|
|
1169
|
+
|
|
1170
|
+
```js
|
|
1171
|
+
// vitest.config.js
|
|
1172
|
+
export default { test: { snapshotSerializers: ['flare-redact/snapshot'] } };
|
|
1173
|
+
```
|
|
1174
|
+
|
|
1175
|
+
Jest cannot `require` an ES module before Node 24.9, so with Jest register it
|
|
1176
|
+
from a setup file (`setupFilesAfterEnv: ['<rootDir>/jest.setup.mjs']`, run with
|
|
1177
|
+
`NODE_OPTIONS=--experimental-vm-modules`):
|
|
1178
|
+
|
|
1179
|
+
```js
|
|
1180
|
+
// jest.setup.mjs
|
|
1181
|
+
import { expect } from '@jest/globals';
|
|
1182
|
+
import serializer from 'flare-redact/snapshot';
|
|
1183
|
+
|
|
1184
|
+
expect.addSnapshotSerializer(serializer);
|
|
1185
|
+
```
|
|
1186
|
+
|
|
1187
|
+
`createSnapshotSerializer(opts)` builds one with your own options, for example
|
|
1188
|
+
`{ mode: 'label' }` for `[REDACTED:email]` in place of a mask.
|
|
1189
|
+
|
|
1190
|
+
## Clean data frames and SQL tables
|
|
1191
|
+
|
|
1192
|
+
Data on its way to a notebook, a parquet file, a feature store or a model often
|
|
1193
|
+
passes through pandas, Polars or DuckDB. The Python SDK cleans text columns
|
|
1194
|
+
where the data already is. None of the three libraries is a dependency; each is
|
|
1195
|
+
imported only when you use it.
|
|
1196
|
+
|
|
1197
|
+
```python
|
|
1198
|
+
import flare_redact.frames as frames
|
|
1199
|
+
|
|
1200
|
+
safe = frames.redact_frame(df) # pandas or Polars, lazy frames too
|
|
1201
|
+
safe = frames.redact_frame(df, columns=["note"], mode="label")
|
|
1202
|
+
frames.scan_frame(df)
|
|
1203
|
+
# {'total': 5, 'columns': {'note': {'rows': 2, 'by_detector': {'email': 1, 'github_token': 1}},
|
|
1204
|
+
# 'password': {'rows': 3, 'by_detector': {'sensitive_key': 3}}}}
|
|
1205
|
+
```
|
|
1206
|
+
|
|
1207
|
+
`frames.register()` adds a `.flare` namespace to pandas (`DataFrame`, `Series`)
|
|
1208
|
+
and Polars (`DataFrame`, `LazyFrame`, `Series`, `Expr`):
|
|
1209
|
+
|
|
1210
|
+
```python
|
|
1211
|
+
frames.register()
|
|
1212
|
+
df.flare.redact()
|
|
1213
|
+
df.with_columns(pl.col("note").flare.redact()) # inside a Polars query
|
|
1214
|
+
```
|
|
1215
|
+
|
|
1216
|
+
In DuckDB the same rules are SQL functions:
|
|
1217
|
+
|
|
1218
|
+
```python
|
|
1219
|
+
frames.register_duckdb(con)
|
|
1220
|
+
con.sql("""
|
|
1221
|
+
SELECT redact(note), redact_field('password', pw), redact_is_clean(note)
|
|
1222
|
+
FROM tickets
|
|
1223
|
+
""")
|
|
1224
|
+
```
|
|
1225
|
+
|
|
1226
|
+
A column is treated like a field, so a column named `password` or `api_key` is
|
|
1227
|
+
masked whole, as a dictionary key with that name would be. Each distinct value
|
|
1228
|
+
is redacted once (1M pandas or Polars rows with 2,000 distinct values take
|
|
1229
|
+
under 0.2 s), and with `mode="hash"`, `"pseudonym"` or `"surrogate"` the same
|
|
1230
|
+
value maps the same way everywhere, so joins keep working. `scan_frame` returns
|
|
1231
|
+
counts only, never values, so its report is safe to log.
|
|
1232
|
+
|
|
1004
1233
|
## Guard what leaves your app
|
|
1005
1234
|
|
|
1006
1235
|
Stop PII from reaching an analytics, telemetry, or webhook endpoint: wrap
|
|
@@ -1014,6 +1243,52 @@ const fetch = wrapFetch(globalThis.fetch, { hosts: ['api.segment.io', 'telemetry
|
|
|
1014
1243
|
// bodies sent to those hosts are redacted; everything else is left alone
|
|
1015
1244
|
```
|
|
1016
1245
|
|
|
1246
|
+
## Mask session replays
|
|
1247
|
+
|
|
1248
|
+
Session replay tools record what users see and type. Their built-in choices are
|
|
1249
|
+
to mask every character, which makes replays hard to use, or to mask only the
|
|
1250
|
+
elements a CSS selector names, which misses the email typed into a search box
|
|
1251
|
+
and the API key pasted into a support form. `flare-redact/replay` masks what is
|
|
1252
|
+
sensitive and keeps the rest readable.
|
|
1253
|
+
|
|
1254
|
+
```js
|
|
1255
|
+
import { replayMaskFn, rrwebMasking } from 'flare-redact/replay';
|
|
1256
|
+
|
|
1257
|
+
// rrweb
|
|
1258
|
+
rrweb.record({ emit, ...rrwebMasking() });
|
|
1259
|
+
|
|
1260
|
+
// Sentry Session Replay: maskAllText and maskAllInputs stay on (the default)
|
|
1261
|
+
Sentry.replayIntegration({ maskFn: replayMaskFn() });
|
|
1262
|
+
|
|
1263
|
+
// PostHog
|
|
1264
|
+
posthog.init(key, { session_recording: rrwebMasking() });
|
|
1265
|
+
```
|
|
1266
|
+
|
|
1267
|
+
```
|
|
1268
|
+
Please call me at +44 20 7946 0958 or mail ada@example.com
|
|
1269
|
+
Please call me at *** ** **** **** or mail ***************
|
|
1270
|
+
```
|
|
1271
|
+
|
|
1272
|
+
- Each masked character becomes `*` and spaces are kept, as rrweb's own masking
|
|
1273
|
+
does, so the replayed layout does not shift. `preserveLength: false` gives
|
|
1274
|
+
the usual masks (`a***@***`) or the chosen `mode` instead.
|
|
1275
|
+
- A form field is masked whole when it is a password field, when its
|
|
1276
|
+
`autocomplete` names a password, one-time code or card number, or when its
|
|
1277
|
+
`name` or `id` is a credential name such as `password` or `api_key`. Anything
|
|
1278
|
+
else typed is masked where a detector finds something, and that holds for
|
|
1279
|
+
later keystrokes too, not only the first snapshot.
|
|
1280
|
+
- Without detector options the `pii` group is on, so phone numbers count. Free
|
|
1281
|
+
text names and addresses are not caught by default; add
|
|
1282
|
+
`enable: ['pii', 'entities']`, or keep a selector-based mask on the parts of
|
|
1283
|
+
the page that show them.
|
|
1284
|
+
- It runs in the browser with no Node built-ins: about 57 kB gzipped with every
|
|
1285
|
+
detector bundled. Repeated texts are cached.
|
|
1286
|
+
|
|
1287
|
+
Checked with rrweb 2.2, which Sentry and PostHog both record with. This makes
|
|
1288
|
+
replays readable, so it only shows text the detectors consider clean; keep
|
|
1289
|
+
`block` and `mask` selectors on screens that show sensitive data the detectors
|
|
1290
|
+
cannot recognise, such as medical notes.
|
|
1291
|
+
|
|
1017
1292
|
## Fail a build when a secret sneaks in
|
|
1018
1293
|
|
|
1019
1294
|
Stop it before the commit exists:
|
|
@@ -1035,7 +1310,7 @@ not, as long as Node 20 or newer is on the PATH:
|
|
|
1035
1310
|
```yaml
|
|
1036
1311
|
repos:
|
|
1037
1312
|
- repo: https://github.com/flare-collection/flare-redact
|
|
1038
|
-
rev: v1.
|
|
1313
|
+
rev: v1.11.0
|
|
1039
1314
|
hooks:
|
|
1040
1315
|
- id: flare-redact # only the lines being added, like --staged
|
|
1041
1316
|
```
|
|
@@ -1100,7 +1375,7 @@ reports never echo the matched secret value:
|
|
|
1100
1375
|
with:
|
|
1101
1376
|
node-version: 24
|
|
1102
1377
|
- name: Scan project text files
|
|
1103
|
-
run: npx --yes --package flare-redact@1.
|
|
1378
|
+
run: npx --yes --package flare-redact@1.11.0 flare-redact --scan . --exclude package-lock.json
|
|
1104
1379
|
```
|
|
1105
1380
|
|
|
1106
1381
|
The scan runs on the GitHub runner, reports safe file and source locations, and
|
|
@@ -1326,8 +1601,17 @@ redactHttp(req, opts?) // 'flare-redact/http' → safe-to-log request snaps
|
|
|
1326
1601
|
redactUrl(url, opts?) // 'flare-redact/http' → sanitized absolute/relative URL
|
|
1327
1602
|
httpRedactor(opts?) // 'flare-redact/http' → Express/Connect middleware
|
|
1328
1603
|
redactCsv(text, opts?) // 'flare-redact/csv' → anonymize a CSV dataset
|
|
1604
|
+
redactHar(har, opts?) // 'flare-redact/recording' → clean a HAR file (also redactHarEntry)
|
|
1605
|
+
pollyBeforePersist(opts?) // 'flare-redact/recording' → Polly.js beforePersist handler
|
|
1606
|
+
createSnapshotSerializer(opts?) // 'flare-redact/snapshot' → Vitest/Jest snapshot serializer
|
|
1607
|
+
redactQuery(sql, params?, opts?) // 'flare-redact/db' → SQL and bound parameters, masked by column
|
|
1608
|
+
// also from 'flare-redact/db': prismaQueryLogger, drizzleLogger, typeormLogger, knexQueryLogger, sequelizeLogging
|
|
1329
1609
|
wrapFetch(fetch, opts?) // 'flare-redact/fetch' → redact egress to named hosts
|
|
1610
|
+
replayMaskFn(opts?) // 'flare-redact/replay' → rrweb maskTextFn/maskInputFn, Sentry maskFn
|
|
1611
|
+
rrwebMasking(opts?) // 'flare-redact/replay' → options for rrweb record() or PostHog session_recording
|
|
1330
1612
|
createRedactionMiddleware(opts?) // 'flare-redact/middleware' → any function/handler
|
|
1613
|
+
createAudit(opts?) // 'flare-redact/audit' → shadow mode: count findings, optional OpenTelemetry meter
|
|
1614
|
+
shadowConsole(audit, console?, { enforce? }) // 'flare-redact/audit' → count console output
|
|
1331
1615
|
|
|
1332
1616
|
// from 'flare-redact/ml'
|
|
1333
1617
|
secretProbability(value, context?): number // learned secret-vs-look-alike score, 0..1
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flare-redact",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "Keep secrets and PII out of logs, Sentry, LLM prompts and commits. Reads values, not field names. Zero dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -61,6 +61,26 @@
|
|
|
61
61
|
"types": "./dist/csv.d.ts",
|
|
62
62
|
"default": "./dist/csv.js"
|
|
63
63
|
},
|
|
64
|
+
"./recording": {
|
|
65
|
+
"types": "./dist/recording.d.ts",
|
|
66
|
+
"default": "./dist/recording.js"
|
|
67
|
+
},
|
|
68
|
+
"./snapshot": {
|
|
69
|
+
"types": "./dist/snapshot.d.ts",
|
|
70
|
+
"default": "./dist/snapshot.js"
|
|
71
|
+
},
|
|
72
|
+
"./replay": {
|
|
73
|
+
"types": "./dist/replay.d.ts",
|
|
74
|
+
"default": "./dist/replay.js"
|
|
75
|
+
},
|
|
76
|
+
"./audit": {
|
|
77
|
+
"types": "./dist/audit.d.ts",
|
|
78
|
+
"default": "./dist/audit.js"
|
|
79
|
+
},
|
|
80
|
+
"./db": {
|
|
81
|
+
"types": "./dist/db.d.ts",
|
|
82
|
+
"default": "./dist/db.js"
|
|
83
|
+
},
|
|
64
84
|
"./fetch": {
|
|
65
85
|
"types": "./dist/fetch.d.ts",
|
|
66
86
|
"default": "./dist/fetch.js"
|
package/spec/detectors.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "./detectors.schema.json",
|
|
3
3
|
"spec": "FRS-1",
|
|
4
4
|
"id": "flare-redact/core",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.11.0",
|
|
6
6
|
"title": "flare-redact core detector pack",
|
|
7
7
|
"description": "The portable profile of the flare-redact detector set. Every pattern is written in the FRS-1 regular-expression subset so the JavaScript, Python, Go and Rust engines compile it to the same automaton and produce byte-identical output. See spec/SPEC.md.",
|
|
8
8
|
"license": "MIT",
|