Skip to content

Commit 1aef4f1

Browse files
committed
feat(web-app-template): Handle scan results excluded due to path includes
Signed-off-by: Nicolas Nobelis <[email protected]>
1 parent 1bbe4ed commit 1aef4f1

File tree

5 files changed

+73
-8
lines changed

5 files changed

+73
-8
lines changed

plugins/reporters/web-app-template/src/components/PackageFindingsTable.jsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const PackageFindingsTable = ({ webAppPackage }) => {
5252
key: finding.key,
5353
path: finding.path,
5454
pathExcludes: finding.pathExcludes,
55+
isExcludedByPathIncludes: finding.isExcludedByPathIncludes,
5556
pathExcludeReasonsText: Array.from(finding.pathExcludeReasons).join(', '),
5657
startLine: finding.startLine,
5758
value: finding.value
@@ -124,7 +125,7 @@ const PackageFindingsTable = ({ webAppPackage }) => {
124125
<span className="ort-excludes">
125126
<Tooltip
126127
placement="right"
127-
title={record.pathExcludeReasonsText}
128+
title={record.isExcludedByPathIncludes? Array.from(webAppPackage.pathIncludeReasons).join(', ') : record.pathExcludeReasonsText}
128129
>
129130
<FileExcelOutlined className="ort-excluded" />
130131
</Tooltip>
@@ -138,11 +139,19 @@ const PackageFindingsTable = ({ webAppPackage }) => {
138139
});
139140

140141
expandable = {
141-
expandedRowRender: (webAppFinding) => (
142-
<PathExcludesTable
143-
excludes={webAppFinding.pathExcludes}
144-
/>
145-
),
142+
expandedRowRender: (webAppFinding) => {
143+
if (webAppFinding.isExcludedByPathIncludes) {
144+
return (<PathExcludesTable
145+
excludes={webAppPackage.pathIncludes}
146+
isIncludes={true}
147+
/>)
148+
} else {
149+
return (<PathExcludesTable
150+
excludes={webAppFinding.pathExcludes}
151+
/>)
152+
}
153+
154+
},
146155
expandIcon: (obj) => {
147156
const { expanded, onExpand, record } = obj;
148157

plugins/reporters/web-app-template/src/components/PathExcludesTable.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,18 @@
2020
import { Table } from 'antd';
2121

2222
// Generates the HTML to display webAppPathExclude(s) as a table
23-
const PathExcludesTable = ({ excludes }) => {
23+
const PathExcludesTable = ({ excludes, isIncludes = false }) => {
2424
const columns = [
2525
{
2626
dataIndex: 'reason',
2727
key: 'reason',
28-
title: 'Reason'
28+
title: 'Reason',
29+
30+
render: (text) => (
31+
<>
32+
{text} {isIncludes && <i>(includes)</i>}
33+
</>
34+
)
2935
},
3036
{
3137
dataIndex: 'pattern',

plugins/reporters/web-app-template/src/models/WebAppFinding.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ class WebAppFinding {
3232

3333
#pathExcludes;
3434

35+
#isExcludedByPathIncludes;
36+
3537
#pathExcludeIndexes = new Set();
3638

3739
#pathExcludeReasons;
40+
#pathIncludeReasons;
3841

3942
#startLine;
4043

@@ -63,11 +66,18 @@ class WebAppFinding {
6366
}
6467

6568
const pathExcludes = obj.path_excludes || obj.pathExcludes;
69+
6670
if (Array.isArray(pathExcludes) && pathExcludes.length > 0) {
6771
this.#pathExcludeIndexes = new Set(pathExcludes);
6872
this.#isExcluded = true;
6973
}
7074

75+
const isExcludedByPathIncludes = obj.isExcludedByPathIncludes || obj.is_excluded_by_path_includes;
76+
if (isExcludedByPathIncludes) {
77+
this.#isExcludedByPathIncludes = true;
78+
this.#isExcluded = true;
79+
}
80+
7181
if (Number.isInteger(obj.start_line) || Number.isInteger(obj.startLine)) {
7282
this.#startLine = obj.start_line || obj.startLine;
7383
}
@@ -155,6 +165,10 @@ class WebAppFinding {
155165
return this.#pathExcludeReasons;
156166
}
157167

168+
get isExcludedByPathIncludes() {
169+
return this.#isExcludedByPathIncludes;
170+
}
171+
158172
get startLine() {
159173
return this.#startLine;
160174
}

plugins/reporters/web-app-template/src/models/WebAppOrtResult.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ class WebAppOrtResult {
8080

8181
#pathExcludes = [];
8282

83+
#pathIncludes = [];
84+
85+
#pathIncludeReasons;
86+
8387
#paths = [];
8488

8589
#projects = [];
@@ -180,6 +184,14 @@ class WebAppOrtResult {
180184
}
181185
}
182186

187+
if (obj.path_includes || obj.pathIncludes) {
188+
const pathIncludes = obj.path_includes || obj.pathIncludes;
189+
190+
for (let i = 0, len = pathIncludes.length; i < len; i++) {
191+
this.#pathIncludes.push(new WebAppPathExclude(pathIncludes[i]));
192+
}
193+
}
194+
183195
if (obj.paths) {
184196
const { paths } = obj;
185197
for (let i = 0, len = paths.length; i < len; i++) {
@@ -447,6 +459,22 @@ class WebAppOrtResult {
447459
return this.#pathExcludes;
448460
}
449461

462+
get pathIncludes() {
463+
return this.#pathIncludes;
464+
}
465+
466+
get pathIncludeReasons() {
467+
if (!this.#pathIncludeReasons) {
468+
if (Array.isArray(this.#pathIncludes) && this.#pathIncludes.length > 0) {
469+
this.#pathIncludeReasons = new Set(this.#pathIncludes.map((value) => value.reason))
470+
} else {
471+
this.#pathIncludeReasons = new Set();
472+
}
473+
}
474+
475+
return this.#pathIncludeReasons;
476+
}
477+
450478
get paths() {
451479
return this.#paths;
452480
}

plugins/reporters/web-app-template/src/models/WebAppPackage.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,10 @@ class WebAppPackage {
411411
return new Set([...pathExcludeReasons, ...scopeExcludeReasons]);
412412
}
413413

414+
get pathIncludeReasons() {
415+
return this.#webAppOrtResult.pathIncludeReasons
416+
}
417+
414418
get excludedFindings() {
415419
if (!this.#excludedFindings) {
416420
this.#excludedFindings = [];
@@ -477,6 +481,10 @@ class WebAppPackage {
477481
return this.#pathExcludes;
478482
}
479483

484+
get pathIncludes() {
485+
return this.#webAppOrtResult.pathIncludes;
486+
}
487+
480488
get pathExcludeIndexes() {
481489
return this.#pathExcludeIndexes;
482490
}

0 commit comments

Comments
 (0)