logshield-cli 0.2.9 → 0.3.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/cli/index.cjs +61 -24
- package/package.json +1 -1
package/dist/cli/index.cjs
CHANGED
|
@@ -108,9 +108,9 @@ var init_summary = __esm({
|
|
|
108
108
|
function applyRules(input, rules, ctx, matches) {
|
|
109
109
|
let output = input;
|
|
110
110
|
for (const rule of rules) {
|
|
111
|
-
output = output.replace(rule.pattern, (...
|
|
112
|
-
const match =
|
|
113
|
-
const groups =
|
|
111
|
+
output = output.replace(rule.pattern, (...args) => {
|
|
112
|
+
const match = args[0];
|
|
113
|
+
const groups = args.slice(1, -2);
|
|
114
114
|
const replaced = rule.replace(match, ctx, groups);
|
|
115
115
|
if (replaced !== match) {
|
|
116
116
|
matches.push({
|
|
@@ -156,6 +156,16 @@ var init_tokens = __esm({
|
|
|
156
156
|
pattern: /\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/g,
|
|
157
157
|
replace: () => "<REDACTED_JWT>"
|
|
158
158
|
},
|
|
159
|
+
{
|
|
160
|
+
name: "OAUTH_ACCESS_TOKEN",
|
|
161
|
+
pattern: /\bya29\.[A-Za-z0-9._-]+\b/g,
|
|
162
|
+
replace: () => "<REDACTED_OAUTH_TOKEN>"
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
name: "OAUTH_REFRESH_TOKEN",
|
|
166
|
+
pattern: /\b1\/\/[A-Za-z0-9._-]+\b/g,
|
|
167
|
+
replace: () => "<REDACTED_OAUTH_REFRESH>"
|
|
168
|
+
},
|
|
159
169
|
{
|
|
160
170
|
name: "AUTH_BEARER",
|
|
161
171
|
pattern: /\bBearer\s+[A-Za-z0-9._-]+\b/g,
|
|
@@ -179,12 +189,25 @@ var init_credentials = __esm({
|
|
|
179
189
|
{
|
|
180
190
|
name: "PASSWORD",
|
|
181
191
|
pattern: /\bpassword=([^\s]+)/gi,
|
|
182
|
-
replace: (
|
|
192
|
+
replace: () => "password=<REDACTED_PASSWORD>"
|
|
193
|
+
},
|
|
194
|
+
// DB URL credential: postgres://user:pass@host
|
|
195
|
+
{
|
|
196
|
+
name: "DB_URL_CREDENTIAL",
|
|
197
|
+
pattern: /\b(postgres|mysql|mongodb):\/\/([^:\s]+):([^@\s]+)@/gi,
|
|
198
|
+
replace: (_match, _ctx, groups) => `${groups[0]}://${groups[1]}:<REDACTED_PASSWORD>@`
|
|
183
199
|
},
|
|
200
|
+
// apiKey=...
|
|
184
201
|
{
|
|
185
202
|
name: "API_KEY",
|
|
186
203
|
pattern: /\bapiKey=([A-Za-z0-9_\-]{16,})\b/g,
|
|
187
204
|
replace: () => "<REDACTED_API_KEY>"
|
|
205
|
+
},
|
|
206
|
+
// x-api-key: ....
|
|
207
|
+
{
|
|
208
|
+
name: "API_KEY_HEADER",
|
|
209
|
+
pattern: /\bx-api-key:\s*[A-Za-z0-9_\-]{16,}\b/gi,
|
|
210
|
+
replace: () => "x-api-key: <REDACTED_API_KEY>"
|
|
188
211
|
}
|
|
189
212
|
];
|
|
190
213
|
}
|
|
@@ -201,10 +224,15 @@ var init_cloud = __esm({
|
|
|
201
224
|
pattern: /\bAKIA[0-9A-Z]{16,20}\b/g,
|
|
202
225
|
replace: (match, { strict }) => strict ? "<REDACTED_AWS_KEY>" : match
|
|
203
226
|
},
|
|
227
|
+
{
|
|
228
|
+
name: "AWS_SECRET_KEY",
|
|
229
|
+
pattern: /\b[A-Za-z0-9\/+=]{40}\b/g,
|
|
230
|
+
replace: (match, { strict }) => strict ? "<REDACTED_AWS_SECRET>" : match
|
|
231
|
+
},
|
|
204
232
|
{
|
|
205
233
|
name: "STRIPE_SECRET_KEY",
|
|
206
234
|
pattern: /\b(?:LS_STRIPE_(?:TEST|LIVE)_KEY_[A-Z0-9_]{10,}|sk_(?:test|live)_[A-Za-z0-9]{16,})\b/g,
|
|
207
|
-
replace: (match,
|
|
235
|
+
replace: (match, { strict }) => strict ? "<REDACTED_STRIPE_KEY>" : match
|
|
208
236
|
}
|
|
209
237
|
];
|
|
210
238
|
}
|
|
@@ -350,21 +378,12 @@ var { readInput: readInput2 } = (init_readInput(), __toCommonJS(readInput_export
|
|
|
350
378
|
var { writeOutput: writeOutput2 } = (init_writeOutput(), __toCommonJS(writeOutput_exports));
|
|
351
379
|
var { printSummary: printSummary2 } = (init_summary(), __toCommonJS(summary_exports));
|
|
352
380
|
var { sanitizeLog: sanitizeLog2 } = (init_sanitizeLog(), __toCommonJS(sanitizeLog_exports));
|
|
353
|
-
var
|
|
354
|
-
function hasFlag(flag) {
|
|
355
|
-
return args.includes(flag);
|
|
356
|
-
}
|
|
381
|
+
var rawArgs = process.argv.slice(2);
|
|
357
382
|
function getVersion() {
|
|
358
|
-
return true ? "0.
|
|
359
|
-
}
|
|
360
|
-
function getFileArg() {
|
|
361
|
-
const file = args[1];
|
|
362
|
-
if (!file || file.startsWith("--")) return void 0;
|
|
363
|
-
return file;
|
|
383
|
+
return true ? "0.3.0" : "unknown";
|
|
364
384
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
process.stdout.write(`Usage: logshield scan [file]
|
|
385
|
+
function printHelp() {
|
|
386
|
+
process.stdout.write(`Usage: logshield scan [file]
|
|
368
387
|
|
|
369
388
|
Options:
|
|
370
389
|
--strict Aggressive redaction
|
|
@@ -373,21 +392,38 @@ Options:
|
|
|
373
392
|
--version Print version
|
|
374
393
|
--help Show help
|
|
375
394
|
`);
|
|
395
|
+
}
|
|
396
|
+
function parseArgs(args) {
|
|
397
|
+
const flags = /* @__PURE__ */ new Set();
|
|
398
|
+
const positionals = [];
|
|
399
|
+
for (const arg of args) {
|
|
400
|
+
if (arg.startsWith("--")) {
|
|
401
|
+
flags.add(arg);
|
|
402
|
+
} else {
|
|
403
|
+
positionals.push(arg);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return { flags, positionals };
|
|
407
|
+
}
|
|
408
|
+
async function main() {
|
|
409
|
+
if (rawArgs.length === 0 || rawArgs.includes("--help")) {
|
|
410
|
+
printHelp();
|
|
376
411
|
process.exit(0);
|
|
377
412
|
}
|
|
378
|
-
if (
|
|
413
|
+
if (rawArgs.includes("--version")) {
|
|
379
414
|
console.log(`logshield v${getVersion()}`);
|
|
380
415
|
process.exit(0);
|
|
381
416
|
}
|
|
382
|
-
const
|
|
417
|
+
const { flags, positionals } = parseArgs(rawArgs);
|
|
418
|
+
const command = positionals[0];
|
|
383
419
|
if (command !== "scan") {
|
|
384
420
|
process.stderr.write("Unknown command\n");
|
|
385
421
|
process.exit(1);
|
|
386
422
|
}
|
|
387
|
-
const
|
|
388
|
-
const
|
|
389
|
-
const
|
|
390
|
-
const
|
|
423
|
+
const file = positionals[1];
|
|
424
|
+
const strict = flags.has("--strict");
|
|
425
|
+
const json = flags.has("--json");
|
|
426
|
+
const summary = flags.has("--summary");
|
|
391
427
|
try {
|
|
392
428
|
const input = await readInput2(file);
|
|
393
429
|
const result = sanitizeLog2(input, { strict });
|
|
@@ -395,6 +431,7 @@ Options:
|
|
|
395
431
|
if (summary) {
|
|
396
432
|
printSummary2(result.matches);
|
|
397
433
|
}
|
|
434
|
+
process.exit(0);
|
|
398
435
|
} catch (err) {
|
|
399
436
|
process.stderr.write(err?.message || "Unexpected error");
|
|
400
437
|
process.stderr.write("\n");
|