Skip to content

Commit

Permalink
Don't fail in CSPGlobalCheck if CSP is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
baltpeter committed Jul 3, 2020
1 parent 321a061 commit ed1f2c6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/finder/checks/GlobalChecks/CSPGlobalCheck.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as attributes from '../../attributes';
import * as csp from '@doyensec/csp-evaluator';
import logger from 'winston';

export default class CSPGlobalCheck {

Expand All @@ -23,9 +24,16 @@ export default class CSPGlobalCheck {
// There is a CSP set
var confidence = 0;
for (var cspIssue of cspIssues) {
var parser = new csp.CspParser(cspIssue.properties.CSPstring);
var evaluator = new csp.CspEvaluator(parser.csp, csp.Version.CSP3);
var findings = evaluator.evaluate();
var findings;
try {
var parser = new csp.CspParser(cspIssue.properties.CSPstring);
var evaluator = new csp.CspEvaluator(parser.csp, csp.Version.CSP3);
findings = evaluator.evaluate();
}
catch (e) {
logger.warn(`Parsing the CSP '${cspIssue.properties.CSPstring}' failed: ${e.message}`);
continue;
}
for (var finding of findings)
if (finding.severity === csp.severities.HIGH || finding.severity === csp.severities.MEDIUM)
confidence = 2;
Expand Down

0 comments on commit ed1f2c6

Please sign in to comment.