Skip to content

Test for failure and more complex vulnapi arguments #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 87 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ jobs:
id: npm-ci-test
run: npm run ci-test

test-action:
name: GitHub Actions Test
test-failed-scans:
name: GitHub Actions Test Failed Scans
runs-on: ubuntu-latest

permissions:
contents: read
packages: read

env:
DOCKER_IMAGE: ghcr.io/cerberauth/api-vulns-challenges/jwt-strong-eddsa-key:latest
DOCKER_IMAGE: ghcr.io/cerberauth/api-vulns-challenges/jwt-alg-none-bypass:latest

steps:
- name: Checkout
Expand All @@ -66,24 +66,97 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get JWT
id: get-jwt
run: |
echo "jwt=$(docker run --rm ${{ env.DOCKER_IMAGE }} jwt)" >> $GITHUB_OUTPUT

- name: Run Server
run: |
docker run -d -p 8080:8080 ${{ env.DOCKER_IMAGE }}
sleep 5
curl --verbose http://localhost:8080
curl --verbose http://localhost:8080 -H "Authorization: Bearer ${{ steps.get-jwt.outputs.jwt }}"

- name: Test cURL Local Action
uses: ./
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
scans: jwt.*
curl: |
http://localhost:8080 -H "Authorization: Bearer ${{ steps.get-jwt.outputs.jwt }}"

- name: Check for vulnerabilities
if: ${{ success() }}
run: |
echo "No vulnerabilities found"
exit 1

- name: Test OpenAPI Local Action
uses: ./
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
scans: jwt.*
openapi: ./__tests__/openapi.yaml

- name: Stop Server
if: ${{ always() }}
run:
docker stop $(docker ps -q --filter ancestor=${{ env.DOCKER_IMAGE }})

test-scans:
name: GitHub Actions Test Scans
runs-on: ubuntu-latest

permissions:
contents: read
packages: read

env:
DOCKER_IMAGE: ghcr.io/cerberauth/api-vulns-challenges/jwt-strong-eddsa-key:latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get JWT
id: get-jwt
run: |
echo "jwt=$(docker run --rm ${{ env.DOCKER_IMAGE }} jwt)" >> $GITHUB_OUTPUT

- name: Test cURL Local Action
- name: Run Server
run: |
docker run -d -p 8080:8080 ${{ env.DOCKER_IMAGE }}
sleep 5
curl --verbose http://localhost:8080 -H "Authorization: Bearer ${{ steps.get-jwt.outputs.jwt }}"

- name: Test cURL Local Action with rate limit and excluded scans
uses: ./
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
rateLimit: 1000/s
excludeScans: discover.*
curl: |
http://localhost:8080 -H "Authorization: Bearer ${{ steps.get-jwt.outputs.jwt }}"

- name: Test cURL Local Action with selected scans
uses: ./
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
scans: jwt.*
curl: |
curl http://localhost:8080 -H "Authorization: Bearer ${{ steps.get-jwt.outputs.jwt }}"
http://localhost:8080 -H "Authorization: Bearer ${{ steps.get-jwt.outputs.jwt }}"

- name: Test cURL Local Action without Telemetry
uses: ./
Expand All @@ -92,17 +165,17 @@ jobs:
with:
scans: jwt.*
curl: |
curl http://localhost:8080 -H "Authorization: Bearer ${{ steps.get-jwt.outputs.jwt }}"
http://localhost:8080 -H "Authorization: Bearer ${{ steps.get-jwt.outputs.jwt }}"
telemetry: false

# - name: Test OpenAPI Local Action
# uses: ./
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# scans: jwt.*
# openapi: ./__tests__/openapi.yaml
# telemetry: false
- name: Test OpenAPI Local Action
uses: ./
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
scans: jwt.*
openapi: ./__tests__/openapi.yaml
telemetry: false

- name: Stop Server
if: ${{ always() }}
Expand Down
1 change: 0 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ inputs:
rateLimit:
description: 'The rate limit used to run API vulnerability scans'
required: false
default: 10/s

telemetry:
description:
Expand Down
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.
19 changes: 11 additions & 8 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.

19 changes: 11 additions & 8 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ const { installVersion } = require('./installer')

function getArgsFromInput(input) {
const inputArgs = parseArgs(input)
debug(`Parsed input args: ${JSON.stringify(inputArgs)}`)
return Object.entries(inputArgs).flatMap(([key, value]) => {
if (key === '_') {
return value
}

if (key.length === 1) {
return `-${key} ${value}`
return `-${key}="${value}"`
}

return `--${key}=${value}`
return `--${key}="${value}"`
})
}

Expand All @@ -34,17 +35,17 @@ function getCommonArgs() {

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

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

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

const severityThreshold = getInput('severityThreshold')
Expand Down Expand Up @@ -74,11 +75,13 @@ async function run() {
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, ...commonArgs])
debug(
`Running vulnapi scan with curl: ${JSON.stringify(args)} ${JSON.stringify(commonArgs)}`
)
await exec('vulnapi', ['scan', 'curl', ...args, ...commonArgs])
} else if (openapi) {
debug(`Running vulnapi scan with openapi: ${openapi}`)
await exec('vulnapi scan openapi', [openapi, ...commonArgs])
await exec('vulnapi', ['scan', 'openapi', openapi, ...commonArgs])
} else {
setFailed('You must provide curl or openapi input')
}
Expand Down
Loading