From 8ecfe79d7e496373adf87567f1314e4ab943f7ad Mon Sep 17 00:00:00 2001 From: Nasirudeen Olohundare Date: Fri, 22 Nov 2024 02:54:13 +0100 Subject: [PATCH] feat: 3.0.13 --- package.json | 2 +- src/fileScanner.ts | 10 +++++++--- src/types/index.ts | 2 ++ src/util.ts | 13 +++++++++---- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 2cb5864..5986fb5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "securelog-scan", - "version": "3.0.12", + "version": "3.0.13", "description": "A CLI tool to scan codebases for potential secrets.", "main": "dist/index.js", "author": { diff --git a/src/fileScanner.ts b/src/fileScanner.ts index 281f864..f50c1dd 100644 --- a/src/fileScanner.ts +++ b/src/fileScanner.ts @@ -3,7 +3,7 @@ import path from "path"; import { isBinaryFile, maskString, getLineNumber } from "./util"; import { AhoCorasickCore } from "./ahocorasick"; import { MAX_FILE_SIZE } from "./constants"; -import { ScanDirectoryOptions, ScanOptions, ScanStringOptions } from "./types"; +import { ScanDirectoryOptions, ScanStringOptions } from "./types"; import { EventManager } from "./events"; import { Detector, EScannerTypes } from "./types/detector"; @@ -31,7 +31,8 @@ export const processPossibleSecretsInString = async ( options: ScanStringOptions, core?: AhoCorasickCore ) => { - const { rawValue, file, updateFile, outputFile } = options; + const { rawValue, file, updateFile, outputFile, maskedValue, visibleChars } = + options; if (!rawValue || (rawValue === "" && !file)) { console.error("A rawValue or file has to be passed"); @@ -56,7 +57,10 @@ export const processPossibleSecretsInString = async ( if (scanResponse) { modifiedValue = modifiedValue.replaceAll( scanResponse.rawValue as string, - maskString(scanResponse.rawValue as string) + maskString(scanResponse.rawValue as string, { + maskValue: maskedValue, + visibleChars, + }) ); } }) diff --git a/src/types/index.ts b/src/types/index.ts index d856ed0..e614a07 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -19,6 +19,8 @@ export interface ScanStringOptions { updateFile?: boolean; config?: string; outputFile?: string; + maskedValue?: string; + visibleChars?: number; } export interface Config { diff --git a/src/util.ts b/src/util.ts index c714374..1e516fc 100644 --- a/src/util.ts +++ b/src/util.ts @@ -76,7 +76,12 @@ export const formatBytes = (bytes: number, decimals: number = 2): string => { return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`; }; -export const maskString = (str: string, visibleChars: number = 5): string => { +export const maskString = ( + str: string, + options?: { maskValue?: string; visibleChars?: number } +): string => { + const visibleChars = options?.visibleChars ?? 5; + if (typeof str !== "string" || str.length === 0) { throw new Error("Invalid input: Input must be a non-empty string."); } @@ -90,9 +95,9 @@ export const maskString = (str: string, visibleChars: number = 5): string => { } // make the masked chars only 10 characters - const maskedPart = "*".repeat( - str.length < 10 ? str.length : 10 - visibleChars - ); + const maskedPart = + options?.maskValue ?? + "*".repeat(str.length < 10 ? str.length : 10 - visibleChars); const visiblePart = str.slice(0, visibleChars); return visiblePart + maskedPart; };