@appystore/secret-shield 0.0.0-stage → 0.1.3
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 +202 -0
- package/README.md +34 -2
- package/dist/index.cjs +2353 -0
- package/dist/index.d.cts +355 -0
- package/dist/index.d.ts +355 -0
- package/dist/index.js +2313 -0
- package/package.json +68 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public contracts of the SecretShield core engine.
|
|
3
|
+
*
|
|
4
|
+
* SECURITY INVARIANT: no type exported from this module may ever carry the
|
|
5
|
+
* original secret value — not even in an internal or debug field.
|
|
6
|
+
*/
|
|
7
|
+
type SecretCategory = "api-key" | "client-secret" | "password" | "jwt" | "oauth-token" | "private-key" | "database-credential" | "cloud-credential" | "generic-secret" | "custom";
|
|
8
|
+
declare const SECRET_CATEGORIES: readonly SecretCategory[];
|
|
9
|
+
type Severity = "low" | "medium" | "high" | "critical";
|
|
10
|
+
declare const SEVERITIES: readonly Severity[];
|
|
11
|
+
/**
|
|
12
|
+
* How a detected value is masked.
|
|
13
|
+
* - `public-prefix`: keep a well-known, non-secret vendor prefix (e.g. `sk_live_`, `ghp_`, `AKIA`)
|
|
14
|
+
* and replace the rest with a fixed-length mask. Falls back to `full` when no public prefix exists.
|
|
15
|
+
* - `full`: replace the whole value with a fixed-length mask.
|
|
16
|
+
* - `placeholder`: replace the whole value with a fixed label (e.g. `[PRIVATE_KEY_REDACTED]`).
|
|
17
|
+
*/
|
|
18
|
+
type MaskPolicy = "public-prefix" | "full" | "placeholder";
|
|
19
|
+
/**
|
|
20
|
+
* Global masking strategy.
|
|
21
|
+
* - `partial` (default): honours each rule's MaskPolicy (public prefixes only, never suffixes).
|
|
22
|
+
* - `full`: never keeps any prefix.
|
|
23
|
+
* - `token`: replaces values with numbered tokens such as `[REDACTED:api-key#1]`; identical
|
|
24
|
+
* values in one operation share the same token.
|
|
25
|
+
*/
|
|
26
|
+
type MaskingStrategy = "partial" | "full" | "token";
|
|
27
|
+
type ConfidenceLevel = "very-high" | "high" | "suspicious" | "weak";
|
|
28
|
+
/** Source language used to select a syntax-aware analyzer. */
|
|
29
|
+
type Language = "javascript" | "typescript" | "json" | "yaml" | "dotenv" | "text";
|
|
30
|
+
interface SecretFinding {
|
|
31
|
+
/** Random identifier. Never derived from the secret value. */
|
|
32
|
+
id: string;
|
|
33
|
+
ruleId: string;
|
|
34
|
+
category: SecretCategory;
|
|
35
|
+
severity: Severity;
|
|
36
|
+
/** 0–100. */
|
|
37
|
+
confidence: number;
|
|
38
|
+
confidenceLevel: ConfidenceLevel;
|
|
39
|
+
file?: string;
|
|
40
|
+
/** 1-based line of the first masked character. */
|
|
41
|
+
line: number;
|
|
42
|
+
/** 1-based column of the first masked character (UTF-16 code units). */
|
|
43
|
+
column: number;
|
|
44
|
+
/** 1-based line of the last masked character. */
|
|
45
|
+
endLine: number;
|
|
46
|
+
/** 1-based column just after the last masked character. */
|
|
47
|
+
endColumn: number;
|
|
48
|
+
/** The masked representation that replaced the value in the output text. */
|
|
49
|
+
maskedValue: string;
|
|
50
|
+
}
|
|
51
|
+
interface FindingSummary {
|
|
52
|
+
total: number;
|
|
53
|
+
critical: number;
|
|
54
|
+
high: number;
|
|
55
|
+
medium: number;
|
|
56
|
+
low: number;
|
|
57
|
+
}
|
|
58
|
+
interface ScanResult {
|
|
59
|
+
findings: SecretFinding[];
|
|
60
|
+
summary: FindingSummary;
|
|
61
|
+
}
|
|
62
|
+
interface RedactResult extends ScanResult {
|
|
63
|
+
/** The input text with every finding masked. */
|
|
64
|
+
text: string;
|
|
65
|
+
}
|
|
66
|
+
interface DetectionOptions {
|
|
67
|
+
/** Pattern-based rules (built-in and custom). Default: true. */
|
|
68
|
+
regex?: boolean;
|
|
69
|
+
/** Syntax-aware analysis for JavaScript, TypeScript, JSON and YAML. Default: true. */
|
|
70
|
+
ast?: boolean;
|
|
71
|
+
/** Entropy signal and high-entropy string detection. Default: true. */
|
|
72
|
+
entropy?: boolean;
|
|
73
|
+
/** Name/context scoring of assigned values. Default: true. */
|
|
74
|
+
contextual?: boolean;
|
|
75
|
+
/** Findings below this confidence (0–100) are ignored. Default: 40. */
|
|
76
|
+
minConfidence?: number;
|
|
77
|
+
}
|
|
78
|
+
interface MaskingOptions {
|
|
79
|
+
strategy?: MaskingStrategy;
|
|
80
|
+
/** Single character used to build masks (allow-listed). Default: `*`. */
|
|
81
|
+
maskChar?: string;
|
|
82
|
+
/** Fixed mask length, independent of the secret length. Default: 8. */
|
|
83
|
+
maskLength?: number;
|
|
84
|
+
}
|
|
85
|
+
interface LimitOptions {
|
|
86
|
+
/** Maximum input size in UTF-16 code units. Default: 5_000_000 (~5 MB). */
|
|
87
|
+
maxInputLength?: number;
|
|
88
|
+
}
|
|
89
|
+
interface RuleOptions {
|
|
90
|
+
/** Ids of built-in or custom rules to disable. */
|
|
91
|
+
disabled?: string[];
|
|
92
|
+
/** Custom rules to register at construction time. */
|
|
93
|
+
custom?: CustomRuleDefinition[];
|
|
94
|
+
}
|
|
95
|
+
interface SecretShieldOptions {
|
|
96
|
+
detection?: DetectionOptions;
|
|
97
|
+
masking?: MaskingOptions;
|
|
98
|
+
limits?: LimitOptions;
|
|
99
|
+
rules?: RuleOptions;
|
|
100
|
+
}
|
|
101
|
+
interface ScanOptions {
|
|
102
|
+
/** Optional file label attached to findings; also used to infer the language. */
|
|
103
|
+
file?: string;
|
|
104
|
+
/** Overrides language detection. */
|
|
105
|
+
language?: Language;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* A user-defined detection rule. Patterns are compiled with RE2 semantics
|
|
109
|
+
* (linear time, no backreferences or lookarounds) to rule out ReDoS.
|
|
110
|
+
*/
|
|
111
|
+
interface CustomRuleDefinition {
|
|
112
|
+
/** Lowercase identifier: letters, digits, `-`, `_`, `.` (max 64). */
|
|
113
|
+
id: string;
|
|
114
|
+
name: string;
|
|
115
|
+
description?: string;
|
|
116
|
+
category: SecretCategory;
|
|
117
|
+
severity: Severity;
|
|
118
|
+
/** RE2 pattern source, or a RegExp whose source is RE2-compatible. */
|
|
119
|
+
pattern: string | RegExp;
|
|
120
|
+
/** Subset of `i`, `m`, `s`. Ignored when `pattern` is a RegExp (its flags are used). */
|
|
121
|
+
flags?: string;
|
|
122
|
+
/** 0–100. */
|
|
123
|
+
confidence: number;
|
|
124
|
+
enabled?: boolean;
|
|
125
|
+
/** Capture group holding the secret. Default: the whole match. */
|
|
126
|
+
secretGroup?: number;
|
|
127
|
+
/** Default: `full`. */
|
|
128
|
+
maskPolicy?: MaskPolicy;
|
|
129
|
+
/** Required when maskPolicy is `placeholder`, e.g. `[INTERNAL_SECRET]`. */
|
|
130
|
+
placeholder?: string;
|
|
131
|
+
/** Lowercase substrings used as a fast pre-filter. */
|
|
132
|
+
keywords?: string[];
|
|
133
|
+
}
|
|
134
|
+
interface RuleInfo {
|
|
135
|
+
id: string;
|
|
136
|
+
name: string;
|
|
137
|
+
category: SecretCategory;
|
|
138
|
+
severity: Severity;
|
|
139
|
+
source: "builtin" | "custom";
|
|
140
|
+
enabled: boolean;
|
|
141
|
+
}
|
|
142
|
+
type NotScannedReason = "ignored" | "binary" | "too-large" | "symlink" | "unreadable" | "not-a-file" | "limit-reached";
|
|
143
|
+
interface FileOptions {
|
|
144
|
+
/** Maximum file size in bytes. Default: 2 MiB. */
|
|
145
|
+
maxFileSize?: number;
|
|
146
|
+
/** Overrides language detection from the file extension. */
|
|
147
|
+
language?: Language;
|
|
148
|
+
}
|
|
149
|
+
interface FileScanResult extends ScanResult {
|
|
150
|
+
/** The path as provided (scanFile) or relative to the root with `/` (scanDirectory). */
|
|
151
|
+
file: string;
|
|
152
|
+
status: "scanned" | "not-scanned";
|
|
153
|
+
reason?: NotScannedReason;
|
|
154
|
+
}
|
|
155
|
+
interface FileRedactResult extends FileScanResult {
|
|
156
|
+
/** Redacted content. Present only when status is `scanned`. The file on disk is never modified. */
|
|
157
|
+
text?: string;
|
|
158
|
+
}
|
|
159
|
+
interface DirectoryScanOptions extends FileOptions {
|
|
160
|
+
/** Read `.secretshieldignore` at the root. Disable for untrusted workspaces. Default: true. */
|
|
161
|
+
useIgnoreFile?: boolean;
|
|
162
|
+
/** Extra ignore patterns (gitignore syntax subset). */
|
|
163
|
+
ignore?: string[];
|
|
164
|
+
/** Maximum number of files to scan. Default: 20_000. */
|
|
165
|
+
maxFiles?: number;
|
|
166
|
+
/** Maximum directory depth. Default: 32. */
|
|
167
|
+
maxDepth?: number;
|
|
168
|
+
/** Parallel file reads. Default: 8. */
|
|
169
|
+
concurrency?: number;
|
|
170
|
+
signal?: AbortSignal;
|
|
171
|
+
onProgress?: (progress: {
|
|
172
|
+
scanned: number;
|
|
173
|
+
notScanned: number;
|
|
174
|
+
}) => void;
|
|
175
|
+
}
|
|
176
|
+
interface NotScannedEntry {
|
|
177
|
+
file: string;
|
|
178
|
+
reason: NotScannedReason;
|
|
179
|
+
}
|
|
180
|
+
interface DirectoryScanResult {
|
|
181
|
+
/** Absolute, resolved root directory. */
|
|
182
|
+
root: string;
|
|
183
|
+
/** Scanned files that contain at least one finding. */
|
|
184
|
+
files: FileScanResult[];
|
|
185
|
+
/** Files and directories that were NOT analysed. They must never be presented as safe. */
|
|
186
|
+
notScanned: NotScannedEntry[];
|
|
187
|
+
scannedFiles: number;
|
|
188
|
+
/** True when maxFiles was reached before the walk completed. */
|
|
189
|
+
truncated: boolean;
|
|
190
|
+
summary: FindingSummary;
|
|
191
|
+
}
|
|
192
|
+
interface ObjectSecretFinding {
|
|
193
|
+
id: string;
|
|
194
|
+
ruleId: string;
|
|
195
|
+
category: SecretCategory;
|
|
196
|
+
severity: Severity;
|
|
197
|
+
confidence: number;
|
|
198
|
+
confidenceLevel: ConfidenceLevel;
|
|
199
|
+
/** JSONPath-like location, e.g. `$.database.password` or `$.items[0]["x-api-key"]`. */
|
|
200
|
+
path: string;
|
|
201
|
+
maskedValue: string;
|
|
202
|
+
}
|
|
203
|
+
interface ObjectRedactResult<T> {
|
|
204
|
+
/** A deep copy of the input with sensitive values masked. The input is never mutated. */
|
|
205
|
+
value: T;
|
|
206
|
+
findings: ObjectSecretFinding[];
|
|
207
|
+
summary: FindingSummary;
|
|
208
|
+
}
|
|
209
|
+
type ReportFormat = "json" | "markdown" | "sarif";
|
|
210
|
+
type ReportInput = ScanResult | FileScanResult | DirectoryScanResult | ObjectRedactResult<unknown> | readonly FileScanResult[];
|
|
211
|
+
interface ValidationIssue {
|
|
212
|
+
code: "RESIDUAL_SECRET" | "SUMMARY_MISMATCH" | "UNEXPECTED_FINDING_FIELD" | "INVALID_FINDING";
|
|
213
|
+
/** 1-based line in the redacted text, when relevant. */
|
|
214
|
+
line?: number;
|
|
215
|
+
}
|
|
216
|
+
interface ValidationResult {
|
|
217
|
+
valid: boolean;
|
|
218
|
+
issues: ValidationIssue[];
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* SecretShield core engine.
|
|
223
|
+
*
|
|
224
|
+
* - Fully offline: no network access, no telemetry, no logging.
|
|
225
|
+
* - Results never contain original secret values.
|
|
226
|
+
* - Redaction fails closed: if the output cannot be verified, an error is
|
|
227
|
+
* thrown and no text is returned.
|
|
228
|
+
* - Files are read but never written.
|
|
229
|
+
*/
|
|
230
|
+
declare class SecretShield {
|
|
231
|
+
private readonly options;
|
|
232
|
+
private readonly customRules;
|
|
233
|
+
private readonly disabledRules;
|
|
234
|
+
constructor(options?: SecretShieldOptions);
|
|
235
|
+
/** Detects secrets without modifying the input. */
|
|
236
|
+
scan(input: string, options?: ScanOptions): ScanResult;
|
|
237
|
+
/**
|
|
238
|
+
* Detects and masks secrets. Formatting, quotes and non-sensitive values are
|
|
239
|
+
* preserved. Fails closed: if the result cannot be verified, an error is
|
|
240
|
+
* thrown and no text is returned.
|
|
241
|
+
*/
|
|
242
|
+
redact(input: string, options?: ScanOptions): RedactResult;
|
|
243
|
+
/**
|
|
244
|
+
* Protects a prompt intended for an LLM. Fenced code blocks (```ts, ```json,
|
|
245
|
+
* ```yaml…) are analysed with the matching parser.
|
|
246
|
+
*/
|
|
247
|
+
redactPrompt(prompt: string): RedactResult;
|
|
248
|
+
scanFile(filePath: string, options?: FileOptions): Promise<FileScanResult>;
|
|
249
|
+
/** Returns a redacted version of a file. The file on disk is never modified. */
|
|
250
|
+
redactFile(filePath: string, options?: FileOptions): Promise<FileRedactResult>;
|
|
251
|
+
/**
|
|
252
|
+
* Scans a directory tree. Symbolic links are never followed, ignored and
|
|
253
|
+
* unreadable paths are reported in `notScanned`.
|
|
254
|
+
*/
|
|
255
|
+
scanDirectory(root: string, options?: DirectoryScanOptions): Promise<DirectoryScanResult>;
|
|
256
|
+
/**
|
|
257
|
+
* Returns a deep copy of `input` with sensitive values masked: values of
|
|
258
|
+
* sensitive properties (`password`, `apiKey`…) and known secret formats in
|
|
259
|
+
* any string. The input is never mutated.
|
|
260
|
+
*/
|
|
261
|
+
redactObject<T>(input: T): ObjectRedactResult<T>;
|
|
262
|
+
/** Registers a custom rule (compiled with RE2: linear time, no ReDoS). */
|
|
263
|
+
registerRule(definition: CustomRuleDefinition): RuleInfo;
|
|
264
|
+
/** Removes a custom rule. Built-in rules cannot be removed, only disabled. */
|
|
265
|
+
removeRule(id: string): void;
|
|
266
|
+
/** Enables or disables a built-in or custom rule. */
|
|
267
|
+
setRuleEnabled(id: string, enabled: boolean): void;
|
|
268
|
+
listRules(): RuleInfo[];
|
|
269
|
+
/**
|
|
270
|
+
* Tests a rule definition against a sample without registering it. Only that
|
|
271
|
+
* rule runs, so the result shows exactly what it would detect.
|
|
272
|
+
*/
|
|
273
|
+
testRule(definition: CustomRuleDefinition, sample: string): RedactResult;
|
|
274
|
+
/** Generates a shareable report: no secret values, no masked values, no lengths. */
|
|
275
|
+
generateReport(input: ReportInput, format?: ReportFormat): string;
|
|
276
|
+
/**
|
|
277
|
+
* Verifies a redaction result: re-scans the redacted text for residual
|
|
278
|
+
* secrets and checks that findings carry only allowed fields.
|
|
279
|
+
*/
|
|
280
|
+
validate(result: RedactResult): ValidationResult;
|
|
281
|
+
private guard;
|
|
282
|
+
private ruleInfo;
|
|
283
|
+
private extractContext;
|
|
284
|
+
private looksMasked;
|
|
285
|
+
private activeRules;
|
|
286
|
+
private process;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Error handling (spec §8.2, OWASP A10).
|
|
291
|
+
*
|
|
292
|
+
* Every error thrown by the engine is a SecretShieldError with a stable `code`
|
|
293
|
+
* and a fixed, generic message. Messages NEVER embed analysed content, and
|
|
294
|
+
* underlying errors (e.g. from parsers, which may quote source snippets) are
|
|
295
|
+
* never attached as `cause`.
|
|
296
|
+
*/
|
|
297
|
+
type SecretShieldErrorCode = "INVALID_INPUT" | "INPUT_TOO_LARGE" | "INVALID_OPTIONS" | "REDACTION_INCOMPLETE" | "INVALID_RULE" | "DUPLICATE_RULE" | "RULE_NOT_FOUND" | "TOO_MANY_RULES" | "ABORTED" | "INTERNAL_ERROR";
|
|
298
|
+
declare class SecretShieldError extends Error {
|
|
299
|
+
readonly code: SecretShieldErrorCode;
|
|
300
|
+
constructor(code: SecretShieldErrorCode);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Shannon entropy in bits per character: H(X) = −Σ p(xᵢ) log₂ p(xᵢ) (spec §4.3).
|
|
305
|
+
*
|
|
306
|
+
* Entropy alone never proves that a string is a secret; it is only one
|
|
307
|
+
* scoring signal combined with patterns and context.
|
|
308
|
+
*/
|
|
309
|
+
declare function shannonEntropy(value: string): number;
|
|
310
|
+
|
|
311
|
+
/** Infers the language from a file name. Unknown names are treated as plain text. */
|
|
312
|
+
declare function detectLanguage(file: string | undefined): Language;
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Default exclusions (spec §8.3). Lockfiles are excluded because integrity
|
|
316
|
+
* hashes are high-entropy noise. Excluded paths are always reported as
|
|
317
|
+
* "not scanned", never as safe.
|
|
318
|
+
*/
|
|
319
|
+
declare const DEFAULT_IGNORE_PATTERNS: readonly string[];
|
|
320
|
+
|
|
321
|
+
declare const IGNORE_FILE_NAME = ".secretshieldignore";
|
|
322
|
+
|
|
323
|
+
/** Keep in sync with package.json (enforced by test/version.test.ts). */
|
|
324
|
+
declare const VERSION = "0.1.3";
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Reports are designed to be shared (CI logs, tickets, dashboards), so they
|
|
328
|
+
* carry even less than findings: no masked value (which may keep a vendor
|
|
329
|
+
* prefix) and no end position (which would reveal the secret length).
|
|
330
|
+
*/
|
|
331
|
+
interface ReportEntry {
|
|
332
|
+
file?: string;
|
|
333
|
+
path?: string;
|
|
334
|
+
line?: number;
|
|
335
|
+
column?: number;
|
|
336
|
+
ruleId: string;
|
|
337
|
+
category: SecretCategory;
|
|
338
|
+
severity: Severity;
|
|
339
|
+
confidence: number;
|
|
340
|
+
}
|
|
341
|
+
interface JsonReport {
|
|
342
|
+
tool: {
|
|
343
|
+
name: "SecretShield";
|
|
344
|
+
version: string;
|
|
345
|
+
};
|
|
346
|
+
generatedAt: string;
|
|
347
|
+
summary: FindingSummary;
|
|
348
|
+
byCategory: Partial<Record<SecretCategory, number>>;
|
|
349
|
+
results: ReportEntry[];
|
|
350
|
+
notScanned: NotScannedEntry[];
|
|
351
|
+
disclaimer: string;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export { DEFAULT_IGNORE_PATTERNS, IGNORE_FILE_NAME, SECRET_CATEGORIES, SEVERITIES, SecretShield, SecretShieldError, VERSION, detectLanguage, shannonEntropy };
|
|
355
|
+
export type { ConfidenceLevel, CustomRuleDefinition, DetectionOptions, DirectoryScanOptions, DirectoryScanResult, FileOptions, FileRedactResult, FileScanResult, FindingSummary, JsonReport, Language, LimitOptions, MaskPolicy, MaskingOptions, MaskingStrategy, NotScannedEntry, NotScannedReason, ObjectRedactResult, ObjectSecretFinding, RedactResult, ReportEntry, ReportFormat, ReportInput, RuleInfo, RuleOptions, ScanOptions, ScanResult, SecretCategory, SecretFinding, SecretShieldErrorCode, SecretShieldOptions, Severity, ValidationIssue, ValidationResult };
|