Here’s a structured, clean documentation you can include in your platform guide for ZAP authentication verification. I’ve organized it by method, typical application type, and recommended usage.
ZAP Authentication Verification Methods Documentation
ZAP provides multiple methods to verify whether authentication has succeeded during automated scans. Choosing the correct verification method is critical, especially for modern Single Page Applications (SPAs) and API-driven backends.
1. Verification Methods Overview
| Method | Description | Typical Usage | Key Parameters |
|---|---|---|---|
| autodetect | ZAP attempts to automatically determine which responses indicate successful login based on cookies, session tokens, headers, or form submissions. | Only reliable for traditional web apps with standard session cookies (e.g., PHPSESSID, JSESSIONID) or form-based logins. | None (automatic) |
| response | Matches a specified regex against responses within the authenticated context to determine login success. | Suitable for SPAs or apps where backend APIs return predictable messages upon successful login. | loggedInRegex – regex to match a successful response.pollFrequency / pollUnits – how often to check responses. |
| poll | Makes requests to a specific URL at a defined frequency and checks the response body against a regex. | Recommended for SPAs or API-driven apps where the frontend URL differs from the backend authentication endpoint. | pollUrl – the URL to poll.loggedInRegex – regex to match authenticated response.pollFrequency / pollUnits. |
Conclusion:
pollis the most reliable verification method across all types of applications. When properly configured with apollUrlpointing to a protected endpoint, it works consistently for SPAs, server-rendered apps, hybrid apps, and API-driven apps.responseworks well for JSON-based authentication or predictable backend responses, but may fail if frontend and backend domains differ or if redirects occur.autodetectis the least reliable and should be avoided for SPAs, API-driven apps, and hybrid applications. It is only suitable for traditional server-rendered apps with standard session cookies or simple form-based logins.
Recommendation: Prefer poll wherever possible. Use response only when polling is not feasible and autodetect only for legacy MPA/form-based logins.
2. Application Type Guidance
2.1 Browser-based Authentication
-
Method to Use:
poll(preferred) orresponse -
When to Use: SPA frontend where login is performed via JavaScript and backend APIs handle authentication.
-
Notes:
autodetectoften fails for SPAs because it cannot reliably match tokens or cookies across frontend and backend endpoints.- Even if frontend route differs from backend API,
responseworks as long as the regex matches any response in the authenticated context. - For higher reliability, provide an explicit
pollUrlpointing to a stable backend endpoint that confirms authentication.
Important Notes for Browser-based Authentication in SPA / Multi-domain Applications:
- The primary host in the context must always be the frontend URL, because browser-based authentication will attempt to load the login page using a browser. If the backend API is set as the primary host, authentication will fail since the browser cannot directly load API endpoints.
- The context can include multiple hosts (an array), but ZAP reports authentication results based on the first host (primary host) in the context.
- If the backend API domain is different from the frontend domain, verification via regex may fail because ZAP only evaluates responses within the current context domain.
- To handle this reliably, provide an explicit
pollUrlpointing to a backend endpoint that confirms successful authentication. This avoids relying onautodetector response checks against mismatched domains.
2.2 JSON / API-based Authentication
-
Method to Use:
responseorpoll -
When to Use: REST APIs or AJAX endpoints that return JSON responses with authentication status.
-
Notes:
- Specify the backend API URL explicitly using
pollUrlfor SPAs. - Use
loggedInRegexor JSON path references (e.g.,Authorizationheader) for validation. autodetectmay fail because ZAP cannot infer login success from JSON alone without guidance.
- Specify the backend API URL explicitly using
2.3 Form-based / HTML Authentication
-
Method to Use:
form(traditional HTML login form) -
When to Use: Legacy web applications with server-rendered login forms.
-
Notes:
autodetectcan sometimes work if the session mechanism is standard, but it is not fully reliable.- Using response-based verification may fail for apps like DVWA that redirect (302) immediately after login without returning a usable response body, or set cookies server-side.
- Poll-based verification is generally more reliable for form-based authentication. Set a
pollUrlpointing to a page that requires authentication. - Ensure the
pollUrlorloggedInRegexpoints to a page visible only to logged-in users.
Recommendation: For most form-based HTML applications, prefer poll-based verification. Response-based verification is optional and may fail on redirects or when login responses do not contain identifiable content.
3. Best Practices
-
Always prefer explicit verification over autodetect, especially for modern SPAs and API-driven apps.
-
Use
pollUrlfor SPAs:- Points directly to a backend API endpoint that reliably confirms authentication (e.g.,
/api/users/me). - Reduces false negatives compared to
autodetect.
- Points directly to a backend API endpoint that reliably confirms authentication (e.g.,
-
Use
responseverification for browser-based authentication:- Provide a regex matching a known success indicator in API or HTML response.
-
Reserve
autodetectfor legacy or simple HTML login forms:- May work with standard session cookies but is unreliable for JSON or SPA-based flows.
-
Always test verification settings before running full automated scans:
- Check the
auth-summarysection in the auth-report. - Look for
Verification URL identified: trueto confirm ZAP recognized authentication.
- Check the
4. Recommended Verification Flow for SPAs
- Configure authentication (browser or JSON method).
- Set verification to response or poll.
- For JSON/SPA: explicitly provide backend URL (pollUrl).
- Define
loggedInRegexbased on a reliable success message or JSON property. - Run a small test scan and check the auth-report summary.
5. ZAP’s autodetect heuristics
ZAP’s autodetect looks for changes in session state or the presence of tokens, not strictly HTML responses.
If a login request returns a set-cookie header, an Authorization header, or any session token, ZAP may detect it as “successful login” even without a full HTML page.
Juice Shop’s /rest/user/login returns a JWT in JSON. ZAP apparently can detect the Authorization header being set or session token being present.
6. Summary
- SPAs / AJAX-heavy applications: Prefer
pollorresponsewith explicit URL/regex. - JSON API-based authentication: Explicit backend URL with
pollorresponse. - HTML form login:
formverification orautodetectif standard session cookies exist. - Autodetect is not reliable for SPA applications and should generally be avoided.