Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
40f904a
fix(redaction): MCP gap rules, part 1 (DRO-4114)
Cyro292 Dec 2, 2026
57ce067
fix(redaction): MCP gap rules, part 2 (DRO-4114)
Cyro292 Dec 2, 2026
0ba389e
fix(redaction): MCP gap rules, part 4 (DRO-4114)
Cyro292 Dec 2, 2026
935129d
fix(redaction): MCP gap rules, part 6 (DRO-4114)
Cyro292 Dec 2, 2026
aead5ab
fix(redaction): MCP gap rules, part 7 (DRO-4114)
Cyro292 Dec 2, 2026
72b707c
fix(redaction): MCP gap rules, part 8 (DRO-4114)
Cyro292 Dec 2, 2026
e76e1f5
fix(redaction): MCP gap rules, part 9 (DRO-4114)
Cyro292 Dec 2, 2026
eaa2fad
fix(redaction): MCP gap rules, part 12 (DRO-4114)
Cyro292 Dec 2, 2026
67f7a23
fix(redaction): MCP gap rules, part 13 (DRO-4114)
Cyro292 Dec 2, 2026
5c7d94e
fix(redaction): MCP gap rules, go/spec/vectors/pii.json (DRO-4114)
Cyro292 Dec 2, 2026
548ce4c
fix(redaction): MCP gap rules, go/spec_hash_gen.go (DRO-4114)
Cyro292 Dec 2, 2026
4d77042
fix(redaction): MCP gap rules, go/units.go (DRO-4114)
Cyro292 Dec 2, 2026
978f935
fix(redaction): MCP gap rules, go/walk.go (DRO-4114)
Cyro292 Dec 2, 2026
8193c0c
fix(redaction): MCP gap rules, python/NOTICE (DRO-4114)
Cyro292 Dec 2, 2026
875de1c
fix(redaction): MCP gap rules, python/README.md (DRO-4114)
Cyro292 Dec 2, 2026
5d892a2
fix(redaction): MCP gap rules, python/src/droidrun_redaction/_detect.…
Cyro292 Dec 2, 2026
6179173
fix(redaction): MCP gap rules, python/src/droidrun_redaction/_keys.py…
Cyro292 Dec 2, 2026
fd40360
fix(redaction): MCP gap rules, spec/algorithms.json (DRO-4114)
Cyro292 Dec 2, 2026
5b37158
fix(redaction): MCP gap rules, spec/keys.json (DRO-4114)
Cyro292 Dec 2, 2026
e6ed042
test(redaction): 100 no-redaction guards; skip device IDs and promo/v…
Cyro292 Dec 2, 2026
1af9ddd
test(redaction): no-redaction guards, part 2 (DRO-4114)
Cyro292 Dec 2, 2026
5203039
test(redaction): no-redaction guards, part 3 (DRO-4114)
Cyro292 Dec 2, 2026
2c176b8
test(redaction): no-redaction guards, part 4 (DRO-4114)
Cyro292 Dec 2, 2026
b3ed4b2
test(redaction): no-redaction guards, part 5 (DRO-4114)
Cyro292 Dec 2, 2026
b0fba6c
test(redaction): no-redaction guards, part 6 (DRO-4114)
Cyro292 Dec 2, 2026
7261fed
test(redaction): no-redaction guards, part 7 (DRO-4114)
Cyro292 Dec 2, 2026
43dfea6
test(redaction): no-redaction guards, part 8 (DRO-4114)
Cyro292 Dec 2, 2026
e20e71a
test(redaction): no-redaction guards, part 9 (DRO-4114)
Cyro292 Dec 2, 2026
68cd334
test(redaction): golden replay for mnemonic windows; split fake token…
Cyro292 Dec 2, 2026
e648415
test(redaction): attack corpus for MCP gap rules; unicode-escape fixt…
Cyro292 Dec 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## Unreleased

