redac---n 0.0.0-stage → 0.0.2
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/LICENSE +21 -0
- package/README.md +323 -2
- package/THIRD_PARTY_NOTICES.md +59 -0
- package/dist/aho.d.ts +25 -0
- package/dist/aho.js +116 -0
- package/dist/base64.d.ts +10 -0
- package/dist/base64.js +29 -0
- package/dist/bip39-data.d.ts +2 -0
- package/dist/bip39-data.js +2 -0
- package/dist/cache.d.ts +14 -0
- package/dist/cache.js +40 -0
- package/dist/calls.d.ts +64 -0
- package/dist/calls.js +269 -0
- package/dist/charlm-data.d.ts +2 -0
- package/dist/charlm-data.js +3 -0
- package/dist/charlm.d.ts +7 -0
- package/dist/charlm.js +65 -0
- package/dist/checksums.d.ts +10 -0
- package/dist/checksums.js +98 -0
- package/dist/commands.d.ts +72 -0
- package/dist/commands.js +787 -0
- package/dist/context.d.ts +98 -0
- package/dist/context.js +469 -0
- package/dist/encoded.d.ts +11 -0
- package/dist/encoded.js +336 -0
- package/dist/environment.d.ts +10 -0
- package/dist/environment.js +62 -0
- package/dist/formats-data.d.ts +2 -0
- package/dist/formats-data.js +405 -0
- package/dist/formats.d.ts +5 -0
- package/dist/formats.js +470 -0
- package/dist/hmac.d.ts +3 -0
- package/dist/hmac.js +87 -0
- package/dist/index.d.ts +101 -0
- package/dist/index.js +488 -0
- package/dist/json.d.ts +82 -0
- package/dist/json.js +392 -0
- package/dist/known.d.ts +34 -0
- package/dist/known.js +340 -0
- package/dist/lines.d.ts +28 -0
- package/dist/lines.js +69 -0
- package/dist/lookup.d.ts +5 -0
- package/dist/lookup.js +7 -0
- package/dist/model-data.d.ts +3 -0
- package/dist/model-data.js +4 -0
- package/dist/model.d.ts +2 -0
- package/dist/model.js +19 -0
- package/dist/named.d.ts +20 -0
- package/dist/named.js +3257 -0
- package/dist/names.d.ts +106 -0
- package/dist/names.js +1517 -0
- package/dist/normalize.d.ts +25 -0
- package/dist/normalize.js +529 -0
- package/dist/pem.d.ts +32 -0
- package/dist/pem.js +269 -0
- package/dist/policy.d.ts +3 -0
- package/dist/policy.js +470 -0
- package/dist/public.d.ts +44 -0
- package/dist/public.js +362 -0
- package/dist/publickeys.d.ts +41 -0
- package/dist/publickeys.js +232 -0
- package/dist/random.d.ts +29 -0
- package/dist/random.js +165 -0
- package/dist/repeats.d.ts +21 -0
- package/dist/repeats.js +80 -0
- package/dist/rules.d.ts +42 -0
- package/dist/rules.js +58 -0
- package/dist/runs.d.ts +10 -0
- package/dist/runs.js +36 -0
- package/dist/secretfile.d.ts +52 -0
- package/dist/secretfile.js +722 -0
- package/dist/shell.d.ts +127 -0
- package/dist/shell.js +703 -0
- package/dist/spans.d.ts +61 -0
- package/dist/spans.js +287 -0
- package/dist/sql.d.ts +20 -0
- package/dist/sql.js +66 -0
- package/dist/stream.d.ts +46 -0
- package/dist/stream.js +150 -0
- package/dist/structure.d.ts +24 -0
- package/dist/structure.js +1625 -0
- package/dist/syntax.d.ts +156 -0
- package/dist/syntax.js +446 -0
- package/dist/transcript.d.ts +30 -0
- package/dist/transcript.js +713 -0
- package/dist/types.d.ts +81 -0
- package/dist/types.js +1 -0
- package/dist/unnamed.d.ts +59 -0
- package/dist/unnamed.js +939 -0
- package/dist/urls.d.ts +70 -0
- package/dist/urls.js +303 -0
- package/dist/values.d.ts +178 -0
- package/dist/values.js +1621 -0
- package/dist/yaml.d.ts +40 -0
- package/dist/yaml.js +174 -0
- package/docs/creddata.svg +318 -0
- package/docs/guessing.md +139 -0
- package/docs/holdout.svg +85 -0
- package/docs/layers.md +80 -0
- package/docs/models.svg +81 -0
- package/docs/real-text.svg +112 -0
- package/package.json +57 -5
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/** One secret found in a text: where it is, what it is, and which rule found it. */
|
|
2
|
+
export interface Finding {
|
|
3
|
+
/** Where the secret starts in the text passed in, in UTF-16 code units. */
|
|
4
|
+
start: number;
|
|
5
|
+
/** Where it ends (exclusive). */
|
|
6
|
+
end: number;
|
|
7
|
+
/** What the secret is, shown in the placeholder: "GitHub token", "password", "private key". */
|
|
8
|
+
kind: string;
|
|
9
|
+
/** The rule that found it, `layer:rule` (`format:GitHub token`, `named:assign`, `known`), for debugging and evaluation. */
|
|
10
|
+
rule: string;
|
|
11
|
+
/**
|
|
12
|
+
* How sure the rule is, 0 to 1. Formats and whole known values are 1; a known value found by one end, 0.95. A finding
|
|
13
|
+
* of 0.9 or more may be learned and hidden wherever its value turns up again (spans.ts isLearnable: not a guess, 8
|
|
14
|
+
* characters or more); one below is hidden only where found.
|
|
15
|
+
*/
|
|
16
|
+
confidence: number;
|
|
17
|
+
/** The name the value sat under, when a rule read one (`DB_PASSWORD`, `apiKey`). */
|
|
18
|
+
name?: string;
|
|
19
|
+
/** Whether the rule read the value where only a literal can stand (an env line, YAML, XML text, a CLI flag). */
|
|
20
|
+
literal?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* From `detect`: the secret as the program reads it, where that differs from the text the span covers (a known
|
|
23
|
+
* value written another way, a literal split in pieces joined, `"xoxb-12" "34ab"`, invisible characters dropped,
|
|
24
|
+
* a JSON escape decoded). May be unset; then the secret is the text the span covers.
|
|
25
|
+
*/
|
|
26
|
+
value?: string;
|
|
27
|
+
}
|
|
28
|
+
/** Where a text came from, which changes what counts as a secret in it. */
|
|
29
|
+
export interface Hint {
|
|
30
|
+
/** The shell command whose output this is. `cat .env` makes the whole output a secret file. */
|
|
31
|
+
command?: string;
|
|
32
|
+
/** The file this text was read from. `.env`, `id_rsa`, `credentials.json` are secret files. */
|
|
33
|
+
path?: string;
|
|
34
|
+
/**
|
|
35
|
+
* The text is a secret file's contents, whatever its path or command says: for a caller that knows by rules of its
|
|
36
|
+
* own (a configured secrets directory, `deploy/prod.conf`). Read as `cat .env` output is.
|
|
37
|
+
*/
|
|
38
|
+
secretFile?: boolean;
|
|
39
|
+
}
|
|
40
|
+
export type Guessing = "off" | "confident" | "eager";
|
|
41
|
+
/** What one call is told about its text: where it came from, and how much to guess. */
|
|
42
|
+
export interface DetectOptions {
|
|
43
|
+
hint?: Hint;
|
|
44
|
+
/** Overrides the redactor's `guessing` for this call. */
|
|
45
|
+
guessing?: Guessing;
|
|
46
|
+
}
|
|
47
|
+
export interface RedactOptions {
|
|
48
|
+
/**
|
|
49
|
+
* How hard to guess at random-looking tokens that have no name or format next to them, the one thing a model
|
|
50
|
+
* decides; every rule runs whatever this says (known values, formats, structure, credential names, secret files
|
|
51
|
+
* and commands, encoded secrets).
|
|
52
|
+
* - "off": no guesses. (In a secret file, the hint's or one written inside the text, the model always sorts the
|
|
53
|
+
* values under neutral names into generated ones, hidden, and settings, kept: the hint already says secrets are
|
|
54
|
+
* there.)
|
|
55
|
+
* - "confident" (default): tokens the model is confident about: in a key-like context, or long ones anywhere.
|
|
56
|
+
* - "eager": shorter and less certain ones too, accepting more false redactions.
|
|
57
|
+
*/
|
|
58
|
+
guessing?: Guessing;
|
|
59
|
+
/**
|
|
60
|
+
* Password hashes (bcrypt, argon2, crypt, SCRAM, LDAP, MySQL, Postgres): "keep" (default) leaves them,
|
|
61
|
+
* as most labelled data does; "hide" redacts them whole, since a weak password's hash can be cracked
|
|
62
|
+
* offline.
|
|
63
|
+
*/
|
|
64
|
+
hashes?: "keep" | "hide";
|
|
65
|
+
/**
|
|
66
|
+
* Values that are secret wherever they appear, in every encoding: credentials the caller holds, each with a label
|
|
67
|
+
* for its placeholders. Values are trimmed. Empty entries are skipped, and so are values too short or ordinary to
|
|
68
|
+
* hide everywhere (under 6 characters, letters only and under 14, digits only and up to 8 digits) or over 16,384
|
|
69
|
+
* characters: `addKnown` returns false for those.
|
|
70
|
+
*/
|
|
71
|
+
known?: Iterable<string | {
|
|
72
|
+
value: string;
|
|
73
|
+
label?: string;
|
|
74
|
+
} | undefined | null>;
|
|
75
|
+
/**
|
|
76
|
+
* Builds the text that replaces a secret, from its finding and its value as the program reads it (decoded where it
|
|
77
|
+
* was escaped). Default: `[REDACTED <kind> #<fingerprint>]`; `redactor.fingerprint(value)` gives the tag. Its text
|
|
78
|
+
* must not look like a secret itself.
|
|
79
|
+
*/
|
|
80
|
+
placeholder?: (finding: Finding, value: string) => string;
|
|
81
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type Context, Doc } from "./context.ts";
|
|
2
|
+
import { type Alphabet } from "./random.ts";
|
|
3
|
+
import type { Finding, Guessing } from "./types.ts";
|
|
4
|
+
export interface Candidate {
|
|
5
|
+
start: number;
|
|
6
|
+
end: number;
|
|
7
|
+
token: string;
|
|
8
|
+
/**
|
|
9
|
+
* What the run had before the token that the token drops (`_`, `-`, `+`, `=`): its context is read from before it,
|
|
10
|
+
* as `Client("` and not `Client("_`.
|
|
11
|
+
*/
|
|
12
|
+
lead?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Runs of token characters long enough to be a key. A run that is a path (`/api/v1/<id>/users`) or
|
|
16
|
+
* dotted (`a.b.c`) is split into its segments, each judged alone. A percent-encoded run that decodes to one token is
|
|
17
|
+
* judged whole, as its decoded value (`token` then differs from the text it spans); its pieces between the escapes
|
|
18
|
+
* aren't judged apart.
|
|
19
|
+
*/
|
|
20
|
+
export declare function candidates(text: string): Candidate[];
|
|
21
|
+
export interface Features {
|
|
22
|
+
token: string;
|
|
23
|
+
alphabet: Alphabet;
|
|
24
|
+
length: number;
|
|
25
|
+
natural: number;
|
|
26
|
+
entropyZ: number;
|
|
27
|
+
switches: number;
|
|
28
|
+
digits: number;
|
|
29
|
+
upper: number;
|
|
30
|
+
lower: number;
|
|
31
|
+
vendorPrefix: boolean;
|
|
32
|
+
decodes: "text" | "binary" | "none";
|
|
33
|
+
hashSize: boolean;
|
|
34
|
+
leftHashy: boolean;
|
|
35
|
+
ctx: Context;
|
|
36
|
+
/** What the token dropped from the front of its run (Candidate.lead); its context's left side ends before it. */
|
|
37
|
+
lead: string;
|
|
38
|
+
secretFile: boolean;
|
|
39
|
+
}
|
|
40
|
+
export declare function features(doc: Doc, c: Candidate, secretFile: boolean): Features;
|
|
41
|
+
/**
|
|
42
|
+
* Why the value at `[start, end)` is public by design, by the vetoes in PUBLIC_VETOES; undefined if none says so. Only
|
|
43
|
+
* of a value the random layer would judge, one run of token characters as long as MIN_TOKEN, which they're written for.
|
|
44
|
+
*/
|
|
45
|
+
export declare function publicReason(doc: Doc, start: number, end: number): string | undefined;
|
|
46
|
+
/** Every hard rule that rules the candidate out (see VETOES), by its reason: for tracing, where vetoed() stops at the first. */
|
|
47
|
+
export declare function vetoes(f: Features): string[];
|
|
48
|
+
/** The first hard rule that rules the candidate out, or undefined. */
|
|
49
|
+
export declare function vetoed(f: Features, { statistical }?: {
|
|
50
|
+
statistical?: boolean | undefined;
|
|
51
|
+
}): string | undefined;
|
|
52
|
+
/** The model's probability that the candidate is a secret: boosted trees trained by scripts/train-unnamed.py. */
|
|
53
|
+
export declare function score(f: Features): number;
|
|
54
|
+
export declare function vector(f: Features): number[];
|
|
55
|
+
/** The model's inputs by name, as vector() gives them. */
|
|
56
|
+
export declare function namedVector(f: Features): Record<string, number>;
|
|
57
|
+
/** The score a token needs to be hidden; undefined where nothing is guessed ("off", outside a secret file). */
|
|
58
|
+
export declare function thresholdFor(guessing: Guessing, secretFile: boolean): number | undefined;
|
|
59
|
+
export declare function findUnnamed(text: string, taken: (start: number, end: number) => boolean, guessing: Guessing, secretFile: boolean, without?: ReadonlySet<string>): Finding[];
|