FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix Bug with Subfinder Parser includeTargetDomain flag for empty results by J12934 · Pull Request #3506 · secureCodeBox/secureCodeBox · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (2) .snap  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -604,3 +604,24 @@ exports[`should properly parse subfinder json file and add target domain to find
},
]
`;

exports[`should properly parse empty json file with includeTargetDomain=true 1`] = `
[
{
"attributes": {
"domain": "example.com",
"hostname": "example.com",
"ip_address": null,
"ip_addresses": [],
"source": "parser",
},
"category": "Subdomain",
"description": "Found subdomain example.com",
"identified_at": null,
"location": "example.com",
"name": "example.com",
"osi_layer": "NETWORK",
"severity": "INFORMATIONAL",
},
]
`;
12 changes: 7 additions & 5 deletions scanners/subfinder/parser/parser.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const DOMAIN_FLAGS = ["-d", "-domain", "--domain"];
export async function parse(
fileContent,
scan,
includeTargetDomain = process.env["INCLUDE_TARGET_DOMAIN"]?.toLowerCase() ==
"true",
options = {},
) {
if (!fileContent && !includeTargetDomain) return [];
const includeTargetDomain = options.includeTargetDomain ??
(process.env["INCLUDE_TARGET_DOMAIN"]?.toLowerCase() === "true");

const targets = parseResultFile(fileContent);
const findings = transformToFindings(targets);
Expand Down Expand Up @@ -92,8 +92,10 @@ function transformToFindings(targets) {
* @param {*} fileContent
*/
function parseResultFile(fileContent) {
return fileContent
.trim()
const trimmed = fileContent.trim();
if (!trimmed) return [];

return trimmed
.split("\n")
.map((line) => JSON.parse(line));
}
29 changes: 26 additions & 3 deletions scanners/subfinder/parser/parser.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,29 @@ test("should properly parse empty json file", async () => {
expect(findings).toMatchSnapshot();
});

test("should properly parse empty json file with includeTargetDomain=true", async () => {
const scan = {
spec: {
scanType: "subfinder",
parameters: ["-timeout", "1", "-d", "example.com"],
},
metadata: {
annotations: {
"metadata.scan.securecodebox.io/subfinder":
"https://github.com/secureCodeBox/secureCodeBox",
},
},
};

const fileContent = await readFile(__dirname + "/__testFiles__/empty.jsonl", {
encoding: "utf8",
});
const findings = await parse(fileContent, scan, { includeTargetDomain: true });
// validate findings
expect(validateParser(findings)).toBeUndefined();
expect(findings).toMatchSnapshot();
});

test("should properly parse subfinder json file and add target domain to findings with param -d", async () => {
const scan = {
spec: {
Expand All @@ -62,7 +85,7 @@ test("should properly parse subfinder json file and add target domain to finding
encoding: "utf8",
},
);
const findings = await parse(fileContent, scan, "true");
const findings = await parse(fileContent, scan, { includeTargetDomain: true });
// validate findings
expect(validateParser(findings)).toBeUndefined();
expect(findings).toMatchSnapshot();
Expand All @@ -88,7 +111,7 @@ test("should properly parse subfinder json file and add target domain to finding
encoding: "utf8",
},
);
const findings = await parse(fileContent, scan, "true");
const findings = await parse(fileContent, scan, { includeTargetDomain: true });
// validate findings
expect(validateParser(findings)).toBeUndefined();
expect(findings).toMatchSnapshot();
Expand All @@ -114,7 +137,7 @@ test("should properly parse subfinder json file and add target domain to finding
encoding: "utf8",
},
);
const findings = await parse(fileContent, scan, "true");
const findings = await parse(fileContent, scan, { includeTargetDomain: true });
// validate findings
expect(validateParser(findings)).toBeUndefined();
expect(findings).toMatchSnapshot();
Expand Down
Loading

Back | FazBrowse Home | New Git URL