- Opt-in `pii` adds Luhn-checked cards and mod-97 IBANs. Overlapping valid IBANs are masked together; IBAN-shaped ranges no longer produce partial phone or card hits.
- Opt-in `phone` covers `00`-prefixed international numbers and German national formats. `ip` covers IPv6 zone IDs such as `fe80::1%en0`.
- Opt-in `otp` recognizes codes before or after their context, including multilingual labels, and excludes date-shaped values. The bare-code rule leaves `Invoice code: 482913`, `Order code: 482913`, and `HTTP error: Code: 482913` visible. The addressed-code rule still masks `HTTP error: Your code: 482913`.
- Localized password keys use NFC and case mapping. The standard-tier `mnemonic` rule covers keyed values, BIP39 runs, and checksum-valid windows; it also applies in `compat` without `pii`.
- The BIP39 wordlist is noted in `THIRD_PARTY_NOTICES.md`. Limits are documented in the README and SPEC §15.

## 0.4.1 (2026-11-26)

- Strict text redaction covers scheme-prefixed assignments and session IDs.
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ Secrets are replaced with a placeholder of the form `[REDACTED:<rule>]`, for exa
- Tokens and API keys of common providers (the full tier): AWS, GitHub, GitLab, Slack, Stripe, OpenAI, Anthropic, npm, 1Password and more. The list is in [`spec/INVENTORY.md`](spec/INVENTORY.md).
- Private keys (PEM blocks), credential URIs and database connection strings.
- JWTs and `Authorization`, `Bearer`, `Basic` and `Token` header values.
- `password=`-style pairs in text, and the values of secret-named JSON keys (`password`, `api_key`, `x-auth-token`, `clientSecret`, …). Counts such as `max_tokens` stay.
- With the opt-in `pii` option: email addresses, phone numbers, IP addresses and OTP codes.
- `password=`-style pairs in text, including localized keys such as `passwort`, `kennwort` and `contraseña`, and the values of secret-named JSON keys (`password`, `api_key`, `x-auth-token`, `clientSecret`, …). Counts such as `max_tokens` stay.
- Seed phrases: keyed `mnemonic` and `seed phrase` values, `seed` only when followed by leading BIP39 words, and BIP39 runs or checksum-valid windows.
- With the opt-in `pii` option: email addresses, card numbers (Luhn), IBANs (mod-97), phone numbers including `00`-prefixed and German national forms, IP addresses including IPv6 zone IDs, and OTP codes before or after their code label.

## Install

