Skip to content

Commit 3783c98

Browse files
aaronshimdevversion
authored andcommitted
bugfix: numCspViolations shouldn't count violations from loader script
1 parent 1cd74c2 commit 3783c98

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

runner/ratings/stats.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,23 @@ export function calculateBuildAndCheckStats(
8686
}
8787
}
8888
securityStats ??= { appsWithErrors: 0, appsWithoutErrors: 0 };
89-
const numCspViolations = (result.build.cspViolations || []).length;
89+
const { numCspViolations, numTrustedTypesViolations } = (
90+
result.build.cspViolations || []
91+
).reduce(
92+
(acc, v) => {
93+
if (v['blocked-uri'] === 'trusted-types-sink') {
94+
acc.numTrustedTypesViolations++;
95+
} else {
96+
acc.numCspViolations++;
97+
}
98+
return acc;
99+
},
100+
{ numCspViolations: 0, numTrustedTypesViolations: 0 }
101+
);
102+
90103
const hasSafetyViolations =
91104
(result.build.safetyWebReportJson?.[0]?.violations?.length ?? 0) > 0;
92-
105+
// TODO: Consider numTrustedTypesViolations once we update autoCsp and re-enable the rating.
93106
if (hasSafetyViolations || numCspViolations > 0) {
94107
securityStats.appsWithErrors++;
95108
} else {

0 commit comments

Comments
 (0)