@platform-sec/sensitive-string-core 0.6.0 → 0.6.1
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/dist/bson.d.ts +28 -0
- package/dist/bson.d.ts.map +1 -0
- package/dist/bson.js +37 -0
- package/dist/bson.js.map +1 -0
- package/dist/classification.d.ts +69 -0
- package/dist/classification.d.ts.map +1 -0
- package/dist/classification.js +104 -0
- package/dist/classification.js.map +1 -0
- package/dist/compare.d.ts +36 -0
- package/dist/compare.d.ts.map +1 -0
- package/dist/compare.js +123 -0
- package/dist/compare.js.map +1 -0
- package/dist/context.d.ts +78 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +110 -0
- package/dist/context.js.map +1 -0
- package/dist/derive.d.ts +110 -0
- package/dist/derive.d.ts.map +1 -0
- package/dist/derive.js +153 -0
- package/dist/derive.js.map +1 -0
- package/dist/destination.d.ts +120 -0
- package/dist/destination.d.ts.map +1 -0
- package/dist/destination.js +352 -0
- package/dist/destination.js.map +1 -0
- package/dist/deterministic.d.ts +145 -0
- package/dist/deterministic.d.ts.map +1 -0
- package/dist/deterministic.js +352 -0
- package/dist/deterministic.js.map +1 -0
- package/dist/dev-mode.d.ts +177 -0
- package/dist/dev-mode.d.ts.map +1 -0
- package/dist/dev-mode.js +503 -0
- package/dist/dev-mode.js.map +1 -0
- package/dist/environment.d.ts +181 -0
- package/dist/environment.d.ts.map +1 -0
- package/dist/environment.js +558 -0
- package/dist/environment.js.map +1 -0
- package/dist/errors.d.ts +23 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +21 -0
- package/dist/errors.js.map +1 -0
- package/dist/global-state.d.ts +8 -0
- package/dist/global-state.d.ts.map +1 -0
- package/dist/global-state.js +22 -0
- package/dist/global-state.js.map +1 -0
- package/dist/hash.d.ts +74 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +253 -0
- package/dist/hash.js.map +1 -0
- package/dist/hygiene.d.ts +242 -0
- package/dist/hygiene.d.ts.map +1 -0
- package/dist/hygiene.js +257 -0
- package/dist/hygiene.js.map +1 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +233 -0
- package/dist/index.js.map +1 -0
- package/dist/mask.d.ts +51 -0
- package/dist/mask.d.ts.map +1 -0
- package/dist/mask.js +461 -0
- package/dist/mask.js.map +1 -0
- package/dist/own-property.d.ts +20 -0
- package/dist/own-property.d.ts.map +1 -0
- package/dist/own-property.js +34 -0
- package/dist/own-property.js.map +1 -0
- package/dist/patterns.d.ts +12 -0
- package/dist/patterns.d.ts.map +1 -0
- package/dist/patterns.js +19 -0
- package/dist/patterns.js.map +1 -0
- package/dist/policy.d.ts +51 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +181 -0
- package/dist/policy.js.map +1 -0
- package/dist/probe.d.ts +141 -0
- package/dist/probe.d.ts.map +1 -0
- package/dist/probe.js +213 -0
- package/dist/probe.js.map +1 -0
- package/dist/redact-copy.d.ts +61 -0
- package/dist/redact-copy.d.ts.map +1 -0
- package/dist/redact-copy.js +217 -0
- package/dist/redact-copy.js.map +1 -0
- package/dist/redact.d.ts +141 -0
- package/dist/redact.d.ts.map +1 -0
- package/dist/redact.js +514 -0
- package/dist/redact.js.map +1 -0
- package/dist/redaction-marker.d.ts +48 -0
- package/dist/redaction-marker.d.ts.map +1 -0
- package/dist/redaction-marker.js +138 -0
- package/dist/redaction-marker.js.map +1 -0
- package/dist/redaction-observer.d.ts +108 -0
- package/dist/redaction-observer.d.ts.map +1 -0
- package/dist/redaction-observer.js +103 -0
- package/dist/redaction-observer.js.map +1 -0
- package/dist/redaction-scope.d.ts +21 -0
- package/dist/redaction-scope.d.ts.map +1 -0
- package/dist/redaction-scope.js +44 -0
- package/dist/redaction-scope.js.map +1 -0
- package/dist/reference.d.ts +101 -0
- package/dist/reference.d.ts.map +1 -0
- package/dist/reference.js +123 -0
- package/dist/reference.js.map +1 -0
- package/dist/regexp.d.ts +25 -0
- package/dist/regexp.d.ts.map +1 -0
- package/dist/regexp.js +61 -0
- package/dist/regexp.js.map +1 -0
- package/dist/release.d.ts +88 -0
- package/dist/release.d.ts.map +1 -0
- package/dist/release.js +108 -0
- package/dist/release.js.map +1 -0
- package/dist/reveal-budget.d.ts +148 -0
- package/dist/reveal-budget.d.ts.map +1 -0
- package/dist/reveal-budget.js +314 -0
- package/dist/reveal-budget.js.map +1 -0
- package/dist/revocation.d.ts +168 -0
- package/dist/revocation.d.ts.map +1 -0
- package/dist/revocation.js +541 -0
- package/dist/revocation.js.map +1 -0
- package/dist/sealing.d.ts +283 -0
- package/dist/sealing.d.ts.map +1 -0
- package/dist/sealing.js +523 -0
- package/dist/sealing.js.map +1 -0
- package/dist/sensitive-string.d.ts +919 -0
- package/dist/sensitive-string.d.ts.map +1 -0
- package/dist/sensitive-string.js +2260 -0
- package/dist/sensitive-string.js.map +1 -0
- package/dist/serialized.d.ts +33 -0
- package/dist/serialized.d.ts.map +1 -0
- package/dist/serialized.js +65 -0
- package/dist/serialized.js.map +1 -0
- package/dist/template.d.ts +69 -0
- package/dist/template.d.ts.map +1 -0
- package/dist/template.js +158 -0
- package/dist/template.js.map +1 -0
- package/dist/ttl.d.ts +104 -0
- package/dist/ttl.d.ts.map +1 -0
- package/dist/ttl.js +330 -0
- package/dist/ttl.js.map +1 -0
- package/dist/types.d.ts +859 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +13 -0
- package/dist/types.js.map +1 -0
- package/dist/winston.d.ts +114 -0
- package/dist/winston.d.ts.map +1 -0
- package/dist/winston.js +170 -0
- package/dist/winston.js.map +1 -0
- package/dist/worker.d.ts +398 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +861 -0
- package/dist/worker.js.map +1 -0
- package/dist/wrap.d.ts +287 -0
- package/dist/wrap.d.ts.map +1 -0
- package/dist/wrap.js +553 -0
- package/dist/wrap.js.map +1 -0
- package/package.json +10 -10
package/dist/mask.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { MaskAuditDetails, MaskOptions, MaskStrategy, SensitivityClass } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The floor on hidden characters for a class.
|
|
4
|
+
*
|
|
5
|
+
* Exported for development mode, whose partial rendering is a disclosure of the
|
|
6
|
+
* same kind as a mask and is held to the same bound, so the two cannot disagree
|
|
7
|
+
* about how much of a value may be shown.
|
|
8
|
+
*/
|
|
9
|
+
export declare function minMaskedFloor(klass: SensitivityClass): number;
|
|
10
|
+
/**
|
|
11
|
+
* A validated set of mask options.
|
|
12
|
+
*
|
|
13
|
+
* Producing one requires no access to the raw value, so an invalid call is
|
|
14
|
+
* rejected before anything is revealed or audited.
|
|
15
|
+
*/
|
|
16
|
+
export interface MaskPlan {
|
|
17
|
+
/** The strategy to apply, or `'positional'` for `showFirst` / `showLast`. */
|
|
18
|
+
readonly strategy: MaskStrategy | 'positional';
|
|
19
|
+
readonly showFirst: number;
|
|
20
|
+
readonly showLast: number;
|
|
21
|
+
readonly maskChar: string;
|
|
22
|
+
readonly minMasked: number;
|
|
23
|
+
readonly customStrategy: ((value: string) => string) | undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Validate mask options against the class defaults.
|
|
27
|
+
*
|
|
28
|
+
* Nothing here reads the raw value, so a rejected call produces no audit record
|
|
29
|
+
* for a mask that was never rendered.
|
|
30
|
+
*
|
|
31
|
+
* @throws TypeError If an option has the wrong type or an unknown strategy is named.
|
|
32
|
+
* @throws RangeError If a count is not a whole number, or `minMasked` is below the class floor.
|
|
33
|
+
* @throws Error If positional options are combined with a strategy, or `customStrategy` is misused.
|
|
34
|
+
*/
|
|
35
|
+
export declare function planMask(options: MaskOptions, klass: SensitivityClass): MaskPlan;
|
|
36
|
+
/**
|
|
37
|
+
* The audit record for a plan.
|
|
38
|
+
*
|
|
39
|
+
* Derived from the options alone, so the audit hook runs at the same point in
|
|
40
|
+
* `mask()` as it does in `reveal()`, before the rendering exists.
|
|
41
|
+
*/
|
|
42
|
+
export declare function maskAuditDetails(plan: MaskPlan): MaskAuditDetails;
|
|
43
|
+
/**
|
|
44
|
+
* Render the masked form of a value.
|
|
45
|
+
*
|
|
46
|
+
* @param value - The raw value, already authorized and audited by the caller.
|
|
47
|
+
* @param plan - Validated options from {@link planMask}.
|
|
48
|
+
* @param redact - The class policy's redaction, used when the floor is unmet.
|
|
49
|
+
*/
|
|
50
|
+
export declare function applyMask(value: string, plan: MaskPlan, redact: (value: string) => string): string;
|
|
51
|
+
//# sourceMappingURL=mask.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mask.d.ts","sourceRoot":"","sources":["../src/mask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAchG;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM,CAE9D;AAmDD;;;;;GAKG;AACH,MAAM,WAAW,QAAQ;IACvB,6EAA6E;IAC7E,QAAQ,CAAC,QAAQ,EAAE,YAAY,GAAG,YAAY,CAAC;IAC/C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,cAAc,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAAC;CAClE;AA8XD;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,gBAAgB,GAAG,QAAQ,CAqDhF;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,QAAQ,GAAG,gBAAgB,CASjE;AAyBD;;;;;;GAMG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,QAAQ,EACd,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAChC,MAAM,CAwBR"}
|
package/dist/mask.js
ADDED
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.minMaskedFloor = minMaskedFloor;
|
|
4
|
+
exports.planMask = planMask;
|
|
5
|
+
exports.maskAuditDetails = maskAuditDetails;
|
|
6
|
+
exports.applyMask = applyMask;
|
|
7
|
+
/**
|
|
8
|
+
* The floor on hidden characters, by class.
|
|
9
|
+
*
|
|
10
|
+
* A caller may raise it, never lower it. `mask()` is a partial reveal, and the
|
|
11
|
+
* floor is the only thing that keeps it partial: without it, `showFirst` alone
|
|
12
|
+
* turns masking into an unaudited-looking `reveal()`.
|
|
13
|
+
*/
|
|
14
|
+
const DEFAULT_MIN_MASKED = {
|
|
15
|
+
sensitive: 4,
|
|
16
|
+
credential: 8,
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The floor on hidden characters for a class.
|
|
20
|
+
*
|
|
21
|
+
* Exported for development mode, whose partial rendering is a disclosure of the
|
|
22
|
+
* same kind as a mask and is held to the same bound, so the two cannot disagree
|
|
23
|
+
* about how much of a value may be shown.
|
|
24
|
+
*/
|
|
25
|
+
function minMaskedFloor(klass) {
|
|
26
|
+
return DEFAULT_MIN_MASKED[klass];
|
|
27
|
+
}
|
|
28
|
+
/** Recognized strategy names, in documentation order. */
|
|
29
|
+
const STRATEGY_NAMES = [
|
|
30
|
+
'email',
|
|
31
|
+
'phone',
|
|
32
|
+
'card',
|
|
33
|
+
'ssn',
|
|
34
|
+
'uuid',
|
|
35
|
+
'url',
|
|
36
|
+
'custom',
|
|
37
|
+
];
|
|
38
|
+
/** Replacement character used when the caller does not choose one. */
|
|
39
|
+
const DEFAULT_MASK_CHAR = '*';
|
|
40
|
+
/**
|
|
41
|
+
* Formatting the phone and SSN strategies keep.
|
|
42
|
+
*
|
|
43
|
+
* Everything outside this set that is not part of the visible tail is masked,
|
|
44
|
+
* so a letter in a value that was assumed to be a phone number is hidden rather
|
|
45
|
+
* than shown.
|
|
46
|
+
*/
|
|
47
|
+
const PRESERVED_SEPARATORS = new Set([' ', '-', '.', '(', ')', '+', '/']);
|
|
48
|
+
/** Digits the phone and SSN strategies leave visible at the end. */
|
|
49
|
+
const TAIL_DIGITS = 4;
|
|
50
|
+
/** Country-code digits the phone strategy keeps after a leading '+'. */
|
|
51
|
+
const MAX_COUNTRY_CODE_DIGITS = 3;
|
|
52
|
+
/** ISO/IEC 7812 allows 12 to 19 digits in a primary account number. */
|
|
53
|
+
const CARD_MIN_DIGITS = 12;
|
|
54
|
+
const CARD_MAX_DIGITS = 19;
|
|
55
|
+
/** The PCI-DSS maximum: the six-digit BIN and the last four digits. */
|
|
56
|
+
const CARD_SHOW_FIRST = 6;
|
|
57
|
+
const CARD_SHOW_LAST = 4;
|
|
58
|
+
/** Code point counts of the five segments of a canonical UUID. */
|
|
59
|
+
const UUID_SEGMENTS = [8, 4, 4, 4, 12];
|
|
60
|
+
/**
|
|
61
|
+
* What the url strategy writes in place of a userinfo, a query value or a
|
|
62
|
+
* fragment. A fixed width rather than one mask character per hidden
|
|
63
|
+
* character, so the rendering does not disclose the length of a credential
|
|
64
|
+
* the way the card and uuid renderings disclose the length of a value whose
|
|
65
|
+
* length is not secret.
|
|
66
|
+
*/
|
|
67
|
+
const URL_MASK_WIDTH = 3;
|
|
68
|
+
/**
|
|
69
|
+
* The outcome of a strategy that does not recognize the value.
|
|
70
|
+
*
|
|
71
|
+
* A format strategy exists to show the parts of a known shape that are safe to
|
|
72
|
+
* show. Applied to a value of a different shape it has no idea which parts
|
|
73
|
+
* those are, so it hides nothing and the floor check in {@link applyMask} turns
|
|
74
|
+
* the result into full redaction. Degrading to positional masking instead would
|
|
75
|
+
* disclose a fixed prefix of whatever the value actually is.
|
|
76
|
+
*/
|
|
77
|
+
const STRATEGY_NOT_APPLICABLE = { masked: '', hidden: 0 };
|
|
78
|
+
/**
|
|
79
|
+
* Describe a rejected option without disclosing it.
|
|
80
|
+
*/
|
|
81
|
+
function describeType(value) {
|
|
82
|
+
return value === null ? 'null' : typeof value;
|
|
83
|
+
}
|
|
84
|
+
function isDigit(char) {
|
|
85
|
+
return char >= '0' && char <= '9';
|
|
86
|
+
}
|
|
87
|
+
function isHexDigit(char) {
|
|
88
|
+
return isDigit(char) || (char >= 'a' && char <= 'f') || (char >= 'A' && char <= 'F');
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Split code points on a separator, keeping empty segments.
|
|
92
|
+
*/
|
|
93
|
+
function splitOn(chars, separator) {
|
|
94
|
+
const segments = [[]];
|
|
95
|
+
for (const char of chars) {
|
|
96
|
+
if (char === separator) {
|
|
97
|
+
segments.push([]);
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
segments[segments.length - 1]?.push(char);
|
|
101
|
+
}
|
|
102
|
+
return segments;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Show the leading and trailing characters the plan asks for, hiding the rest.
|
|
106
|
+
*
|
|
107
|
+
* The visible count is clamped so at least `minMasked` characters stay hidden.
|
|
108
|
+
* A value too short to hide that many hides everything, and the floor check in
|
|
109
|
+
* {@link applyMask} then turns the result into full redaction.
|
|
110
|
+
*/
|
|
111
|
+
function maskPositional(chars, plan) {
|
|
112
|
+
const total = chars.length;
|
|
113
|
+
const revealable = Math.max(0, total - plan.minMasked);
|
|
114
|
+
const first = Math.min(plan.showFirst, revealable);
|
|
115
|
+
const last = Math.min(plan.showLast, revealable - first);
|
|
116
|
+
const hidden = total - first - last;
|
|
117
|
+
return {
|
|
118
|
+
masked: chars.slice(0, first).join('') +
|
|
119
|
+
plan.maskChar.repeat(hidden) +
|
|
120
|
+
chars.slice(total - last).join(''),
|
|
121
|
+
hidden,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Keep the first code point of a label and hide the rest.
|
|
126
|
+
*
|
|
127
|
+
* A label of one code point is hidden whole: showing it would disclose the
|
|
128
|
+
* label rather than hint at it.
|
|
129
|
+
*/
|
|
130
|
+
function maskLabel(chars, plan) {
|
|
131
|
+
const [first, ...rest] = chars;
|
|
132
|
+
if (first === undefined || rest.length === 0) {
|
|
133
|
+
return { masked: plan.maskChar.repeat(chars.length), hidden: chars.length };
|
|
134
|
+
}
|
|
135
|
+
return { masked: first + plan.maskChar.repeat(rest.length), hidden: rest.length };
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Hide every digit except the last {@link TAIL_DIGITS}, keeping the caller's
|
|
139
|
+
* separators and hiding anything else.
|
|
140
|
+
*
|
|
141
|
+
* @param preserveBefore - Code point index before which digits stay visible.
|
|
142
|
+
*/
|
|
143
|
+
function maskDigitTail(chars, plan, preserveBefore) {
|
|
144
|
+
let totalDigits = 0;
|
|
145
|
+
for (const char of chars) {
|
|
146
|
+
if (isDigit(char)) {
|
|
147
|
+
totalDigits += 1;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const maskedDigits = Math.max(0, totalDigits - TAIL_DIGITS);
|
|
151
|
+
const parts = [];
|
|
152
|
+
let seenDigits = 0;
|
|
153
|
+
let hidden = 0;
|
|
154
|
+
chars.forEach((char, index) => {
|
|
155
|
+
if (isDigit(char)) {
|
|
156
|
+
const visible = index < preserveBefore || seenDigits >= maskedDigits;
|
|
157
|
+
seenDigits += 1;
|
|
158
|
+
if (visible) {
|
|
159
|
+
parts.push(char);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
parts.push(plan.maskChar);
|
|
163
|
+
hidden += 1;
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (PRESERVED_SEPARATORS.has(char)) {
|
|
167
|
+
parts.push(char);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
parts.push(plan.maskChar);
|
|
171
|
+
hidden += 1;
|
|
172
|
+
});
|
|
173
|
+
return { masked: parts.join(''), hidden };
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Code point index just past a leading country code, or 0 when there is none.
|
|
177
|
+
*
|
|
178
|
+
* A country code is only recognizable when the caller's own formatting
|
|
179
|
+
* delimits it. `+1-555-123-4567` has one; `+15551234567` does not, and treating
|
|
180
|
+
* its leading digits as a country code would show digits of the number itself.
|
|
181
|
+
*/
|
|
182
|
+
function countryCodeEnd(chars) {
|
|
183
|
+
if (chars[0] !== '+') {
|
|
184
|
+
return 0;
|
|
185
|
+
}
|
|
186
|
+
let index = 1;
|
|
187
|
+
while (index < chars.length && index <= MAX_COUNTRY_CODE_DIGITS && isDigit(chars[index] ?? '')) {
|
|
188
|
+
index += 1;
|
|
189
|
+
}
|
|
190
|
+
const digits = index - 1;
|
|
191
|
+
const next = chars[index];
|
|
192
|
+
if (digits === 0 || next === undefined || isDigit(next)) {
|
|
193
|
+
return 0;
|
|
194
|
+
}
|
|
195
|
+
return index;
|
|
196
|
+
}
|
|
197
|
+
const BUILT_IN_STRATEGIES = {
|
|
198
|
+
/**
|
|
199
|
+
* Hide the local part and the domain, keeping one character of each and the
|
|
200
|
+
* final domain label. Showing a full domain leaks the employer or provider.
|
|
201
|
+
*/
|
|
202
|
+
email: (chars, plan) => {
|
|
203
|
+
// The last '@' separates the domain: a quoted local part may contain one.
|
|
204
|
+
const at = chars.lastIndexOf('@');
|
|
205
|
+
if (at === -1) {
|
|
206
|
+
return STRATEGY_NOT_APPLICABLE;
|
|
207
|
+
}
|
|
208
|
+
const local = maskLabel(chars.slice(0, at), plan);
|
|
209
|
+
const domain = chars.slice(at + 1);
|
|
210
|
+
const lastDot = domain.lastIndexOf('.');
|
|
211
|
+
const head = maskLabel(lastDot === -1 ? domain : domain.slice(0, lastDot), plan);
|
|
212
|
+
const tail = lastDot === -1 ? '' : domain.slice(lastDot).join('');
|
|
213
|
+
return {
|
|
214
|
+
masked: `${local.masked}@${head.masked}${tail}`,
|
|
215
|
+
hidden: local.hidden + head.hidden,
|
|
216
|
+
};
|
|
217
|
+
},
|
|
218
|
+
/** Hide every digit but the last four, keeping formatting and a country code. */
|
|
219
|
+
phone: (chars, plan) => maskDigitTail(chars, plan, countryCodeEnd(chars)),
|
|
220
|
+
/**
|
|
221
|
+
* Show the six-digit BIN and the last four digits, which is the PCI-DSS
|
|
222
|
+
* maximum. This is the only definition of card masking in this repository.
|
|
223
|
+
*/
|
|
224
|
+
card: (chars, plan) => {
|
|
225
|
+
const digits = chars.filter(isDigit);
|
|
226
|
+
// Counting digits is not enough to recognize a PAN: a hex token holds
|
|
227
|
+
// twelve or more of them scattered among letters, and rendering those as a
|
|
228
|
+
// card would show ten characters of a value that is not a card at all.
|
|
229
|
+
const shaped = digits.length >= CARD_MIN_DIGITS &&
|
|
230
|
+
digits.length <= CARD_MAX_DIGITS &&
|
|
231
|
+
chars.every((char) => isDigit(char) || PRESERVED_SEPARATORS.has(char));
|
|
232
|
+
if (!shaped) {
|
|
233
|
+
return STRATEGY_NOT_APPLICABLE;
|
|
234
|
+
}
|
|
235
|
+
const hidden = digits.length - CARD_SHOW_FIRST - CARD_SHOW_LAST;
|
|
236
|
+
return {
|
|
237
|
+
masked: digits.slice(0, CARD_SHOW_FIRST).join('') +
|
|
238
|
+
plan.maskChar.repeat(hidden) +
|
|
239
|
+
digits.slice(digits.length - CARD_SHOW_LAST).join(''),
|
|
240
|
+
hidden,
|
|
241
|
+
};
|
|
242
|
+
},
|
|
243
|
+
/** Hide every digit but the last four, keeping formatting. */
|
|
244
|
+
ssn: (chars, plan) => maskDigitTail(chars, plan, 0),
|
|
245
|
+
/**
|
|
246
|
+
* Keep the scheme, the host, the port and the path, which name the resource,
|
|
247
|
+
* and hide the userinfo, every query value and the fragment, which carry a
|
|
248
|
+
* credential when a URL carries one. Query keys are kept: they name a
|
|
249
|
+
* parameter, and a rendering that lost them would say a token was present
|
|
250
|
+
* without saying which.
|
|
251
|
+
*
|
|
252
|
+
* The rendering is the parsed URL written back, so it is normalized: a host
|
|
253
|
+
* is lowercased, an empty path becomes `/`, and characters the parser
|
|
254
|
+
* percent-encodes appear encoded. What is hidden is counted on the parsed
|
|
255
|
+
* parts, so a credential the parser percent-encoded counts once.
|
|
256
|
+
*
|
|
257
|
+
* A value the parser rejects, or one with no host, is not a URL to this
|
|
258
|
+
* strategy and redacts, on the rule every format strategy follows. A URL
|
|
259
|
+
* with nothing to hide is one too: it hides zero characters, the floor is
|
|
260
|
+
* not met, and the whole value redacts. That is deliberate. A caller who
|
|
261
|
+
* marked a URL sensitive and wants its bare form shown has marked the wrong
|
|
262
|
+
* thing; wrap the credential and keep the URL.
|
|
263
|
+
*/
|
|
264
|
+
url: (chars, plan) => {
|
|
265
|
+
let parsed;
|
|
266
|
+
try {
|
|
267
|
+
parsed = new URL(chars.join(''));
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
return STRATEGY_NOT_APPLICABLE;
|
|
271
|
+
}
|
|
272
|
+
if (parsed.host === '') {
|
|
273
|
+
return STRATEGY_NOT_APPLICABLE;
|
|
274
|
+
}
|
|
275
|
+
const mask = plan.maskChar.repeat(URL_MASK_WIDTH);
|
|
276
|
+
let hidden = [...parsed.username].length + [...parsed.password].length;
|
|
277
|
+
const userinfo = parsed.username !== '' || parsed.password !== '' ? `${mask}@` : '';
|
|
278
|
+
const query = [];
|
|
279
|
+
for (const [key, value] of parsed.searchParams) {
|
|
280
|
+
hidden += [...value].length;
|
|
281
|
+
query.push(`${encodeURIComponent(key)}=${mask}`);
|
|
282
|
+
}
|
|
283
|
+
const search = query.length === 0 ? '' : `?${query.join('&')}`;
|
|
284
|
+
let fragment = '';
|
|
285
|
+
if (parsed.hash !== '') {
|
|
286
|
+
hidden += [...parsed.hash.slice(1)].length;
|
|
287
|
+
fragment = `#${mask}`;
|
|
288
|
+
}
|
|
289
|
+
return {
|
|
290
|
+
masked: `${parsed.protocol}//${userinfo}${parsed.host}${parsed.pathname}${search}${fragment}`,
|
|
291
|
+
hidden,
|
|
292
|
+
};
|
|
293
|
+
},
|
|
294
|
+
/** Show the first segment, which is enough to correlate log lines. */
|
|
295
|
+
uuid: (chars, plan) => {
|
|
296
|
+
const segments = splitOn(chars, '-');
|
|
297
|
+
const [head, ...rest] = segments;
|
|
298
|
+
const canonical = head !== undefined &&
|
|
299
|
+
segments.length === UUID_SEGMENTS.length &&
|
|
300
|
+
segments.every((segment, index) => segment.length === UUID_SEGMENTS[index] && segment.every(isHexDigit));
|
|
301
|
+
if (!canonical) {
|
|
302
|
+
return STRATEGY_NOT_APPLICABLE;
|
|
303
|
+
}
|
|
304
|
+
return {
|
|
305
|
+
masked: [head.join(''), ...rest.map((segment) => plan.maskChar.repeat(segment.length))].join('-'),
|
|
306
|
+
hidden: rest.reduce((total, segment) => total + segment.length, 0),
|
|
307
|
+
};
|
|
308
|
+
},
|
|
309
|
+
};
|
|
310
|
+
/**
|
|
311
|
+
* Reject an option of the wrong type, and any count that is not a whole number
|
|
312
|
+
* of characters.
|
|
313
|
+
*/
|
|
314
|
+
function requireCount(value, name, fallback) {
|
|
315
|
+
if (value === undefined) {
|
|
316
|
+
return fallback;
|
|
317
|
+
}
|
|
318
|
+
if (typeof value !== 'number') {
|
|
319
|
+
throw new TypeError(`SensitiveString.mask: ${name} must be a number, received ${describeType(value)}`);
|
|
320
|
+
}
|
|
321
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
322
|
+
throw new RangeError(`SensitiveString.mask: ${name} must be a non-negative integer`);
|
|
323
|
+
}
|
|
324
|
+
return value;
|
|
325
|
+
}
|
|
326
|
+
function requireMaskChar(value) {
|
|
327
|
+
if (value === undefined) {
|
|
328
|
+
return DEFAULT_MASK_CHAR;
|
|
329
|
+
}
|
|
330
|
+
if (typeof value !== 'string') {
|
|
331
|
+
throw new TypeError(`SensitiveString.mask: maskChar must be a string, received ${describeType(value)}`);
|
|
332
|
+
}
|
|
333
|
+
// Code points, not UTF-16 units, so an emoji is one character and a surrogate
|
|
334
|
+
// pair is never split across a repeat.
|
|
335
|
+
const length = [...value].length;
|
|
336
|
+
if (length !== 1) {
|
|
337
|
+
throw new RangeError(`SensitiveString.mask: maskChar must be exactly one character, received ${length}`);
|
|
338
|
+
}
|
|
339
|
+
return value;
|
|
340
|
+
}
|
|
341
|
+
function requireStrategy(value) {
|
|
342
|
+
if (value === undefined) {
|
|
343
|
+
return undefined;
|
|
344
|
+
}
|
|
345
|
+
if (typeof value !== 'string' || !STRATEGY_NAMES.includes(value)) {
|
|
346
|
+
// Naming a string cannot run caller code, so it is quoted. Anything else is
|
|
347
|
+
// described by type: building the message must not invoke a caller-supplied
|
|
348
|
+
// toString().
|
|
349
|
+
const received = typeof value === 'string' ? `'${value}'` : describeType(value);
|
|
350
|
+
throw new TypeError(`SensitiveString.mask: strategy ${received} is not a masking strategy; expected ` +
|
|
351
|
+
STRATEGY_NAMES.map((name) => `'${name}'`).join(', '));
|
|
352
|
+
}
|
|
353
|
+
return value;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Validate mask options against the class defaults.
|
|
357
|
+
*
|
|
358
|
+
* Nothing here reads the raw value, so a rejected call produces no audit record
|
|
359
|
+
* for a mask that was never rendered.
|
|
360
|
+
*
|
|
361
|
+
* @throws TypeError If an option has the wrong type or an unknown strategy is named.
|
|
362
|
+
* @throws RangeError If a count is not a whole number, or `minMasked` is below the class floor.
|
|
363
|
+
* @throws Error If positional options are combined with a strategy, or `customStrategy` is misused.
|
|
364
|
+
*/
|
|
365
|
+
function planMask(options, klass) {
|
|
366
|
+
const floor = DEFAULT_MIN_MASKED[klass];
|
|
367
|
+
const strategy = requireStrategy(options.strategy);
|
|
368
|
+
const showFirst = requireCount(options.showFirst, 'showFirst', 0);
|
|
369
|
+
const showLast = requireCount(options.showLast, 'showLast', 0);
|
|
370
|
+
const minMasked = requireCount(options.minMasked, 'minMasked', floor);
|
|
371
|
+
const maskChar = requireMaskChar(options.maskChar);
|
|
372
|
+
if (minMasked < floor) {
|
|
373
|
+
throw new RangeError(`SensitiveString.mask: minMasked ${minMasked} is below the floor of ${floor} for ` +
|
|
374
|
+
`sensitivity class '${klass}'; the floor may be raised but not lowered`);
|
|
375
|
+
}
|
|
376
|
+
// Silently ignoring these would leave the caller believing they narrowed the
|
|
377
|
+
// result when the strategy decided what to show.
|
|
378
|
+
if (strategy !== undefined &&
|
|
379
|
+
(options.showFirst !== undefined || options.showLast !== undefined)) {
|
|
380
|
+
throw new Error(`SensitiveString.mask: showFirst and showLast do not apply to strategy '${strategy}'`);
|
|
381
|
+
}
|
|
382
|
+
if (options.customStrategy !== undefined && typeof options.customStrategy !== 'function') {
|
|
383
|
+
throw new TypeError(`SensitiveString.mask: customStrategy must be a function, received ${describeType(options.customStrategy)}`);
|
|
384
|
+
}
|
|
385
|
+
if (options.customStrategy !== undefined && strategy !== 'custom') {
|
|
386
|
+
throw new Error("SensitiveString.mask: customStrategy requires strategy: 'custom'; it receives the raw " +
|
|
387
|
+
'value, so it may not be supplied to a built-in strategy');
|
|
388
|
+
}
|
|
389
|
+
if (strategy === 'custom' && options.customStrategy === undefined) {
|
|
390
|
+
throw new Error("SensitiveString.mask: strategy 'custom' requires customStrategy");
|
|
391
|
+
}
|
|
392
|
+
return {
|
|
393
|
+
strategy: strategy ?? 'positional',
|
|
394
|
+
showFirst,
|
|
395
|
+
showLast,
|
|
396
|
+
maskChar,
|
|
397
|
+
minMasked,
|
|
398
|
+
customStrategy: options.customStrategy,
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* The audit record for a plan.
|
|
403
|
+
*
|
|
404
|
+
* Derived from the options alone, so the audit hook runs at the same point in
|
|
405
|
+
* `mask()` as it does in `reveal()`, before the rendering exists.
|
|
406
|
+
*/
|
|
407
|
+
function maskAuditDetails(plan) {
|
|
408
|
+
return Object.freeze({
|
|
409
|
+
operation: 'mask',
|
|
410
|
+
strategy: plan.strategy,
|
|
411
|
+
showFirst: plan.showFirst,
|
|
412
|
+
showLast: plan.showLast,
|
|
413
|
+
minMasked: plan.minMasked,
|
|
414
|
+
maskChar: plan.maskChar,
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Run a caller-supplied formatter over the raw value.
|
|
419
|
+
*
|
|
420
|
+
* The identity check catches the accidental `(value) => value`. It is not a
|
|
421
|
+
* security boundary: the formatter already holds the raw value and can do
|
|
422
|
+
* whatever it likes with it.
|
|
423
|
+
*/
|
|
424
|
+
function runCustomStrategy(value, customStrategy) {
|
|
425
|
+
const masked = customStrategy(value);
|
|
426
|
+
if (typeof masked !== 'string') {
|
|
427
|
+
throw new TypeError(`SensitiveString.mask: customStrategy must return a string, received ${describeType(masked)}`);
|
|
428
|
+
}
|
|
429
|
+
if (masked === value) {
|
|
430
|
+
throw new Error('SensitiveString.mask: customStrategy returned the value unmasked');
|
|
431
|
+
}
|
|
432
|
+
return masked;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Render the masked form of a value.
|
|
436
|
+
*
|
|
437
|
+
* @param value - The raw value, already authorized and audited by the caller.
|
|
438
|
+
* @param plan - Validated options from {@link planMask}.
|
|
439
|
+
* @param redact - The class policy's redaction, used when the floor is unmet.
|
|
440
|
+
*/
|
|
441
|
+
function applyMask(value, plan, redact) {
|
|
442
|
+
if (plan.strategy === 'custom') {
|
|
443
|
+
const { customStrategy } = plan;
|
|
444
|
+
// planMask rejects 'custom' without a formatter, so reaching this is a bug
|
|
445
|
+
// in the package rather than a caller mistake.
|
|
446
|
+
if (customStrategy === undefined) {
|
|
447
|
+
throw new Error("SensitiveString.mask: strategy 'custom' requires customStrategy");
|
|
448
|
+
}
|
|
449
|
+
// A formatter is handed the raw value, so its output cannot be measured
|
|
450
|
+
// against the floor. It is a reveal in all but name.
|
|
451
|
+
return runCustomStrategy(value, customStrategy);
|
|
452
|
+
}
|
|
453
|
+
const chars = [...value];
|
|
454
|
+
const outcome = plan.strategy === 'positional'
|
|
455
|
+
? maskPositional(chars, plan)
|
|
456
|
+
: BUILT_IN_STRATEGIES[plan.strategy](chars, plan);
|
|
457
|
+
// A rendering that cannot hide `minMasked` characters is not a partial view
|
|
458
|
+
// of the value, it is most of the value.
|
|
459
|
+
return outcome.hidden >= plan.minMasked ? outcome.masked : redact(value);
|
|
460
|
+
}
|
|
461
|
+
//# sourceMappingURL=mask.js.map
|
package/dist/mask.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mask.js","sourceRoot":"","sources":["../src/mask.ts"],"names":[],"mappings":";;AAqBA,wCAEC;AAycD,4BAqDC;AAQD,4CASC;AAgCD,8BA4BC;AAhmBD;;;;;;GAMG;AACH,MAAM,kBAAkB,GAAqC;IAC3D,SAAS,EAAE,CAAC;IACZ,UAAU,EAAE,CAAC;CACd,CAAC;AAEF;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,KAAuB;IACpD,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC;AAED,yDAAyD;AACzD,MAAM,cAAc,GAA4B;IAC9C,OAAO;IACP,OAAO;IACP,MAAM;IACN,KAAK;IACL,MAAM;IACN,KAAK;IACL,QAAQ;CACT,CAAC;AAEF,sEAAsE;AACtE,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAE9B;;;;;;GAMG;AACH,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAE1E,oEAAoE;AACpE,MAAM,WAAW,GAAG,CAAC,CAAC;AAEtB,wEAAwE;AACxE,MAAM,uBAAuB,GAAG,CAAC,CAAC;AAElC,uEAAuE;AACvE,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,uEAAuE;A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IAAI,CAAC;QAC7B,CAAC,CAAC,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAEtD,4EAA4E;IAC5E,yCAAyC;IACzC,OAAO,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC3E,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Assign a value under a key that came from data the library did not create.
|
|
3
|
+
*
|
|
4
|
+
* `JSON.parse('{"__proto__": {"isAdmin": true}}')` yields an object with an
|
|
5
|
+
* own property named `__proto__`, inert on that object. Copying it with
|
|
6
|
+
* `target[key] = value` does not create the same property on the target: the
|
|
7
|
+
* key reaches the `__proto__` accessor on `Object.prototype`, which replaces
|
|
8
|
+
* the target's prototype with the attacker's object, and every property in it
|
|
9
|
+
* becomes inherited. A webhook body wrapped by `wrapSensitiveByPath` then
|
|
10
|
+
* answered `wrapped.isAdmin === true` where the input answered `undefined`,
|
|
11
|
+
* and a shadowed `hasOwnProperty` turned the next call on it into a
|
|
12
|
+
* `TypeError`. The path helpers already refused the name; the copies did not.
|
|
13
|
+
*
|
|
14
|
+
* A defined own data property is what the source had, so it is what the copy
|
|
15
|
+
* gets, and the key survives a round trip through `JSON.stringify` as the key
|
|
16
|
+
* it was. Every other key is assigned as before, so a setter a class declares
|
|
17
|
+
* still runs, which `redactCopy` relies on.
|
|
18
|
+
*/
|
|
19
|
+
export declare function assignOwn(target: object, key: string, value: unknown): void;
|
|
20
|
+
//# sourceMappingURL=own-property.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"own-property.d.ts","sourceRoot":"","sources":["../src/own-property.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAY3E"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assignOwn = assignOwn;
|
|
4
|
+
/**
|
|
5
|
+
* Assign a value under a key that came from data the library did not create.
|
|
6
|
+
*
|
|
7
|
+
* `JSON.parse('{"__proto__": {"isAdmin": true}}')` yields an object with an
|
|
8
|
+
* own property named `__proto__`, inert on that object. Copying it with
|
|
9
|
+
* `target[key] = value` does not create the same property on the target: the
|
|
10
|
+
* key reaches the `__proto__` accessor on `Object.prototype`, which replaces
|
|
11
|
+
* the target's prototype with the attacker's object, and every property in it
|
|
12
|
+
* becomes inherited. A webhook body wrapped by `wrapSensitiveByPath` then
|
|
13
|
+
* answered `wrapped.isAdmin === true` where the input answered `undefined`,
|
|
14
|
+
* and a shadowed `hasOwnProperty` turned the next call on it into a
|
|
15
|
+
* `TypeError`. The path helpers already refused the name; the copies did not.
|
|
16
|
+
*
|
|
17
|
+
* A defined own data property is what the source had, so it is what the copy
|
|
18
|
+
* gets, and the key survives a round trip through `JSON.stringify` as the key
|
|
19
|
+
* it was. Every other key is assigned as before, so a setter a class declares
|
|
20
|
+
* still runs, which `redactCopy` relies on.
|
|
21
|
+
*/
|
|
22
|
+
function assignOwn(target, key, value) {
|
|
23
|
+
if (key === '__proto__') {
|
|
24
|
+
Object.defineProperty(target, key, {
|
|
25
|
+
value,
|
|
26
|
+
enumerable: true,
|
|
27
|
+
writable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
});
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
target[key] = value;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=own-property.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"own-property.js","sourceRoot":"","sources":["../src/own-property.ts"],"names":[],"mappings":";;AAkBA,8BAYC;AA9BD;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,SAAS,CAAC,MAAc,EAAE,GAAW,EAAE,KAAc;IACnE,IAAI,GAAG,KAAK,WAAW,EAAE,CAAC;QACxB,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE;YACjC,KAAK;YACL,UAAU,EAAE,IAAI;YAChB,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;QACH,OAAO;IACT,CAAC;IAEA,MAAkC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anchored, linear-time regular expressions for common sensitive-value formats.
|
|
3
|
+
*
|
|
4
|
+
* These patterns provide structural checks only. They do not prove that a value
|
|
5
|
+
* exists, is deliverable, or is otherwise trustworthy. Each property returns
|
|
6
|
+
* a fresh RegExp so callers cannot mutate shared pattern state.
|
|
7
|
+
*/
|
|
8
|
+
export declare const patterns: Readonly<{
|
|
9
|
+
/** A practical structural email check with exactly one non-empty `@` boundary. */
|
|
10
|
+
readonly email: RegExp;
|
|
11
|
+
}>;
|
|
12
|
+
//# sourceMappingURL=patterns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns.d.ts","sourceRoot":"","sources":["../src/patterns.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ;IACnB,kFAAkF;oBACrE,MAAM;EAKnB,CAAC"}
|
package/dist/patterns.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.patterns = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Anchored, linear-time regular expressions for common sensitive-value formats.
|
|
6
|
+
*
|
|
7
|
+
* These patterns provide structural checks only. They do not prove that a value
|
|
8
|
+
* exists, is deliverable, or is otherwise trustworthy. Each property returns
|
|
9
|
+
* a fresh RegExp so callers cannot mutate shared pattern state.
|
|
10
|
+
*/
|
|
11
|
+
exports.patterns = Object.freeze({
|
|
12
|
+
/** A practical structural email check with exactly one non-empty `@` boundary. */
|
|
13
|
+
get email() {
|
|
14
|
+
// `$` also matches before a final line terminator in JavaScript. The
|
|
15
|
+
// negative lookahead makes the end assertion absolute.
|
|
16
|
+
return /^[^@\s]+@[^@\s]+$(?![\s\S])/;
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=patterns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns.js","sourceRoot":"","sources":["../src/patterns.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACU,QAAA,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC;IACpC,kFAAkF;IAClF,IAAI,KAAK;QACP,qEAAqE;QACrE,uDAAuD;QACvD,OAAO,6BAA6B,CAAC;IACvC,CAAC;CACF,CAAC,CAAC"}
|