How do you run authenticated scans with ZAP?

IntermediateConceptOWASP ZAP
Answer

Short answer

Most of an app is behind login, so an unauthenticated scan only sees the login page. Configure ZAP with a context describing how to log in (form, JSON, script or header/token), a test user, and logged-in/out indicators so ZAP can stay logged in while spidering and scanning.

Options

Method When
Header injection (replacer) APIs with bearer tokens or API keys
Form-based / JSON-based auth Classic login forms or JSON login endpoints
Browser-based auth Modern SPAs with complex login flows
Script-based auth Custom flows (MFA bypass for test users, OAuth)

Automation Framework example (YAML)

env:
  contexts:
    - name: shop
      urls: ["https://staging.shop.example.com"]
      authentication:
        method: json
        parameters:
          loginPageUrl: https://staging.shop.example.com/login
          loginRequestUrl: https://staging.shop.example.com/api/auth/login
          loginRequestBody: '{"email":"{%username%}","password":"{%password%}"}'
        verification:
          method: response
          loggedInRegex: '"authenticated":true'
      users:
        - name: tester
          credentials: { username: "[email protected]", password: "${DAST_PASSWORD}" }
jobs:
  - type: spider
    parameters: { context: shop, user: tester }
  - type: activeScan
    parameters: { context: shop, user: tester }
  - type: report
    parameters: { template: traditional-html, reportDir: /zap/wrk }
docker run --rm -v $(pwd):/zap/wrk ghcr.io/zaproxy/zaproxy:stable zap.sh -cmd -autorun /zap/wrk/zap-plan.yaml

What to say in the interview

"Authenticated scanning needs a context with the login method, a dedicated test user and logged-in indicators. For APIs I inject a bearer token; for apps I use the Automation Framework with JSON, form or browser-based auth, credentials coming from CI secrets."

All Security Tools questions Roadmap: OWASP ZAP — dynamic testing (DAST)

More on OWASP ZAP