Skip to content

Commit

Permalink
feat(githubaction): adapt for use as a github action (#65)
Browse files Browse the repository at this point in the history
Uses the existing docker container

The 'scan-url' GitHub workflow argument is explicitly mapped to the
SCAN_URL environment variable already expected&handled by the docker
container.

This enables the Dockerfile to remain agnostic to the fact that it is
running as a Github action, rather than depending on the 'INPUT_'
GitHub Action variable naming.
  • Loading branch information
mattorb committed Feb 3, 2020
1 parent d0c8cfe commit b2355a3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,23 @@ docker run --rm -e SCAN_URL="https://www.google.com/" lirantal/is-website-vulner

:warning: A modern version of Chrome is assumed to be available when using `is-website-vulnerable`. It may not be safe to assume that this is satisfied automatically on some CI services. For example, [additional configuration](https://docs.travis-ci.com/user/chrome#selecting-a-chrome-version) is necessary for [Travis CI](https://travis-ci.com/).

# Github Action
Create .github/workflows/is-website-vulnerable.yml with the url that you want scanned:

```
name: Test site for publicly known js vulnerabilities
on: push
jobs:
security:
runs-on: ubuntu-latest
steps:
- name: Test for public javascript library vulnerabilities
uses: lirantal/is-website-vulnerable@master
with:
scan-url: "https://yoursite.com"
```

# Install

You can install globally via:
Expand Down
11 changes: 11 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: 'Is Website vulnerable'
description: 'Scans a url for public javascript library vulnerabilities'
inputs:
scan-url:
description: 'Website url to scan'
required: true
runs:
using: 'docker'
image: 'Dockerfile'
env:
SCAN_URL: ${{ inputs.scan-url }}
4 changes: 4 additions & 0 deletions bin/is-website-vulnerable.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ function getLighthouseOptions() {
: new RenderConsole(results, argv.jsLib)
renderer.print()

if (audit.hasVulnerabilities(results)) {
process.exit(2)
}

process.exit(0)
} catch (error) {
console.error(`\nError: ${error.message}\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 b2355a3

Please sign in to comment.