-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add fetchZAPResults.sh script to download ZAP reports from a URL #450
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Downloads a ZAP XML report from a URL and saves it to the results/ directory. | ||
| # After downloading, run createScorecards.sh to generate the scorecard. | ||
| # | ||
| # Usage: scripts/fetchZAPResults.sh <ZAP_REPORT_URL> [OUTPUT_FILENAME] | ||
| # | ||
| # Examples: | ||
| # scripts/fetchZAPResults.sh http://172.17.0.3:8090/OTHER/core/other/xmlreport/ | ||
| # scripts/fetchZAPResults.sh "http://zap:8090/OTHER/core/other/xmlreport/?apikey=abc123" | ||
| # scripts/fetchZAPResults.sh http://zap:8090/OTHER/core/other/xmlreport/ my-zap-results.xml | ||
|
|
||
| source scripts/requireCommand.sh | ||
|
|
||
| requireCommand curl | ||
|
|
||
| if [ $# -eq 0 ]; then | ||
| echo "Usage: $0 <ZAP_REPORT_URL> [OUTPUT_FILENAME]" | ||
| echo "" | ||
| echo "Downloads a ZAP XML report from the given URL and saves it to results/." | ||
| echo "After downloading, run createScorecards.sh to generate the scorecard." | ||
| echo "" | ||
| echo "Examples:" | ||
| echo " $0 http://172.17.0.3:8090/OTHER/core/other/xmlreport/" | ||
| echo " $0 \"http://zap:8090/OTHER/core/other/xmlreport/?apikey=abc123\"" | ||
| echo " $0 http://zap:8090/OTHER/core/other/xmlreport/ my-zap-results.xml" | ||
| exit 1 | ||
| fi | ||
|
|
||
| zap_url="$1" | ||
|
|
||
| if [ $# -ge 2 ]; then | ||
| filename="$2" | ||
| else | ||
| benchmark_version=$(scripts/getBenchmarkVersion.sh) | ||
| date_stamp=$(date +%Y%m%d) | ||
| filename="Benchmark_${benchmark_version}-ZAP-${date_stamp}.xml" | ||
| fi | ||
|
|
||
| output="results/${filename}" | ||
|
|
||
| echo "Downloading ZAP report from: ${zap_url}" | ||
| http_code=$(curl -sS -o "${output}" -w '%{http_code}' --connect-timeout 10 --max-time 120 "${zap_url}") | ||
|
||
|
|
||
| if [ "${http_code}" -ne 200 ]; then | ||
| echo "ERROR: Download failed with HTTP status ${http_code}" | ||
|
||
| rm -f "${output}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if ! head -2 "${output}" | grep -q "OWASPZAPReport"; then | ||
| echo "ERROR: Downloaded file does not appear to be a ZAP XML report." | ||
| echo "First 3 lines of downloaded content:" | ||
| head -3 "${output}" | ||
| rm -f "${output}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "ZAP report saved to: ${output}" | ||
| echo "To generate the scorecard, run: ./createScorecards.sh" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing
?apikey=abc123as part of the URL argument exposes the API key in the process list (ps auxor/proc/$PID/cmdline). Consider accepting the key as a separate argument and passing it via curl's-Hflag instead:This keeps the key out of the argument list. The existing
?apikey=query-param form can still be documented as an alternative for ZAP versions that require it in the URL.