logshield-cli 0.2.8 → 0.3.0

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.
Files changed (2) hide show
  1. package/dist/cli/index.cjs +61 -25
  2. package/package.json +1 -1
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env node
2
- #!/usr/bin/env node
3
2
  "use strict";
4
3
  var __create = Object.create;
5
4
  var __defProp = Object.defineProperty;
@@ -109,9 +108,9 @@ var init_summary = __esm({
109
108
  function applyRules(input, rules, ctx, matches) {
110
109
  let output = input;
111
110
  for (const rule of rules) {
112
- output = output.replace(rule.pattern, (...args2) => {
113
- const match = args2[0];
114
- const groups = args2.slice(1, -2);
111
+ output = output.replace(rule.pattern, (...args) => {
112
+ const match = args[0];
113
+ const groups = args.slice(1, -2);
115
114
  const replaced = rule.replace(match, ctx, groups);
116
115
  if (replaced !== match) {
117
116
  matches.push({
@@ -157,6 +156,16 @@ var init_tokens = __esm({
157
156
  pattern: /\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/g,
158
157
  replace: () => "<REDACTED_JWT>"
159
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
+ },
160
169
  {
161
170
  name: "AUTH_BEARER",
162
171
  pattern: /\bBearer\s+[A-Za-z0-9._-]+\b/g,
@@ -180,12 +189,25 @@ var init_credentials = __esm({
180
189
  {
181
190
  name: "PASSWORD",
182
191
  pattern: /\bpassword=([^\s]+)/gi,
183
- replace: (_match, _value, _ctx) => "password=<REDACTED_PASSWORD>"
192
+ replace: () => "password=<REDACTED_PASSWORD>"
184
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>@`
199
+ },
200
+ // apiKey=...
185
201
  {
186
202
  name: "API_KEY",
187
203
  pattern: /\bapiKey=([A-Za-z0-9_\-]{16,})\b/g,
188
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>"
189
211
  }
190
212
  ];
191
213
  }
@@ -202,10 +224,15 @@ var init_cloud = __esm({
202
224
  pattern: /\bAKIA[0-9A-Z]{16,20}\b/g,
203
225
  replace: (match, { strict }) => strict ? "<REDACTED_AWS_KEY>" : match
204
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
+ },
205
232
  {
206
233
  name: "STRIPE_SECRET_KEY",
207
234
  pattern: /\b(?:LS_STRIPE_(?:TEST|LIVE)_KEY_[A-Z0-9_]{10,}|sk_(?:test|live)_[A-Za-z0-9]{16,})\b/g,
208
- replace: (match, ctx) => ctx.strict ? "<REDACTED_STRIPE_KEY>" : match
235
+ replace: (match, { strict }) => strict ? "<REDACTED_STRIPE_KEY>" : match
209
236
  }
210
237
  ];
211
238
  }
@@ -351,21 +378,12 @@ var { readInput: readInput2 } = (init_readInput(), __toCommonJS(readInput_export
351
378
  var { writeOutput: writeOutput2 } = (init_writeOutput(), __toCommonJS(writeOutput_exports));
352
379
  var { printSummary: printSummary2 } = (init_summary(), __toCommonJS(summary_exports));
353
380
  var { sanitizeLog: sanitizeLog2 } = (init_sanitizeLog(), __toCommonJS(sanitizeLog_exports));
354
- var args = process.argv.slice(2);
355
- function hasFlag(flag) {
356
- return args.includes(flag);
357
- }
381
+ var rawArgs = process.argv.slice(2);
358
382
  function getVersion() {
359
- return true ? "0.2.8" : "unknown";
360
- }
361
- function getFileArg() {
362
- const file = args[1];
363
- if (!file || file.startsWith("--")) return void 0;
364
- return file;
383
+ return true ? "0.3.0" : "unknown";
365
384
  }
366
- async function main() {
367
- if (hasFlag("--help") || args.length === 0) {
368
- process.stdout.write(`Usage: logshield scan [file]
385
+ function printHelp() {
386
+ process.stdout.write(`Usage: logshield scan [file]
369
387
 
370
388
  Options:
371
389
  --strict Aggressive redaction
@@ -374,21 +392,38 @@ Options:
374
392
  --version Print version
375
393
  --help Show help
376
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();
377
411
  process.exit(0);
378
412
  }
379
- if (hasFlag("--version")) {
413
+ if (rawArgs.includes("--version")) {
380
414
  console.log(`logshield v${getVersion()}`);
381
415
  process.exit(0);
382
416
  }
383
- const command = args[0];
417
+ const { flags, positionals } = parseArgs(rawArgs);
418
+ const command = positionals[0];
384
419
  if (command !== "scan") {
385
420
  process.stderr.write("Unknown command\n");
386
421
  process.exit(1);
387
422
  }
388
- const strict = hasFlag("--strict");
389
- const json = hasFlag("--json");
390
- const summary = hasFlag("--summary");
391
- const file = getFileArg();
423
+ const file = positionals[1];
424
+ const strict = flags.has("--strict");
425
+ const json = flags.has("--json");
426
+ const summary = flags.has("--summary");
392
427
  try {
393
428
  const input = await readInput2(file);
394
429
  const result = sanitizeLog2(input, { strict });
@@ -396,6 +431,7 @@ Options:
396
431
  if (summary) {
397
432
  printSummary2(result.matches);
398
433
  }
434
+ process.exit(0);
399
435
  } catch (err) {
400
436
  process.stderr.write(err?.message || "Unexpected error");
401
437
  process.stderr.write("\n");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "logshield-cli",
3
- "version": "0.2.8",
3
+ "version": "0.3.0",
4
4
  "type": "commonjs",
5
5
  "bin": {
6
6
  "logshield": "dist/cli/index.cjs"