From aaf988a1e2f1066df54df5bd4f358db6e0e595c0 Mon Sep 17 00:00:00 2001 From: Jannik Hollenbach Date: Tue, 10 Feb 2026 09:57:11 +0100 Subject: [PATCH 1/3] Add test for empty result files with includeTargetDomain flag set to true Signed-off-by: Jannik Hollenbach --- scanners/subfinder/parser/parser.test.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scanners/subfinder/parser/parser.test.js b/scanners/subfinder/parser/parser.test.js index 90c761b122..7eda01afd0 100644 --- a/scanners/subfinder/parser/parser.test.js +++ b/scanners/subfinder/parser/parser.test.js @@ -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, "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: { From c98a88a3357b50a0ab2f6c143599614375170e0b Mon Sep 17 00:00:00 2001 From: Jannik Hollenbach Date: Tue, 10 Feb 2026 09:57:34 +0100 Subject: [PATCH 2/3] Fix bug when the results are empty but the includeTargetDomain is set Signed-off-by: Jannik Hollenbach --- .../parser/__snapshots__/parser.test.js.snap | 21 +++++++++++++++++++ scanners/subfinder/parser/parser.js | 8 +++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/scanners/subfinder/parser/__snapshots__/parser.test.js.snap b/scanners/subfinder/parser/__snapshots__/parser.test.js.snap index 840f42518e..e35673f89f 100644 --- a/scanners/subfinder/parser/__snapshots__/parser.test.js.snap +++ b/scanners/subfinder/parser/__snapshots__/parser.test.js.snap @@ -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", + }, +] +`; diff --git a/scanners/subfinder/parser/parser.js b/scanners/subfinder/parser/parser.js index 2afdfc93ce..ffde45b733 100644 --- a/scanners/subfinder/parser/parser.js +++ b/scanners/subfinder/parser/parser.js @@ -10,8 +10,6 @@ export async function parse( includeTargetDomain = process.env["INCLUDE_TARGET_DOMAIN"]?.toLowerCase() == "true", ) { - if (!fileContent && !includeTargetDomain) return []; - const targets = parseResultFile(fileContent); const findings = transformToFindings(targets); @@ -92,8 +90,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)); } From aaf3b066b7a975b8bd4e50cdbed6f2260989b693 Mon Sep 17 00:00:00 2001 From: Jannik Hollenbach Date: Tue, 10 Feb 2026 09:59:38 +0100 Subject: [PATCH 3/3] Move param to a named param in a object Makes it easier to understand what this bool flag is doing from the tests Signed-off-by: Jannik Hollenbach --- scanners/subfinder/parser/parser.js | 6 ++++-- scanners/subfinder/parser/parser.test.js | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/scanners/subfinder/parser/parser.js b/scanners/subfinder/parser/parser.js index ffde45b733..6c5be9b787 100644 --- a/scanners/subfinder/parser/parser.js +++ b/scanners/subfinder/parser/parser.js @@ -7,9 +7,11 @@ const DOMAIN_FLAGS = ["-d", "-domain", "--domain"]; export async function parse( fileContent, scan, - includeTargetDomain = process.env["INCLUDE_TARGET_DOMAIN"]?.toLowerCase() == - "true", + options = {}, ) { + const includeTargetDomain = options.includeTargetDomain ?? + (process.env["INCLUDE_TARGET_DOMAIN"]?.toLowerCase() === "true"); + const targets = parseResultFile(fileContent); const findings = transformToFindings(targets); diff --git a/scanners/subfinder/parser/parser.test.js b/scanners/subfinder/parser/parser.test.js index 7eda01afd0..8fc20c91b8 100644 --- a/scanners/subfinder/parser/parser.test.js +++ b/scanners/subfinder/parser/parser.test.js @@ -59,7 +59,7 @@ test("should properly parse empty json file with includeTargetDomain=true", asyn const fileContent = await readFile(__dirname + "/__testFiles__/empty.jsonl", { 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(); @@ -85,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(); @@ -111,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(); @@ -137,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();