Expand Down Expand Up @@ -132,18 +133,19 @@ out, _, err := redaction.RedactJSON([]byte(`{"user":"ann","api_key":"k-123","max

| Option | What it does | Spec |
|---|---|---|
| `compat` mode | Output of release 0.2.0. Default in TypeScript. The full tier falls back to the standard rules if it fails. | [§9](spec/SPEC.md#9-tiers-and-modes) |
| `compat` mode | Keeps legacy failure and limit behavior; this release also masks seed phrases. Default in TypeScript. The full tier falls back to the standard rules if it fails. | [§9](spec/SPEC.md#9-tiers-and-modes) |
| `strict` mode | Never returns text that was not scanned; anything it cannot scan becomes a placeholder. Default in Python and Go, an option in TypeScript. | [§9](spec/SPEC.md#9-tiers-and-modes) |
| Standard tier (sync) | The core rules, for logs, spans and hot paths. | [§4](spec/SPEC.md#4-detection) |
| Full tier (async in TypeScript) | The standard rules plus the ported secretlint preset: provider tokens, private keys, connection strings. | [§4.11–4.17](spec/SPEC.md#411-token-full-tier) |
| `pii` | Off by default. Also redacts emails, phone numbers, IP addresses and OTP codes. | [§9.5](spec/SPEC.md#95-the-pii-option) |
| `pii` | Off by default. This release also redacts cards, IBANs, 00-prefixed and German national phones, IPv6 zone IDs, and OTP codes on either side of code labels, alongside emails, phones and IP addresses. | [§9.5](spec/SPEC.md#95-the-pii-option) |
| Size limits | Text, node and depth limits. Input over a limit becomes `[REDACTED:size-limit]`; the full-tier rules scan the first 2,000,000 characters. | [§9.1](spec/SPEC.md#91-text-standard-tier) |

## Limits

- Detection is based on patterns and key names. It is best effort and not a data-loss-prevention guarantee: a secret in a format no rule knows, or in prose, can be missed.
- Not a PII class today: IMEI, GPS coordinates, postal addresses, dates of birth and national IDs. Names are not detected either.
- Input over a size limit is redacted with `[REDACTED:size-limit]` instead of being passed on unscanned. The limits and their defaults are in each package README.
- Known misses are listed in [TypeScript limits](ts/README.md#limits) and [SPEC §15](spec/SPEC.md#15-known-portability-risks).
- Report a miss privately, as described in [`SECURITY.md`](SECURITY.md).

## How it works
Expand Down
30 changes: 30 additions & 0 deletions THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,33 @@ not be used in advertising or otherwise to promote the sale, use or other
dealings in these Data Files or Software without prior written
authorization of the copyright holder.
```

## BIP39 English wordlist (MIT)

`mnemonic.words` in `spec/algorithms.json` reproduces the English BIP39 wordlist from
[python-mnemonic v0.21](https://github.com/trezor/python-mnemonic/blob/v0.21/src/mnemonic/wordlist/english.txt).
The [upstream MIT license](https://github.com/trezor/python-mnemonic/blob/v0.21/LICENSE) follows.

```
The MIT License (MIT)

Copyright (c) 2013-2016 Pavol Rusnak

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
30 changes: 30 additions & 0 deletions go/NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,33 @@ not be used in advertising or otherwise to promote the sale, use or other
dealings in these Data Files or Software without prior written
authorization of the copyright holder.
```

## BIP39 English wordlist (MIT)

`mnemonic.words` in `spec/algorithms.json` reproduces the English BIP39 wordlist from
[python-mnemonic v0.21](https://github.com/trezor/python-mnemonic/blob/v0.21/src/mnemonic/wordlist/english.txt).
The [upstream MIT license](https://github.com/trezor/python-mnemonic/blob/v0.21/LICENSE) follows.

```
The MIT License (MIT)

Copyright (c) 2013-2016 Pavol Rusnak

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
14 changes: 8 additions & 6 deletions go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ replaced; `example_test.go` runs this.
- `Compat` reproduces the TypeScript package's default mode (a skip-key value is kept as it is, an
over-long key is left as it is). In the full tier it has **no length, depth or node limit**
(SPEC 9.4, as in the TypeScript package: `MaxChars`, `MaxDepth` and `MaxNodes` are not used), and a
failing scanner falls back to the standard rules, then to `[REDACTED:error]`. Use Compat only to
match old output.
failing scanner falls back to the standard rules, then to `[REDACTED:error]`. Compat preserves
legacy failure and limit behavior, not identical output: for example, mnemonic detection now runs without `PII`.

In `Strict` the same key names that decide JSON keys also decide **text pairs** (`key: value`,
`key=value`, `key => "value"`, `key := "value"`, also inside escaped JSON): a value under a key with
Expand All @@ -138,11 +138,13 @@ strings and keys:
| `email` | `person@example.com`, `A.B+tag@Example.CO.uk` | `react@18.2.0`, `icon@2x.png`, `user@localhost` |
| `phone` | `+44 20 7946 0958`, `(415) 555-0123`, `415-555-0123`, `020 7946 0958`, `01 99 00 12 34` | `Request ID 1234567890`, `2026-11-19 10:00:59`, `v0.3.0` |
| `ip` | IPv4 `192.0.2.123`, IPv6 `2001:db8::1`, `[fdab::cafe]:8080` (the address only, a port stays) | `version 1.2.3.4`, `android 14.0.0.1`, `999.1.1.1`, `std::vector` |
| `otp` | the digits after a code noun (`Your verification code is 482913`, `OTP code: 482913`) | `error code 5000`, `exit code 1370`, `response code 200000`, `port 8080` |
| `otp` | codes before or after a recognized label (`482913 is your verification code`, `OTP code: 482913`) | `error code 5000`, `Invoice code: 482913`, `HTTP error: Code: 482913` |
| `card` | `4111 1111 1111 1111` (13–19 digits, Luhn-valid) | Luhn-invalid numbers |
| `iban` | `DE89 3704 0044 0532 0130 00` (known country length and valid checksum) | Same shape with a bad checksum |

The placeholders are `[REDACTED:email]`, `[REDACTED:phone]`, `[REDACTED:ip]` and `[REDACTED:otp]`; a text
of any length is scanned. Names, postal addresses, IDN emails, URL-encoded values and prose secrets such
as `password hunter2` are not detected; the rules are in SPEC sections 4.19 to 4.22 and 15.
Each placeholder uses the rule ID, for example `[REDACTED:iban]`. With the option a text of any length is scanned.
See [SPEC](../spec/SPEC.md) §§4.19–4.24 and §15 for rules and limits. Mnemonic detection is part of the standard tier
in both modes, including `Compat` without `PII`.

## Limits

Expand Down
23 changes: 14 additions & 9 deletions go/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package redaction
import (
"encoding/json"
"reflect"
"strings"
)

const fieldSeedPrefixBytes = 256

// KeyVerdict says what the key name makes of the values below it: VerdictNone, VerdictString
// (a string is replaced, a number is kept: `tokens`, `max_tokens`) or VerdictAny (a string and a
// number are replaced: `password`, `pin`). It is the verdict RedactJSON uses for an object key.
Expand All @@ -14,28 +17,28 @@ func KeyVerdict(key string) Verdict {

// RedactField redacts the value of one attribute (a log field, a span attribute) by its key, the
// way RedactJSON treats an object member: a string under a secret-named key is replaced by
// `[REDACTED:key-context]`, any other string is scanned like RedactText with the default
// `[REDACTED:key-context]` (including seed strings that start with three BIP39 words).
// Any other string is scanned like RedactText with the default
// options, and a number is replaced only under a key whose verdict is VerdictAny, so counts such
// as `max_tokens` stay. Every other type (bool, nil, a struct, an error) is returned as it is:
// turn it into a string first, or marshal it and use RedactJSON. The returned value has the type
// of the input, except that a replaced number is the placeholder string.
func RedactField(key string, value any) any {
verdict := KeyVerdict(key)
switch typed := value.(type) {
case nil:
return nil
case string:
return redactFieldText(verdict, typed)
return redactFieldText(key, typed)
case json.Number:
return redactFieldNumber(verdict, value)
return redactFieldNumber(KeyVerdict(key), value)
}
switch reflect.ValueOf(value).Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr,
reflect.Float32, reflect.Float64:
return redactFieldNumber(verdict, value)
return redactFieldNumber(KeyVerdict(key), value)
case reflect.String:
return redactFieldText(verdict, reflect.ValueOf(value).String())
return redactFieldText(key, reflect.ValueOf(value).String())
}
return value
}
Expand All @@ -47,12 +50,14 @@ func redactFieldNumber(verdict Verdict, value any) any {
return theEngine.placeholders.read(theEngine.spec.algorithms.RuleIDs.KeyContext)
}

func redactFieldText(verdict Verdict, text string) string {
if verdict == VerdictNone {
func redactFieldText(key, text string) string {
if exceedsChars(text, theEngine.limits(Options{}).maxChars) ||
theEngine.stringKeyVerdict(decodeUTF8(key), len(text), fieldSeedPrefixBytes, func(at int) uint16 { return uint16(text[at]) }) == VerdictNone {
out, _ := RedactText(text, Options{})
return out
}
if text == "" || theEngine.placeholders.isWhole(decodeUTF8(text)) {
p := theEngine.placeholders
if text == "" || (strings.HasPrefix(text, strings.TrimSuffix(p.open, ":")) && p.isWhole(decodeUTF8(text))) {
return text
}
return theEngine.placeholders.read(theEngine.spec.algorithms.RuleIDs.KeyContext)
Expand Down
46 changes: 45 additions & 1 deletion go/field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package redaction

import (
"encoding/json"
"runtime"
"strings"
"testing"
)

Expand Down Expand Up @@ -59,6 +61,11 @@ func TestRedactField(t *testing.T) {
{"json.Number elsewhere", "latency_ms", json.Number("42"), json.Number("42")},
{"number elsewhere", "latency_ms", 42, 42},
{"named string type", "password", nameString("hunter2xx"), "[REDACTED:key-context]"},
{"named seed string", "SEED", nameString("abandon ability able about"), "[REDACTED:key-context]"},
{"seed with whitespace", "seed", "\tAbandon ability\table.", "[REDACTED:key-context]"},
{"seed with partial third word", "seed", "abandon ability able_suffix", "abandon ability able_suffix"},
{"ordinary seed stays", "seed", "abandon ability not-a-word", "abandon ability not-a-word"},
{"numeric seed stays", "seed", 42, 42},
{"bool stays", "password", true, true},
{"nil stays", "password", nil, nil},
{"struct stays", "password", attribute{"x"}, attribute{"x"}},
Expand All @@ -72,13 +79,50 @@ func TestRedactField(t *testing.T) {
}
}

func TestRedactFieldRejectsOversizedNoteBeforeAllocatingUnits(t *testing.T) {
maxChars := theEngine.limits(Options{}).maxChars
text := strings.Repeat("a", 3*maxChars+1)
var before, after runtime.MemStats
runtime.ReadMemStats(&before)
got := RedactField("note", text)
runtime.ReadMemStats(&after)
if got != "[REDACTED:size-limit]" {
t.Fatal("oversized field did not return the size-limit marker")
}
if allocated := after.TotalAlloc - before.TotalAlloc; allocated >= uint64(len(text)) {
t.Fatalf("oversized field allocated %d bytes; want less than the %d-byte input", allocated, len(text))
}
}

func TestRedactFieldRejectsOversizedSeed(t *testing.T) {
spaces := strings.Repeat(" ", 3*theEngine.limits(Options{}).maxChars+1)
for _, tc := range []struct{ name, value string }{
{"whitespace only", spaces},
{"valid prefix", "abandon ability able " + spaces},
} {
t.Run(tc.name, func(t *testing.T) {
if got := RedactField("seed", tc.value); got != "[REDACTED:size-limit]" {
t.Fatal("oversized seed did not return the size-limit marker")
}
})
}
}

func TestRedactFieldBoundsSeedPrefixProbe(t *testing.T) {
value := strings.Repeat(" ", 4096) + "abandon ability able"
if got := RedactField("seed", value); got != value {
t.Fatal("seed was classified using words beyond the prefix probe")
}
}

func TestRedactFieldAgreesWithRedactJSON(t *testing.T) {
members := map[string]string{
"password": `"hunter2xx"`, "max_tokens": `100`, "pin": `1234`,
"note": `"password=` + secretValue + `"`,
"note": `"password=` + secretValue + `"`, "seed": `"abandon ability able about"`,
}
values := map[string]any{
"password": "hunter2xx", "max_tokens": 100, "pin": 1234, "note": "password=" + secretValue,
"seed": "abandon ability able about",
}
for key, literal := range members {
out, _, err := RedactJSON([]byte(`{"`+key+`":`+literal+`}`), Options{})
Expand Down
2 changes: 1 addition & 1 deletion go/fulltier.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (e *engine) detectFull(t *text, opts detectOpts) []hit {
if t.length() < e.scanFloor(opts) {
return nil
}
return mergeHits(append(e.detectFullWindows(t), e.detect(t, opts)...))
return e.detect(t, opts, e.detectFullWindows(t)...)
}

// tryDetect runs a detector and reports whether it finished; a panic is a failure.
Expand Down
1 change: 0 additions & 1 deletion go/fulltier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ func brokenEngine(standardFails bool) *engine {
if standardFails {
failing := []pipelineEntry{{id: "broken", scanner: panicScanner{}}}
broken.pipeline, broken.strict = failing, failing
broken.compatPII, broken.strictPII = failing, failing
}
return &broken
}
Expand Down
Loading
Loading