Skip to content

Commit

Permalink
Merge pull request #61 from Onboardbase/post-git-rewrite
Browse files Browse the repository at this point in the history
feat: 3.0.13
  • Loading branch information
iamnasirudeen authored Nov 22, 2024
2 parents c83d745 + 8ecfe79 commit 6e5fb16
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
10 changes: 7 additions & 3 deletions src/fileScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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");
Expand All @@ -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,
})
);
}
})
Expand Down
2 changes: 2 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export interface ScanStringOptions {
updateFile?: boolean;
config?: string;
outputFile?: string;
maskedValue?: string;
visibleChars?: number;
}

export interface Config {
Expand Down
13 changes: 9 additions & 4 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand All @@ -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;
};
Expand Down

0 comments on commit 6e5fb16

Please sign in to comment.