Skip to content

Commit

Permalink
feat: add most of the vulnapi common args
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelgautier committed Oct 4, 2024
1 parent b7c1db2 commit 7cc0d6b
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 14 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,17 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
scans: jwt.*
curl: |
curl http://localhost:8080 -H "Authorization: Bearer ${{ steps.get-jwt.outputs.jwt }}" --scans "jwt.*"
# - name: Test OpenAPI Local Action
# uses: ./
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# openapi: ./__tests__/openapi.yaml
curl http://localhost:8080 -H "Authorization: Bearer ${{ steps.get-jwt.outputs.jwt }}"
- name: Test OpenAPI Local Action
uses: ./
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
scans: jwt.*
openapi: ./__tests__/openapi.yaml

- name: Stop Server
if: ${{ always() }}
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ jobs:
| ------- | -------- | --------------------------------------- | ------- |
| openapi | false | The OpenAPI file location (path or URL) | |

### VulnAPI Supported Flags

| Name | Required | Description | Default |
| ----------------- | -------- | --------------------------------------------------- | ------- |
| scans | false | The scans performed. | all |
| excludeScans | false | The scans to exclude. | |
| rateLimit | false | The rate limit used to run API vulnerability scans. | 10/s |
| proxy | false | The proxy server used during the scan. | |
| severityThreshold | false | The severity threshold to trigger a failure. | 0 |

## Outputs

Scan results are output to the console.
Expand Down
21 changes: 21 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@ inputs:
description: 'The OpenAPI file used to run API vulnerability scans'
required: false

scans:
description: 'The scans performed'
required: false

excludeScans:
description: 'The scans to exclude'
required: false

rateLimit:
description: 'The rate limit used to run API vulnerability scans'
required: false
default: 10/s

proxy:
description: 'The proxy server used during the scan'
required: false

severityThreshold:
description: 'The severity threshold to trigger a failure'
required: false

runs:
using: node20
main: dist/index.js
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 35 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

37 changes: 35 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,37 @@ function getArgsFromInput(input) {
})
}

function getCommonArgs() {
const commonArgs = []

const rateLimit = getInput('rateLimit')
if (rateLimit) {
commonArgs.push(`--rate-limit=${rateLimit}`)
}

const scans = getInput('scans')
if (scans) {
commonArgs.push(`--scans=${scans}`)
}

const excludeScans = getInput('excludeScans')
if (excludeScans) {
commonArgs.push(`--exclude-scans=${excludeScans}`)
}

const proxy = getInput('proxy')
if (proxy) {
commonArgs.push(`--proxy=${proxy}`)
}

const severityThreshold = getInput('severityThreshold')
if (severityThreshold) {
commonArgs.push(`--severity-threshold=${severityThreshold}`)
}

return commonArgs
}

async function run() {
try {
const version = getInput('version')
Expand All @@ -30,17 +61,19 @@ async function run() {
addPath(installDir)
info('vulnapi has been added to the PATH')

const commonArgs = getCommonArgs()

const curl = getInput('curl')
const openapi = getInput('openapi')
if (curl) {
debug(`Parsing curl input: ${curl}`)
const args = getArgsFromInput(curl.replace('curl ', ''))

debug(`Running vulnapi scan with curl: ${JSON.stringify(args)}`)
await exec('vulnapi scan curl', args)
await exec('vulnapi scan curl', [...commonArgs, ...args])
} else if (openapi) {
debug(`Running vulnapi scan with openapi: ${openapi}`)
await exec('vulnapi scan openapi', [openapi])
await exec('vulnapi scan openapi', [...commonArgs, openapi])
} else {
setFailed('You must provide curl or openapi input')
}
Expand Down

0 comments on commit 7cc0d6b

Please sign in to comment.