dotenv-diff 2.4.7 → 2.4.8
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 +13 -0
- package/dist/src/cli/run.js +2 -2
- package/dist/src/cli/run.js.map +1 -1
- package/dist/src/commands/compare.js +1 -1
- package/dist/src/commands/compare.js.map +1 -1
- package/dist/src/commands/ensureFilesOrPrompt.d.ts +22 -0
- package/dist/src/commands/ensureFilesOrPrompt.d.ts.map +1 -0
- package/dist/src/commands/ensureFilesOrPrompt.js +76 -0
- package/dist/src/commands/ensureFilesOrPrompt.js.map +1 -0
- package/dist/src/commands/scanUsage.js +6 -6
- package/dist/src/commands/scanUsage.js.map +1 -1
- package/dist/src/config/types.d.ts +3 -2
- package/dist/src/config/types.d.ts.map +1 -1
- package/dist/src/config/types.js +2 -2
- package/dist/src/config/types.js.map +1 -1
- package/dist/src/core/computeHealthScore.d.ts.map +1 -1
- package/dist/src/core/computeHealthScore.js +3 -0
- package/dist/src/core/computeHealthScore.js.map +1 -1
- package/dist/src/core/detectInconsistentNaming.js +0 -7
- package/dist/src/core/detectInconsistentNaming.js.map +1 -1
- package/dist/src/core/duplicates.d.ts +5 -4
- package/dist/src/core/duplicates.d.ts.map +1 -0
- package/dist/src/core/duplicates.js +5 -2
- package/dist/src/core/duplicates.js.map +1 -0
- package/dist/src/core/envDiscovery.d.ts +19 -0
- package/dist/src/core/envDiscovery.d.ts.map +1 -0
- package/dist/src/core/envDiscovery.js +81 -0
- package/dist/src/core/envDiscovery.js.map +1 -0
- package/dist/src/core/exampleSecretDetector.d.ts.map +1 -1
- package/dist/src/core/exampleSecretDetector.js +2 -2
- package/dist/src/core/exampleSecretDetector.js.map +1 -1
- package/dist/src/core/frameworks/frameworkDetector.d.ts +14 -0
- package/dist/src/core/frameworks/frameworkDetector.d.ts.map +1 -0
- package/dist/src/core/frameworks/frameworkDetector.js +40 -0
- package/dist/src/core/frameworks/frameworkDetector.js.map +1 -0
- package/dist/src/core/frameworks/frameworkValidator.d.ts +10 -0
- package/dist/src/core/frameworks/frameworkValidator.d.ts.map +1 -0
- package/dist/src/core/frameworks/frameworkValidator.js +21 -0
- package/dist/src/core/frameworks/frameworkValidator.js.map +1 -0
- package/dist/src/core/frameworks/nextJsRules.d.ts.map +1 -1
- package/dist/src/core/frameworks/nextJsRules.js +4 -28
- package/dist/src/core/frameworks/nextJsRules.js.map +1 -1
- package/dist/src/core/frameworks/sveltekitRules.d.ts.map +1 -1
- package/dist/src/core/frameworks/sveltekitRules.js +31 -30
- package/dist/src/core/frameworks/sveltekitRules.js.map +1 -1
- package/dist/src/core/parseEnv.d.ts.map +1 -1
- package/dist/src/core/parseEnv.js +19 -1
- package/dist/src/core/parseEnv.js.map +1 -1
- package/dist/src/core/patterns.d.ts.map +1 -1
- package/dist/src/core/patterns.js +24 -1
- package/dist/src/core/patterns.js.map +1 -1
- package/dist/src/core/processComparisonFile.js +1 -1
- package/dist/src/core/processComparisonFile.js.map +1 -1
- package/dist/src/core/scan/scanJsonOutput.d.ts +85 -0
- package/dist/src/core/scan/scanJsonOutput.d.ts.map +1 -0
- package/dist/src/core/scan/scanJsonOutput.js +97 -0
- package/dist/src/core/scan/scanJsonOutput.js.map +1 -0
- package/dist/src/core/scan/secretDetectors.d.ts +28 -0
- package/dist/src/core/scan/secretDetectors.d.ts.map +1 -0
- package/dist/src/core/scan/secretDetectors.js +272 -0
- package/dist/src/core/scan/secretDetectors.js.map +1 -0
- package/dist/src/core/scanFile.d.ts.map +1 -1
- package/dist/src/core/scanFile.js +11 -1
- package/dist/src/core/scanFile.js.map +1 -1
- package/dist/src/core/security/entropy.d.ts +8 -0
- package/dist/src/core/security/entropy.d.ts.map +1 -0
- package/dist/src/core/security/entropy.js +23 -0
- package/dist/src/core/security/entropy.js.map +1 -0
- package/dist/src/core/security/exampleSecretDetector.d.ts +13 -0
- package/dist/src/core/security/exampleSecretDetector.d.ts.map +1 -0
- package/dist/src/core/security/exampleSecretDetector.js +61 -0
- package/dist/src/core/security/exampleSecretDetector.js.map +1 -0
- package/dist/src/core/security/secretDetectors.d.ts +28 -0
- package/dist/src/core/security/secretDetectors.d.ts.map +1 -0
- package/dist/src/core/security/secretDetectors.js +292 -0
- package/dist/src/core/security/secretDetectors.js.map +1 -0
- package/dist/src/index.js +0 -7
- package/dist/src/index.js.map +1 -1
- package/dist/src/services/printScanResult.d.ts +17 -0
- package/dist/src/services/printScanResult.d.ts.map +1 -0
- package/dist/src/services/printScanResult.js +127 -0
- package/dist/src/services/printScanResult.js.map +1 -0
- package/dist/src/services/scanCodebase.d.ts +8 -0
- package/dist/src/services/scanCodebase.d.ts.map +1 -0
- package/dist/src/services/scanCodebase.js +110 -0
- package/dist/src/services/scanCodebase.js.map +1 -0
- package/dist/src/ui/scan/printConsolelogWarning.d.ts.map +1 -1
- package/dist/src/ui/scan/printConsolelogWarning.js +5 -4
- package/dist/src/ui/scan/printConsolelogWarning.js.map +1 -1
- package/dist/src/ui/scan/printExampleWarnings.d.ts +1 -1
- package/dist/src/ui/scan/printExampleWarnings.d.ts.map +1 -1
- package/dist/src/ui/scan/printFrameworkWarnings.d.ts.map +1 -1
- package/dist/src/ui/scan/printFrameworkWarnings.js +4 -2
- package/dist/src/ui/scan/printFrameworkWarnings.js.map +1 -1
- package/dist/src/ui/scan/printSecrets.d.ts +1 -1
- package/dist/src/ui/scan/printSecrets.d.ts.map +1 -1
- package/package.json +7 -5
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type SecretSeverity = 'high' | 'medium' | 'low';
|
|
2
|
+
export type SecretFinding = {
|
|
3
|
+
file: string;
|
|
4
|
+
line: number;
|
|
5
|
+
kind: 'pattern' | 'entropy';
|
|
6
|
+
message: string;
|
|
7
|
+
snippet: string;
|
|
8
|
+
severity: SecretSeverity;
|
|
9
|
+
};
|
|
10
|
+
export declare const SUSPICIOUS_KEYS: RegExp;
|
|
11
|
+
export declare const PROVIDER_PATTERNS: RegExp[];
|
|
12
|
+
/**
|
|
13
|
+
* Checks if a line has an ignore comment
|
|
14
|
+
* fx: // dotenv-diff-ignore or /* dotenv-diff-ignore *\/ or <!-- dotenv-diff-ignore -->
|
|
15
|
+
* @param line - The line to check
|
|
16
|
+
* @returns True if the line should be ignored
|
|
17
|
+
*/
|
|
18
|
+
export declare function hasIgnoreComment(line: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Detects secrets in the source code of a file.
|
|
21
|
+
* @param file - The file path to check.
|
|
22
|
+
* @param source - The source code to scan for secrets.
|
|
23
|
+
* @returns An array of secret findings.
|
|
24
|
+
*/
|
|
25
|
+
export declare function detectSecretsInSource(file: string, source: string, opts?: {
|
|
26
|
+
ignoreUrls?: string[];
|
|
27
|
+
}): SecretFinding[];
|
|
28
|
+
//# sourceMappingURL=secretDetectors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secretDetectors.d.ts","sourceRoot":"","sources":["../../../../src/core/scan/secretDetectors.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;AAGvD,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,SAAS,GAAG,SAAS,CAAC;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,cAAc,CAAC;CAC1B,CAAC;AAGF,eAAO,MAAM,eAAe,QAC6E,CAAC;AAG1G,eAAO,MAAM,iBAAiB,EAAE,MAAM,EAYrC,CAAC;AAiEF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAUtD;AAmGD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE;IAAE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,GAC/B,aAAa,EAAE,CA4HjB"}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { shannonEntropyNormalized } from '../entropy.js';
|
|
2
|
+
// Regular expressions for detecting suspicious keys and provider patterns
|
|
3
|
+
export const SUSPICIOUS_KEYS = /\b(pass(word)?|secret|token|apikey|api_key|key|auth|bearer|private|client_secret|access[_-]?token)\b/i;
|
|
4
|
+
// Regular expressions for detecting provider patterns
|
|
5
|
+
export const PROVIDER_PATTERNS = [
|
|
6
|
+
/\bAKIA[0-9A-Z]{16}\b/, // AWS access key id
|
|
7
|
+
/\bASIA[0-9A-Z]{16}\b/, // AWS temp key
|
|
8
|
+
/\bghp_[0-9A-Za-z]{30,}\b/, // GitHub token
|
|
9
|
+
/\bsk_live_[0-9a-zA-Z]{24,}\b/, // Stripe live secret
|
|
10
|
+
/\bsk_test_[0-9a-zA-Z]{24,}\b/, // Stripe test secret
|
|
11
|
+
/\bAIza[0-9A-Za-z\-_]{20,}\b/, // Google API key
|
|
12
|
+
/\bya29\.[0-9A-Za-z\-_]+\b/, // Google OAuth access token
|
|
13
|
+
/\b[A-Za-z0-9_-]{21}:[A-Za-z0-9_-]{140}\b/, // Firebase token
|
|
14
|
+
/\b0x[a-fA-F0-9]{40}\b/, // Ethereum address
|
|
15
|
+
/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/, // JWT token
|
|
16
|
+
/\bAC[0-9a-fA-F]{32}\b/, // Twilio Account SID
|
|
17
|
+
];
|
|
18
|
+
const LONG_LITERAL = /["'`]{1}([A-Za-z0-9+/_\-]{24,})["'`]{1}/g;
|
|
19
|
+
const HTTPS_PATTERN = /["'`](https?:\/\/(?!localhost)[^"'`]*)["'`]/g;
|
|
20
|
+
// List of harmless URL patterns to ignore
|
|
21
|
+
const HARMLESS_URLS = [
|
|
22
|
+
/https?:\/\/(www\.)?placeholder\.com/i,
|
|
23
|
+
/https?:\/\/(www\.)?example\.com/i,
|
|
24
|
+
/https?:\/\/127\.0\.0\.1(:\d+)?/i,
|
|
25
|
+
/http:\/\/www\.w3\.org\/2000\/svg/i,
|
|
26
|
+
/xmlns=["']http:\/\/www\.w3\.org\/2000\/svg["']/i, // SVG namespace
|
|
27
|
+
];
|
|
28
|
+
// Known harmless attribute keys commonly used in UI / analytics
|
|
29
|
+
const HARMLESS_ATTRIBUTE_KEYS = /\b(trackingId|trackingContext|data-testid|data-test|aria-label)\b/i;
|
|
30
|
+
/**
|
|
31
|
+
* Determines the severity of a secret finding.
|
|
32
|
+
* @param kind 'pattern' | 'entropy'
|
|
33
|
+
* @param message The message describing the finding
|
|
34
|
+
* @param literalLength The length of the literal string (if applicable)
|
|
35
|
+
* @returns The severity level of the secret finding
|
|
36
|
+
*/
|
|
37
|
+
function determineSeverity(kind, message, literalLength) {
|
|
38
|
+
// HIGH: Known provider key patterns
|
|
39
|
+
if (message.includes('known provider key pattern')) {
|
|
40
|
+
return 'high';
|
|
41
|
+
}
|
|
42
|
+
// HIGH: Very high-entropy long strings
|
|
43
|
+
if (kind === 'entropy' && literalLength && literalLength >= 48) {
|
|
44
|
+
return 'high';
|
|
45
|
+
}
|
|
46
|
+
// MEDIUM: Password/secret/token patterns
|
|
47
|
+
if (message.includes('password/secret/token-like')) {
|
|
48
|
+
return 'medium';
|
|
49
|
+
}
|
|
50
|
+
// MEDIUM: Medium high-entropy strings
|
|
51
|
+
if (kind === 'entropy' && literalLength && literalLength >= 32) {
|
|
52
|
+
return 'medium';
|
|
53
|
+
}
|
|
54
|
+
// MEDIUM: HTTP URLs
|
|
55
|
+
if (message.includes('HTTP URL detected')) {
|
|
56
|
+
return 'medium';
|
|
57
|
+
}
|
|
58
|
+
// LOW: HTTPS URLs
|
|
59
|
+
if (message.includes('HTTPS URL detected')) {
|
|
60
|
+
return 'low';
|
|
61
|
+
}
|
|
62
|
+
// Default to medium if we can't determine
|
|
63
|
+
return 'medium';
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Checks if a line has an ignore comment
|
|
67
|
+
* fx: // dotenv-diff-ignore or /* dotenv-diff-ignore *\/ or <!-- dotenv-diff-ignore -->
|
|
68
|
+
* @param line - The line to check
|
|
69
|
+
* @returns True if the line should be ignored
|
|
70
|
+
*/
|
|
71
|
+
export function hasIgnoreComment(line) {
|
|
72
|
+
const normalized = line.trim();
|
|
73
|
+
// Allow mixed casing, extra spaces, and optional dashes
|
|
74
|
+
return (/\/\/.*dotenv[\s-]*diff[\s-]*ignore/i.test(normalized) ||
|
|
75
|
+
/\/\*.*dotenv[\s-]*diff[\s-]*ignore.*\*\//i.test(normalized) ||
|
|
76
|
+
/<!--.*dotenv[\s-]*diff[\s-]*ignore.*-->/i.test(normalized) ||
|
|
77
|
+
/\bdotenv[\s-]*diff[\s-]*ignore\b/i.test(normalized));
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Checks if a URL should be ignored based on ignoreUrls from config.
|
|
81
|
+
* @param url - The URL that might be a potential secret
|
|
82
|
+
* @param ignoreUrls - List of URLs to ignore (from config)
|
|
83
|
+
* @returns true if the URL matches any ignore pattern
|
|
84
|
+
*/
|
|
85
|
+
function ignoreUrlsMatch(url, ignoreUrls) {
|
|
86
|
+
if (!ignoreUrls?.length)
|
|
87
|
+
return false;
|
|
88
|
+
// case-insensitive substring match
|
|
89
|
+
return ignoreUrls.some((pattern) => url.toLowerCase().includes(pattern.toLowerCase()));
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Checks if a string looks like a harmless literal.
|
|
93
|
+
* @param s - The string to check.
|
|
94
|
+
* @returns True if the string looks harmless, false otherwise.
|
|
95
|
+
*/
|
|
96
|
+
function looksHarmlessLiteral(s) {
|
|
97
|
+
return (/\S+@\S+/.test(s) || // emails
|
|
98
|
+
/^data:[a-z]+\/[a-z0-9.+-]+;base64,/i.test(s) || // data URIs
|
|
99
|
+
/^\.{0,2}\//.test(s) || // relative paths
|
|
100
|
+
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(s) || // UUID
|
|
101
|
+
/^[0-9a-f]{32,128}$/i.test(s) || // MD5, SHA1, SHA256, etc.
|
|
102
|
+
/^[A-Za-z0-9+/_\-]{16,20}={0,2}$/.test(s) || // short base64
|
|
103
|
+
/^[A-Za-z0-9+/_\-]*(_PUBLIC|_PRIVATE|VITE_|NEXT_PUBLIC|VUE_)[A-Za-z0-9+/_\-]*={0,2}$/.test(s) || // env-like keys
|
|
104
|
+
/^[MmZzLlHhVvCcSsQqTtAa][0-9eE+.\- ,MmZzLlHhVvCcSsQqTtAa]*$/.test(s) || // SVG path data
|
|
105
|
+
/<svg[\s\S]*?>[\s\S]*?<\/svg>/i.test(s) || // SVG markup
|
|
106
|
+
HARMLESS_URLS.some((rx) => rx.test(s)) // Allowlisted URLs
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Checks if a line looks like a URL construction pattern.
|
|
111
|
+
* @param line - The line to check.
|
|
112
|
+
* @returns True if the line looks like URL construction, false otherwise.
|
|
113
|
+
*/
|
|
114
|
+
function looksLikeUrlConstruction(line) {
|
|
115
|
+
// Check for template literals or string concatenation that looks like URLs
|
|
116
|
+
return (
|
|
117
|
+
// Template literals with URL-like patterns
|
|
118
|
+
/=\s*`[^`]*\$\{[^}]+\}[^`]*\/[^`]*`/.test(line) ||
|
|
119
|
+
// String concatenation with slashes
|
|
120
|
+
/=\s*["'][^"']*\/[^"']*["']\s*\+/.test(line) ||
|
|
121
|
+
// Contains common URL patterns
|
|
122
|
+
/=\s*["'`][^"'`]*\/[^"'`]*(auth|api|login|redirect|callback|protocol)[^"'`]*\/[^"'`]*["'`]/.test(line) ||
|
|
123
|
+
// Keycloak-specific patterns
|
|
124
|
+
/realms\/.*\/protocol\/openid-connect/.test(line));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Checks if a file path is probably a test path.
|
|
128
|
+
* This is determined by looking for common test folder names and file extensions.
|
|
129
|
+
* @param p - The file path to check.
|
|
130
|
+
* @returns True if the file path is probably a test path, false otherwise.
|
|
131
|
+
*/
|
|
132
|
+
function isProbablyTestPath(p) {
|
|
133
|
+
return (/\b(__tests__|__mocks__|fixtures|sandbox|samples)\b/i.test(p) ||
|
|
134
|
+
/\.(spec|test)\.[jt]sx?$/.test(p));
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Checks if a string is a pure interpolation template.
|
|
138
|
+
* @param s - The string to check.
|
|
139
|
+
* @returns True if the string is a pure interpolation template, false otherwise.
|
|
140
|
+
*/
|
|
141
|
+
function isPureInterpolationTemplate(s) {
|
|
142
|
+
// Matches templates like `${a}`, `${a}:${b}`, `${a}|${b}|${c}`
|
|
143
|
+
// i.e. no meaningful static content
|
|
144
|
+
const withoutInterpolations = s.replace(/\$\{[^}]+\}/g, '');
|
|
145
|
+
return /^[\s:|,._-]*$/.test(withoutInterpolations);
|
|
146
|
+
}
|
|
147
|
+
// Threshold is the value between 0 and 1 that determines the sensitivity of the detection.
|
|
148
|
+
const DEFAULT_SECRET_THRESHOLD = 0.85;
|
|
149
|
+
/**
|
|
150
|
+
* Optimized for sveltekit and vite env accessors
|
|
151
|
+
* @param line - A line of code to check.
|
|
152
|
+
* @returns True if the line is an environment variable accessor, false otherwise.
|
|
153
|
+
*/
|
|
154
|
+
function isEnvAccessor(line) {
|
|
155
|
+
return /\b(process\.env|import\.meta\.env|\$env\/(static|dynamic)\/(public|private))\b/.test(line);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Detects secrets in the source code of a file.
|
|
159
|
+
* @param file - The file path to check.
|
|
160
|
+
* @param source - The source code to scan for secrets.
|
|
161
|
+
* @returns An array of secret findings.
|
|
162
|
+
*/
|
|
163
|
+
export function detectSecretsInSource(file, source, opts) {
|
|
164
|
+
const threshold = isProbablyTestPath(file) ? 0.95 : DEFAULT_SECRET_THRESHOLD;
|
|
165
|
+
const findings = [];
|
|
166
|
+
const lines = source.split(/\r?\n/);
|
|
167
|
+
let insideIgnoreBlock = false;
|
|
168
|
+
for (let i = 0; i < lines.length; i++) {
|
|
169
|
+
const lineNo = i + 1;
|
|
170
|
+
const line = lines[i] || '';
|
|
171
|
+
if (/<!--\s*dotenv[\s-]*diff[\s-]*ignore[\s-]*start\s*-->/i.test(line)) {
|
|
172
|
+
insideIgnoreBlock = true;
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (/<!--\s*dotenv[\s-]*diff[\s-]*ignore[\s-]*end\s*-->/i.test(line)) {
|
|
176
|
+
insideIgnoreBlock = false;
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
// Skip if inside ignore block
|
|
180
|
+
if (insideIgnoreBlock)
|
|
181
|
+
continue;
|
|
182
|
+
// Skip comments
|
|
183
|
+
if (/^\s*\/\//.test(line))
|
|
184
|
+
continue;
|
|
185
|
+
// Check if line has ignore comment
|
|
186
|
+
if (hasIgnoreComment(line))
|
|
187
|
+
continue;
|
|
188
|
+
// Check for HTTPS URLs
|
|
189
|
+
HTTPS_PATTERN.lastIndex = 0;
|
|
190
|
+
let httpsMatch;
|
|
191
|
+
while ((httpsMatch = HTTPS_PATTERN.exec(line))) {
|
|
192
|
+
const url = httpsMatch[1] || '';
|
|
193
|
+
if (url && !looksHarmlessLiteral(url)) {
|
|
194
|
+
if (ignoreUrlsMatch(url, opts?.ignoreUrls))
|
|
195
|
+
continue;
|
|
196
|
+
const protocol = url.startsWith('https') ? 'HTTPS' : 'HTTP';
|
|
197
|
+
findings.push({
|
|
198
|
+
file,
|
|
199
|
+
line: lineNo,
|
|
200
|
+
kind: 'pattern',
|
|
201
|
+
message: `${protocol} URL detected – consider moving to an environment variable`,
|
|
202
|
+
snippet: line.trim().slice(0, 180),
|
|
203
|
+
severity: protocol === 'HTTP' ? 'medium' : 'low',
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// 1) Suspicious key literal assignments
|
|
208
|
+
if (SUSPICIOUS_KEYS.test(line)) {
|
|
209
|
+
// Ignore known harmless UI / analytics attributes
|
|
210
|
+
if (HARMLESS_ATTRIBUTE_KEYS.test(line))
|
|
211
|
+
continue;
|
|
212
|
+
const m = line.match(/=\s*["'`](.+?)["'`]/);
|
|
213
|
+
if (m &&
|
|
214
|
+
m[1] &&
|
|
215
|
+
!looksHarmlessLiteral(m[1]) &&
|
|
216
|
+
!looksLikeUrlConstruction(line) &&
|
|
217
|
+
m[1].length >= 12 &&
|
|
218
|
+
!isEnvAccessor(line) &&
|
|
219
|
+
!isPureInterpolationTemplate(m[1])) {
|
|
220
|
+
findings.push({
|
|
221
|
+
file,
|
|
222
|
+
line: lineNo,
|
|
223
|
+
kind: 'pattern',
|
|
224
|
+
message: 'matches password/secret/token-like literal assignment',
|
|
225
|
+
snippet: line.trim().slice(0, 180),
|
|
226
|
+
severity: 'medium',
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
// 2) Provider patterns
|
|
231
|
+
for (const rx of PROVIDER_PATTERNS) {
|
|
232
|
+
if (rx.test(line)) {
|
|
233
|
+
findings.push({
|
|
234
|
+
file,
|
|
235
|
+
line: lineNo,
|
|
236
|
+
kind: 'pattern',
|
|
237
|
+
message: 'matches known provider key pattern',
|
|
238
|
+
snippet: line.trim().slice(0, 180),
|
|
239
|
+
severity: 'high',
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
// 3) High-entropy long literals
|
|
244
|
+
LONG_LITERAL.lastIndex = 0;
|
|
245
|
+
let lm;
|
|
246
|
+
while ((lm = LONG_LITERAL.exec(line))) {
|
|
247
|
+
const literal = lm[1] || '';
|
|
248
|
+
if (looksHarmlessLiteral(literal))
|
|
249
|
+
continue;
|
|
250
|
+
if (literal.length < 32)
|
|
251
|
+
continue;
|
|
252
|
+
const ent = shannonEntropyNormalized(literal);
|
|
253
|
+
if (ent >= threshold) {
|
|
254
|
+
const message = `found high-entropy string (len ${literal.length}, H≈${ent.toFixed(2)})`;
|
|
255
|
+
findings.push({
|
|
256
|
+
file,
|
|
257
|
+
line: lineNo,
|
|
258
|
+
kind: 'entropy',
|
|
259
|
+
message,
|
|
260
|
+
snippet: line.trim().slice(0, 180),
|
|
261
|
+
severity: determineSeverity('entropy', message, literal.length),
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const uniqueFindings = findings.filter((f, idx, arr) => idx ===
|
|
267
|
+
arr.findIndex((other) => other.file === f.file &&
|
|
268
|
+
other.line === f.line &&
|
|
269
|
+
other.snippet === f.snippet));
|
|
270
|
+
return uniqueFindings;
|
|
271
|
+
}
|
|
272
|
+
//# sourceMappingURL=secretDetectors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secretDetectors.js","sourceRoot":"","sources":["../../../../src/core/scan/secretDetectors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAczD,0EAA0E;AAC1E,MAAM,CAAC,MAAM,eAAe,GAC1B,uGAAuG,CAAC;AAE1G,sDAAsD;AACtD,MAAM,CAAC,MAAM,iBAAiB,GAAa;IACzC,sBAAsB,EAAE,oBAAoB;IAC5C,sBAAsB,EAAE,eAAe;IACvC,0BAA0B,EAAE,eAAe;IAC3C,8BAA8B,EAAE,qBAAqB;IACrD,8BAA8B,EAAE,qBAAqB;IACrD,6BAA6B,EAAE,iBAAiB;IAChD,2BAA2B,EAAE,4BAA4B;IACzD,0CAA0C,EAAE,iBAAiB;IAC7D,uBAAuB,EAAE,mBAAmB;IAC5C,uDAAuD,EAAE,YAAY;IACrE,uBAAuB,EAAE,qBAAqB;CAC/C,CAAC;AAEF,MAAM,YAAY,GAAG,0CAA0C,CAAC;AAEhE,MAAM,aAAa,GAAG,8CAA8C,CAAC;AAErE,0CAA0C;AAC1C,MAAM,a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,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI;YACrB,KAAK,CAAC,OAAO,KAAK,CAAC,CAAC,OAAO,CAC9B,CACJ,CAAC;IAEF,OAAO,cAAc,CAAC;AACxB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanFile.d.ts","sourceRoot":"","sources":["../../../src/core/scanFile.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAIhE;;;;;;GAMG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,WAAW,GAChB,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"scanFile.d.ts","sourceRoot":"","sources":["../../../src/core/scanFile.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAIhE;;;;;;GAMG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,WAAW,GAChB,QAAQ,EAAE,CAoEZ"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { ENV_PATTERNS } from './patterns.js';
|
|
3
|
-
import { hasIgnoreComment } from '
|
|
3
|
+
import { hasIgnoreComment } from './security/secretDetectors.js';
|
|
4
4
|
/**
|
|
5
5
|
* Scans a file for environment variable usage.
|
|
6
6
|
* @param filePath - The path to the file being scanned.
|
|
@@ -12,6 +12,15 @@ export function scanFile(filePath, content, opts) {
|
|
|
12
12
|
const usages = [];
|
|
13
13
|
const lines = content.split('\n');
|
|
14
14
|
const relativePath = path.relative(opts.cwd, filePath);
|
|
15
|
+
// Collect all $env imports used in this file
|
|
16
|
+
const envImports = [];
|
|
17
|
+
const importRegex = /import\s+(?:\{[^}]*\}|\w+)\s+from\s+['"](\$env\/(?:static|dynamic)\/(?:private|public))['"]/g;
|
|
18
|
+
let importMatch;
|
|
19
|
+
while ((importMatch = importRegex.exec(content)) !== null) {
|
|
20
|
+
if (importMatch[1]) {
|
|
21
|
+
envImports.push(importMatch[1]);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
15
24
|
for (const pattern of ENV_PATTERNS) {
|
|
16
25
|
let match;
|
|
17
26
|
const regex = new RegExp(pattern.regex.source, pattern.regex.flags);
|
|
@@ -43,6 +52,7 @@ export function scanFile(filePath, content, opts) {
|
|
|
43
52
|
line: lineNumber,
|
|
44
53
|
column,
|
|
45
54
|
pattern: pattern.name,
|
|
55
|
+
imports: envImports,
|
|
46
56
|
context: contextLine,
|
|
47
57
|
isLogged,
|
|
48
58
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanFile.js","sourceRoot":"","sources":["../../../src/core/scanFile.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"scanFile.js","sourceRoot":"","sources":["../../../src/core/scanFile.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEjE;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CACtB,QAAgB,EAChB,OAAe,EACf,IAAiB;IAEjB,MAAM,MAAM,GAAe,EAAE,CAAC;IAC9B,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAEvD,6CAA6C;IAC7C,MAAM,UAAU,GA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YAC/C,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;YAE7C,MAAM,SAAS,GACb,gBAAgB,CAAC,WAAW,CAAC,IAAI,gBAAgB,CAAC,QAAQ,CAAC,CAAC;YAE9D,wCAAwC;YACxC,IAAI,SAAS;gBAAE,SAAS;YAExB,uBAAuB;YACvB,MAAM,QAAQ,GAAG,6CAA6C,CAAC,IAAI,CACjE,WAAW,CACZ,CAAC;YAEF,MAAM,CAAC,IAAI,CAAC;gBACV,QAAQ;gBACR,IAAI,EAAE,YAAY;gBAClB,IAAI,EAAE,UAAU;gBAChB,MAAM;gBACN,OAAO,EAAE,OAAO,CAAC,IAAI;gBACrB,OAAO,EAAE,UAAU;gBACnB,OAAO,EAAE,WAAW;gBACpB,QAAQ;aACT,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the normalized Shannon entropy of a string.
|
|
3
|
+
* Shannon entropy is a measure of the unpredictability or randomness of a string.
|
|
4
|
+
* @param s - The input string.
|
|
5
|
+
* @returns The normalized Shannon entropy (between 0 and 1).
|
|
6
|
+
*/
|
|
7
|
+
export declare function shannonEntropyNormalized(s: string): number;
|
|
8
|
+
//# sourceMappingURL=entropy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entropy.d.ts","sourceRoot":"","sources":["../../../../src/core/security/entropy.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAa1D"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the normalized Shannon entropy of a string.
|
|
3
|
+
* Shannon entropy is a measure of the unpredictability or randomness of a string.
|
|
4
|
+
* @param s - The input string.
|
|
5
|
+
* @returns The normalized Shannon entropy (between 0 and 1).
|
|
6
|
+
*/
|
|
7
|
+
export function shannonEntropyNormalized(s) {
|
|
8
|
+
if (!s)
|
|
9
|
+
return 0;
|
|
10
|
+
const freq = new Map();
|
|
11
|
+
for (const ch of s)
|
|
12
|
+
freq.set(ch, (freq.get(ch) ?? 0) + 1);
|
|
13
|
+
const len = s.length;
|
|
14
|
+
let H = 0;
|
|
15
|
+
for (const [, c] of freq) {
|
|
16
|
+
const p = c / len;
|
|
17
|
+
H += -p * Math.log2(p);
|
|
18
|
+
}
|
|
19
|
+
// Normalize by the maximum possible entropy for the character set (assuming 72 possible characters)
|
|
20
|
+
const maxH = Math.log2(72);
|
|
21
|
+
return Math.min(1, H / maxH);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=entropy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entropy.js","sourceRoot":"","sources":["../../../../src/core/security/entropy.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAC,CAAS;IAChD,IAAI,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC;IACjB,MAAM,IAAI,GAAG,IAAI,GAAG,EAAkB,CAAC;IACvC,KAAK,MAAM,EAAE,IAAI,CAAC;QAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1D,MAAM,GAAG,GAAG,CAAC,CAAC,MAAM,CAAC;IACrB,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,KAAK,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;QACzB,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;QAClB,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC;IACD,oGAAoG;IACpG,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC3B,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface ExampleSecretWarning {
|
|
2
|
+
key: string;
|
|
3
|
+
value: string;
|
|
4
|
+
reason: string;
|
|
5
|
+
severity: 'high' | 'medium' | 'low';
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Detects potential secrets in a .env.example file.
|
|
9
|
+
* @param env - An object representing the `.env.example` file (key-value pairs).
|
|
10
|
+
* @returns An array of warnings about potential secrets.
|
|
11
|
+
*/
|
|
12
|
+
export declare function detectSecretsInExample(env: Record<string, string>): ExampleSecretWarning[];
|
|
13
|
+
//# sourceMappingURL=exampleSecretDetector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exampleSecretDetector.d.ts","sourceRoot":"","sources":["../../../../src/core/security/exampleSecretDetector.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;CACrC;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC1B,oBAAoB,EAAE,CA4DxB"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { PROVIDER_PATTERNS, SUSPICIOUS_KEYS } from './secretDetectors.js';
|
|
2
|
+
import { shannonEntropyNormalized } from './entropy.js';
|
|
3
|
+
/**
|
|
4
|
+
* Detects potential secrets in a .env.example file.
|
|
5
|
+
* @param env - An object representing the `.env.example` file (key-value pairs).
|
|
6
|
+
* @returns An array of warnings about potential secrets.
|
|
7
|
+
*/
|
|
8
|
+
export function detectSecretsInExample(env) {
|
|
9
|
+
const warnings = [];
|
|
10
|
+
for (const [key, rawValue] of Object.entries(env)) {
|
|
11
|
+
if (!rawValue)
|
|
12
|
+
continue;
|
|
13
|
+
const value = rawValue.trim();
|
|
14
|
+
// 1 — Skip placeholders
|
|
15
|
+
if (value === '' ||
|
|
16
|
+
value.toLowerCase() === 'example' ||
|
|
17
|
+
value.toLowerCase() === 'placeholder' ||
|
|
18
|
+
value.includes('your_') ||
|
|
19
|
+
value.includes('<') ||
|
|
20
|
+
value.includes('CHANGE_ME')) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
// 2 — Check provider patterns (AWS, Stripe, GitHub, JWT etc.)
|
|
24
|
+
for (const rx of PROVIDER_PATTERNS) {
|
|
25
|
+
if (rx.test(value)) {
|
|
26
|
+
warnings.push({
|
|
27
|
+
key,
|
|
28
|
+
value,
|
|
29
|
+
reason: 'Value in .env.example matches a known provider key pattern',
|
|
30
|
+
severity: 'high',
|
|
31
|
+
});
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// 3 — Check suspicious keywords on values
|
|
36
|
+
if (SUSPICIOUS_KEYS.test(key)) {
|
|
37
|
+
if (value.length >= 12) {
|
|
38
|
+
warnings.push({
|
|
39
|
+
key,
|
|
40
|
+
value,
|
|
41
|
+
reason: 'Suspicious key name combined with a non-placeholder value',
|
|
42
|
+
severity: 'medium',
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// 4 — Check entropy (high randomness → real secret)
|
|
47
|
+
if (value.length >= 24) {
|
|
48
|
+
const entropy = shannonEntropyNormalized(value);
|
|
49
|
+
if (entropy > 0.8) {
|
|
50
|
+
warnings.push({
|
|
51
|
+
key,
|
|
52
|
+
value,
|
|
53
|
+
reason: `High entropy value in .env.example (≈${entropy.toFixed(2)})`,
|
|
54
|
+
severity: entropy > 0.92 ? 'high' : 'medium',
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return warnings;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=exampleSecretDetector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exampleSecretDetector.js","sourceRoot":"","sources":["../../../../src/core/security/exampleSecretDetector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AASxD;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CACpC,GAA2B;IAE3B,MAAM,QAAQ,GAA2B,EAAE,CAAC;IAE5C,KAAK,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAClD,IAAI,CAAC,QAAQ;YAAE,SAAS;QAExB,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;QAE9B,wBAAwB;QACxB,IACE,KAAK,KAAK,EAAE;YACZ,KAAK,CAAC,WAAW,EAAE,KAAK,SAAS;YACjC,KAAK,CAAC,WAAW,EAAE,KAAK,aAAa;YACrC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC;YACvB,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;YACnB,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,EAC3B,CAAC;YACD,SAAS;QACX,CAAC;QAED,8DAA8D;QAC9D,KAAK,MAAM,EAAE,IAAI,iBAAiB,EAAE,CAAC;YACnC,IAAI,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;gBACnB,QAAQ,CAAC,IAAI,CAAC;oBACZ,GAAG;oBACH,KAAK;oBACL,MAAM,EAAE,4DAA4D;oBACpE,QAAQ,EAAE,MAAM;iBACjB,CAAC,CAAC;gBACH,SAAS;YACX,CAAC;QACH,CAAC;QAED,0CAA0C;QAC1C,IAAI,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YAC9B,IAAI,KAAK,CAAC,MAAM,IAAI,EAAE,EAAE,CAAC;gBACvB,QAAQ,CAAC,IAAI,CAAC;oBACZ,GAAG;oBACH,KAAK;oBACL,MAAM,EAAE,2DAA2D;oBACnE,QAAQ,EAAE,QAAQ;iBACnB,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,oDAAoD;QACpD,IAAI,KAAK,CAAC,MAAM,IAAI,EAAE,EAAE,CAAC;YACvB,MAAM,OAAO,GAAG,wBAAwB,CAAC,KAAK,CAAC,CAAC;YAChD,IAAI,OAAO,GAAG,GAAG,EAAE,CAAC;gBAClB,QAAQ,CAAC,IAAI,CAAC;oBACZ,GAAG;oBACH,KAAK;oBACL,MAAM,EAAE,wCAAwC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG;oBACrE,QAAQ,EAAE,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ;iBAC7C,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type SecretSeverity = 'high' | 'medium' | 'low';
|
|
2
|
+
export type SecretFinding = {
|
|
3
|
+
file: string;
|
|
4
|
+
line: number;
|
|
5
|
+
kind: 'pattern' | 'entropy';
|
|
6
|
+
message: string;
|
|
7
|
+
snippet: string;
|
|
8
|
+
severity: SecretSeverity;
|
|
9
|
+
};
|
|
10
|
+
export declare const SUSPICIOUS_KEYS: RegExp;
|
|
11
|
+
export declare const PROVIDER_PATTERNS: RegExp[];
|
|
12
|
+
/**
|
|
13
|
+
* Checks if a line has an ignore comment
|
|
14
|
+
* fx: // dotenv-diff-ignore or /* dotenv-diff-ignore *\/ or <!-- dotenv-diff-ignore -->
|
|
15
|
+
* @param line - The line to check
|
|
16
|
+
* @returns True if the line should be ignored
|
|
17
|
+
*/
|
|
18
|
+
export declare function hasIgnoreComment(line: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Detects secrets in the source code of a file.
|
|
21
|
+
* @param file - The file path to check.
|
|
22
|
+
* @param source - The source code to scan for secrets.
|
|
23
|
+
* @returns An array of secret findings.
|
|
24
|
+
*/
|
|
25
|
+
export declare function detectSecretsInSource(file: string, source: string, opts?: {
|
|
26
|
+
ignoreUrls?: string[];
|
|
27
|
+
}): SecretFinding[];
|
|
28
|
+
//# sourceMappingURL=secretDetectors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secretDetectors.d.ts","sourceRoot":"","sources":["../../../../src/core/security/secretDetectors.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;AAGvD,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,SAAS,GAAG,SAAS,CAAC;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,cAAc,CAAC;CAC1B,CAAC;AAGF,eAAO,MAAM,eAAe,QAC6E,CAAC;AAG1G,eAAO,MAAM,iBAAiB,EAAE,MAAM,EAYrC,CAAC;AAoFF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAUtD;AAmGD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE;IAAE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,GAC/B,aAAa,EAAE,CAgIjB"}
|