Skip to content

Commit

Permalink
Merge pull request #74 from Onboardbase/redaction
Browse files Browse the repository at this point in the history
feat: optionally mask rawValue inside scanResult
  • Loading branch information
iamnasirudeen authored Feb 4, 2025
2 parents 3c20ec5 + bad991c commit 368bd8d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 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.21",
"version": "3.0.22",
"description": "A CLI tool to scan codebases for potential secrets.",
"main": "dist/index.js",
"author": {
Expand Down
15 changes: 15 additions & 0 deletions src/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ export const maskAndRedactSensitiveData = async (
const { scan } = detector;
const scanResponse = await scan(false, options.rawValue as string);
if (scanResponse && scanResponse.rawValue) {
/***
* this replaces the secrets in the string to a masked one should incase there
* are multiple secrets in the string, it replaces them one by one based on how
* many secrets was detected
*/
modifiedValue = modifiedValue?.replaceAll(
scanResponse.rawValue as string,
maskString(scanResponse.rawValue as string, {
Expand All @@ -61,6 +66,16 @@ export const maskAndRedactSensitiveData = async (
})
);

/**
* this masks the rawValue thats inside the scanResult based on the user option
*/
if (options.maskSecretRawValue) {
scanResponse.rawValue = maskString(scanResponse.rawValue as string, {
maskValue: options.maskedValue,
visibleChars: options.visibleChars,
});
}

return scanResponse;
}
})
Expand Down
5 changes: 3 additions & 2 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface ScanStringOptions {
maskedValue?: string;
visibleChars?: number;
customDetectors?: DetectorConfig[];
maskSecretRawValue?: boolean;
}

export interface DecayOptions {
Expand Down Expand Up @@ -94,10 +95,10 @@ export interface DataFormat {
}

export type RedactionPattern = {
pattern: string; // RE2 compatible pattern
pattern: string; // RE2 compatible pattern
replacement: string;
description?: string;
}
};

export type RedactionConfig = {
[key: string]: RedactionPattern;
Expand Down

0 comments on commit 368bd8d

Please sign in to comment.