Automated, repeatable vulnerability scanning for web applications using Playwright for authenticated browsing and OWASP ZAP for active and passive scanning. This project crawls and tests each URL in
urls.txt
, produces per-URL HTML reports inOutput/
, and can generate a consolidated CSV/Excel report.
Repository: OWASP-ZAP-Automated-Pentration-Testing-with-Playwright
Primary goals: automated authenticated scans, reproducible CI/CD runs, simple contributor workflow, and clear reports that security and QA teams can use.
Provide a production-grade automation pipeline that:
- Uses Playwright to authenticate and visit application pages (one-step auth via
global-setup.ts
producingstorageState.json
). - Launches and orchestrates OWASP ZAP sessions to spider and actively scan the authenticated surface.
- Generates human-readable HTML scan reports per URL and a unified CSV/Excel summary.
- Integrates with CI/CD (example GitHub Actions workflow included) so scans can run automatically in pipelines.
This repository is suitable for internal pentests of your own applications and for improving security QA workflows. Do not run these scans against systems you do not own or have explicit permission to test.
The project combines:
- Playwright for browser automation and authenticated sessions (
storageState.json
) so ZAP scans the application as a real user. - OWASP ZAP for passive analysis (spidering) and active scanning (attack simulations).
- Scripts to orchestrate session creation, scanning, report generation, and shutdown.
- CI/CD example (
.github/workflows/pentest.yml
) that demonstrates running scans in automation environments (using ZAP Docker or a ZAP service).
- Node.js β₯ 18 and npm β₯ 8
- Git
- Playwright (browsers installed)
- OWASP ZAP (installed locally or available as Docker image)
- Windows, macOS or Linux environment (commands below include platform variations)
git clone https://github.com/MohamedSci/OWASP-ZAP-Automated-Pentration-Testing-with-Playwright.git
cd OWASP-ZAP-Automated-Pentration-Testing-with-Playwright
npm install
Install Playwright browsers (required):
npx playwright install
Install OWASP ZAP (see next section).
You can install OWASP ZAP either via native installer (Windows/macOS/Linux) or using Docker.
-
Download ZAP from the official site: https://www.zaproxy.org/download/
-
Run the installer and install to the default path (recommended):
C:\Program Files\ZAP\Zed Attack Proxy\
-
To run ZAP in daemon/headless mode for automation, open a PowerShell/cmd and run:
cd "C:\Program Files\ZAP\Zed Attack Proxy" .\zap.bat -daemon -host 127.0.0.1 -port 8888 -config api.disablekey=true
Download the cross-platform package from the ZAP site, extract to a chosen folder, then start ZAP:
# example path /opt/zap
/opt/ZAP/zap.sh -daemon -host 127.0.0.1 -port 8888 -config api.disablekey=true
docker run -u zap -p 127.0.0.1:8888:8888 -d owasp/zap2docker-stable zap.sh -daemon -host 0.0.0.0 -port 8888 -config api.disablekey=true
Important:
-config api.disablekey=true
disables the API key requirement (use only in trusted/local/CI environments). For production use, secure the API appropriately.
Create a .env
file in project root with the credentials required for the target application:
# Example .env
LOGIN_URL=https://your-app/login
LOGIN_EMAIL=you@example.com
LOGIN_PASSWORD=yourPassword
COMMON_SELECTOR=.submit-button
ZAP_API_HOST=127.0.0.1
ZAP_API_PORT=8888
The project uses a Playwright global-setup.ts
(or equivalent script) that performs a one-step authentication sequence and stores the resulting authenticated context in storageState.json
. This file is then used by the Playwright/ZAP orchestration so scans are performed while authenticated.
How to generate storageState.json
manually (if needed):
npx playwright test --config=playwright.config.ts --project=chromium --global-setup
# or run the specific global setup script if defined
node src/PlaywrightFuns/createNewPage.js
- Ensure ZAP is running (native or Docker) and listening on the configured host/port (default
127.0.0.1:8888
). - Ensure
.env
andurls.txt
are populated. - Run the main command:
npm run zapTest
npm run zapTest
should be wired inpackage.json
to call the orchestrator/spec file. Example script you can add if not present:"scripts": { "zapTest": "node ./src/runZap.spec.js", "generate-csv": "node generate_csv.cjs" }
What happens
-
Playwright global setup will create
storageState.json
(authenticated session). -
src/runZap.spec.js
will iterate over each URL fromurls.txt
viaUtils/getListURLS.js
. -
For each URL:
src/ZAPFuns/createZapSession.js
initializes a ZAP session.src/ZAPFuns/runSpiderScan.js
runs the spider to discover links.src/ZAPFuns/runActiveScan.js
runs the active scan to find vulnerabilities.src/ZAPFuns/generateReport.js
saves a per-URL HTML report intoOutput/
.src/ZAPFuns/shuttingDownZAP.js
cleans up the session.
-
After the run,
generate_csv.cjs
can consolidate report info into a CSV/Excel format.
.
βββ src/
β βββ PlaywrightFuns/
β β βββ createNewPage.js # create browser, context, page and (optionally) generate storageState.json
β βββ ZAPFuns/
β β βββ createZapSession.js # initialize zap session and context
β β βββ delay_fun.js # helper wait/delay utilities
β β βββ generateReport.js # render/save HTML report
β β βββ runActiveScan.js # active attack scanner orchestration
β β βββ runSpiderScan.js # spider/crawl the site
β β βββ shuttingDownZAP.js # terminate zap session and cleanup
β βββ runZap.spec.js # main orchestration spec β iterates URLs and runs scans
βββ Utils/
β βββ getListURLS.js # read and return URLs from urls.txt
βββ Output/ # generated HTML reports stored here
βββ generate_csv.cjs # consolidate HTML reports -> CSV/Excel
βββ .github/
β βββ workflows/
β βββ pentest.yml # sample GitHub Actions CI workflow
βββ urls.txt # list of URLs to scan (one per line)
βββ .env # env variables: credentials, zap host/port, etc
βββ playwright.config.ts # Playwright config (global-setup, projects, timeouts)
βββ package.json # dependencies and scripts
βββ LICENSE
The repo includes a sample workflow: .github/workflows/pentest.yml
. Typical steps:
- Start ZAP (Docker image) or ensure ZAP service is available in the runner.
- Checkout code.
- Install Node.js and dependencies.
- Install Playwright browsers.
- Generate
storageState.json
(global setup). - Run the orchestrator (
npm run zapTest
). - Upload generated HTML/CSV reports as CI artifacts.
Security note: Never store production credentials in GitHub Actions unencrypted β use GitHub Secrets and inject them at runtime.
-
Per-URL HTML reports are output to
Output/
(filename convention:report-<url-slug>.html
). -
generate_csv.cjs
reads per-report data and producesreport-summary.csv
/ Excel friendly output for easy ingestion into spreadsheets or dashboards. -
Reports include:
- Alerts and risk levels
- Affected URLs and parameters
- CWE/CVSS where applicable (from ZAP)
- Scan summary and timestamps
- Only scan systems you own or have explicit, written authorization to test.
- OWASP ZAP active scanning can be intrusive: active scans may generate impactful requests (e.g., form submissions). Use against production systems with extreme caution.
- Respect rate limiting, user data privacy, and responsible disclosure policies.
- ZAP connection refused: Ensure ZAP is listening on the configured host/port and
api.disablekey
configuration matches your security posture. If using Docker, map the port correctly. - Playwright storageState missing: Run global setup or
createNewPage.js
to generatestorageState.json
before scans. - Spider/Active scan stalls: Check backend logs at
backend-api/logs/
(if your project has similar logging), and increase timeouts inplaywright.config.ts
. - Report generation errors: Verify
Output/
folder permissions and thatgenerateReport.js
can write to disk.
- Add URLs (one per line) to
urls.txt
:
https://staging.example.com/login
https://staging.example.com/dashboard
-
Set
.env
credentials for authentication. -
Start ZAP and run:
npm run zapTest
# then consolidate reports
npm run generate-csv
Contributions are welcome! Suggested workflow:
-
Fork the repo.
-
Create a branch:
git checkout -b feature/<short-desc>
-
Make changes and ensure tests / scripts still run.
-
Open a Pull Request describing:
- Purpose of change
- Security/behavior impact
- Any additional dependencies
Please follow TypeScript/JavaScript best practices and keep changes scoped. Add tests or manual verification steps for new behavior.
This project is licensed under the Apache 2.0 License. See the LICENSE
file for details.
Mohamed Said Ibrahim
- GitHub:
https://github.com/MohamedSci
- Project repo:
https://github.com/MohamedSci/OWASP-ZAP-Automated-Pentration-Testing-with-Playwright
- Use a staging/test environment for scanning, never production unless explicitly authorized.
- Secure your ZAP API in shared environments β prefer API keys or local socket access.
- Consider rate-limiting and scan windows for safer scanning approaches.
- Review ZAP and Playwright logs regularly to improve scan coverage and reduce false positives.