Skip to content

Commit

Permalink
feat(githubaction): fail with error 2 if vulnerabilities are detected
Browse files Browse the repository at this point in the history
Enables the (calling) github action be marked 'fail' when
vulnerabilities are found.
  • Loading branch information
mattorb committed Feb 3, 2020
1 parent 7db3ca9 commit 5127705
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bin/is-website-vulnerable.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function getLighthouseOptions() {
: new RenderConsole(results, argv.jsLib)
renderer.print()

process.exit(0)
if (audit.hasVulnerabilities(results)) process.exit(2)
else process.exit(0)
} catch (error) {
console.error(`\nError: ${error.message}\n`)
console.error('Usage:\n is-website-vulnerable https://www.google.com\n\n')
Expand Down
14 changes: 14 additions & 0 deletions src/Audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ module.exports = class Audit {
}
}

hasVulnerabilities(scanResult) {
const vulnerableAudit = scanResult.lhr.audits['no-vulnerable-libraries']

if (
vulnerableAudit.details &&
vulnerableAudit.details.items &&
vulnerableAudit.details.items.length > 0
) {
return true
}

return false
}

async scanUrl(url, options = { lighthouseOpts: {}, chromeOpts: {} }, progress = false) {
const optflags = options.lighthouseOpts
const chromePath = (options.chromeOpts || {}).chromePath
Expand Down

0 comments on commit 5127705

Please sign in to comment.