For developers
An automatic scan after every deployment
One workflow file scans your site after every successful deployment and every week, and fails the GitHub Actions job when the score falls below the bar you choose. It needs only curl and jq, which every runner has.
Before you start: an API key
- Create a free Kashef account.
- On the Developers page of the dashboard, create an API key (owners and admins). The full key is shown only once.
- Put it in an environment variable named KASHEF_API_KEY, and never in a file that goes into Git.
Setup
- In the repository: Settings, then Secrets and variables, then Actions, then New repository secret. Name it KASHEF_API_KEY and paste the key.
- Add the file below to the repository as .github/workflows/kashef.yml and change TARGET to your site’s address.
GitHub Actions workflow
It runs after every successful deployment and every week, and fails when the security score is below MIN_SCORE. Every scan uses one scan of your monthly quota. Change the address in TARGET to match your site.
.github/workflows/kashef.yml
name: Kashef scan
on:
deployment_status:
schedule:
- cron: '0 6 * * 1' # every Monday, 06:00 UTC
jobs:
scan:
# After a successful deployment, or on the schedule.
if: github.event_name == 'schedule' || github.event.deployment_status.state == 'success'
runs-on: ubuntu-latest
env:
KASHEF_API_KEY: ${{ secrets.KASHEF_API_KEY }}
# The URL GitHub reports for the deployment. The weekly run has none, so put your site's address here.
TARGET: ${{ github.event.deployment_status.environment_url || 'https://example.com' }}
MIN_SCORE: '80'
steps:
- name: Scan with Kashef
run: |
set -euo pipefail
API='https://kashef.scouthub.dev/api/v1'
body=$(jq -n --arg target "$TARGET" '{target: $target, authorizationConfirmed: true}')
scan=$(curl -fsS -X POST "$API/scans" \
-H "x-api-key: $KASHEF_API_KEY" \
-H 'content-type: application/json' \
-H "Idempotency-Key: $GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT" \
-H 'x-kashef-client: github-action' \
-H "x-kashef-repository: $GITHUB_REPOSITORY" \
-d "$body")
id=$(echo "$scan" | jq -r '.scan.id')
for _ in $(seq 1 24); do
result=$(curl -fsS -H "x-api-key: $KASHEF_API_KEY" "$API/scans/$id?wait=25")
status=$(echo "$result" | jq -r '.scan.status')
[ "$status" = completed ] && break
if [ "$status" = failed ] || [ "$status" = cancelled ]; then
echo "The scan $status."
exit 2
fi
done
[ "$status" = completed ] || { echo 'Timed out waiting for the scan.'; exit 2; }
score=$(echo "$result" | jq -r '.scan.score')
grade=$(echo "$result" | jq -r '.scan.grade')
echo "Security score: $score ($grade)"
[ "$score" != null ] && [ "$score" -ge "$MIN_SCORE" ] || { echo "Below MIN_SCORE ($MIN_SCORE)."; exit 1; }
Failing the job on new problems only
Instead of a score bar, send the gate field with the scan request: Kashef judges when the scan completes and returns scan.gateResult.passed with reasons under stable codes. failOn: "new-findings" compares with the latest full scan of the same site, and ignoreLab leaves out lab measurements that vary from run to run.
POST /api/v1/scans
{
"target": "example.com",
"authorizationConfirmed": true,
"gate": {
"failOn": "new-findings",
"minSeverity": "issue",
"ignoreLab": true
}
}Notes
- Preview URLs get a passive scan only, because the domain is not verified. Protected previews on Vercel need a bypass token.
- Start with a minimum close to your current score and raise it gradually as you fix findings.
- The repository appears under "Connected repositories" after the first scan arrives from the file.
