Skip to content

Commit 356de69

Browse files
Merge pull request #63 from Onboardbase/post-sdk-updates
feat: shared utils
2 parents 718b405 + 011bf69 commit 356de69

File tree

3 files changed

+51
-17
lines changed

3 files changed

+51
-17
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "securelog-scan",
3-
"version": "3.0.13",
3+
"version": "3.0.14",
44
"description": "A CLI tool to scan codebases for potential secrets.",
55
"main": "dist/index.js",
66
"author": {

src/fileScanner.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,6 @@ export const processPossibleSecretsInString = async (
7878
if (!core) return modifiedValue;
7979
};
8080

81-
export const scanStringAndReturnJson = async (options: ScanStringOptions) => {
82-
const core = new AhoCorasickCore();
83-
const detectors = core.findMatchingDetectors(options.rawValue as string);
84-
const response = await Promise.all(
85-
detectors.map(async (detector) => {
86-
const { scan } = detector;
87-
const scanResponse = await scan(false, options.rawValue as string);
88-
if (scanResponse) {
89-
return scanResponse;
90-
}
91-
})
92-
);
93-
94-
return response;
95-
};
96-
9781
/**
9882
* Processes possible secrets and checks for matches.
9983
*/

src/shared/index.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* All methods here are supposed to be used on the SDK
3+
* and other securelog libraries
4+
*/
5+
6+
import { AhoCorasickCore } from "../ahocorasick";
7+
import { ScanStringOptions } from "../types";
8+
import { maskString } from "../util";
9+
10+
export const redactSensitiveData = async (options: ScanStringOptions) => {
11+
const core = new AhoCorasickCore();
12+
const detectors = core.findMatchingDetectors(options.rawValue as string);
13+
let modifiedValue = options.rawValue;
14+
15+
const secrets = await Promise.all(
16+
detectors.map(async (detector) => {
17+
const { scan } = detector;
18+
const scanResponse = await scan(false, options.rawValue as string);
19+
if (scanResponse) {
20+
modifiedValue = modifiedValue?.replaceAll(
21+
scanResponse.rawValue as string,
22+
maskString(scanResponse.rawValue as string, {
23+
maskValue: options.maskedValue,
24+
visibleChars: options.visibleChars,
25+
})
26+
);
27+
28+
return scanResponse;
29+
}
30+
})
31+
);
32+
33+
return { rawValue: modifiedValue, secrets };
34+
};
35+
36+
export const scanStringAndReturnJson = async (options: ScanStringOptions) => {
37+
const core = new AhoCorasickCore();
38+
const detectors = core.findMatchingDetectors(options.rawValue as string);
39+
const response = await Promise.all(
40+
detectors.map(async (detector) => {
41+
const { scan } = detector;
42+
const scanResponse = await scan(false, options.rawValue as string);
43+
if (scanResponse) {
44+
return scanResponse;
45+
}
46+
})
47+
);
48+
49+
return response;
50+
};

0 commit comments

Comments
 (0)