Skip to content

Commit 0471226

Browse files
committed
Cascading Scans: add cloneDeep in order to preserver original cascading rule between matched findings
Signed-off-by: Jop Zitman <jop-zitman@hotmail.com>
1 parent 9628753 commit 0471226

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎hooks/cascading-scans/hook/hook.test.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,16 @@ test("should properly parse template values in scanLabels and scanAnnotations",
659659
}
660660

661661
const findings = [
662+
{
663+
name: "Port 8443 is open",
664+
category: "Open Port",
665+
attributes: {
666+
state: "open",
667+
hostname: "foobar.com",
668+
port: 8443,
669+
service: "https"
670+
}
671+
},
662672
{
663673
name: "Port 443 is open",
664674
category: "Open Port",
@@ -678,6 +688,8 @@ test("should properly parse template values in scanLabels and scanAnnotations",
678688
sslyzeCascadingRules[0]
679689
);
680690

691+
expect(sslyzeCascadingRules[0].spec.scanSpec.parameters).toEqual(["--regular", "{{$.hostOrIP}}:{{attributes.port}}"])
692+
681693
const { labels, annotations } = cascadedScans[0].metadata;
682694

683695
// No snapshots as scanLabels/scanAnnotations can be in any order

‎hooks/cascading-scans/hook/hook.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// SPDX-License-Identifier: Apache-2.0
44

5-
import { isMatch, isMatchWith, isString, mapValues } from "lodash";
5+
import { isMatch, isMatchWith, isString, mapValues, cloneDeep } from "lodash";
66
import { isMatch as wildcardIsMatch } from "matcher";
77
import * as Mustache from "mustache";
88

@@ -105,7 +105,8 @@ function getCascadingScan(
105105
finding: Finding,
106106
cascadingRule: CascadingRule
107107
) {
108-
cascadingRule = templateCascadingRule(parentScan, finding, cascadingRule);
108+
// Make a deep copy of the original cascading rule so that we can template it again with different findings.
109+
cascadingRule = templateCascadingRule(parentScan, finding, cloneDeep(cascadingRule));
109110

110111
let { scanType, parameters } = cascadingRule.spec.scanSpec;
111112

0 commit comments

Comments
 (0)