Skip to content

How to Define Context in OWASP ZAP

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Define Context in OWASP ZAP. We cover key concepts, practical examples, and best practices.

Your ZAP context does not include the URLs you are testing, or authentication is not applied within the context. Context configuration determines which URLs are in scope.

The Wrong Way

# Scanning a URL that is not in the default context
# ZAP ignores out-of-scope URLs

Without proper context, ZAP may skip scanning the most important endpoints.

The Right Way

Step 1: Create a new context

# ZAP → Contexts → "+" → New Context
# Name: "Target App"

Step 2: Include the target URLs

# Context → "Include in Context" → Add
# URL: https://target.example.com/.*
# Regex: .* matches all paths

# Also:
# Context → "Exclude from Context" → Add
# URL: https://target.example.com/logout
# This prevents ZAP from logging out during scanning

Step 3: Configure context authentication

# Context → Authentication → "Form-based Authentication"
# Login URL: https://target.example.com/login
# Username field: username
# Password field: password
# Logged-in regex: \bLogout\b
# Logged-out regex: \blogin\b

Step 4: Define context users

# Context → Users → Add
# Username: testuser
# Password: testpass123
# Set as "Forced User" for scanning
Context "Target App" configured — 47 URLs in scope, form-based auth works, scan covers authenticated endpoints.

Prevention

  • Create a dedicated context for each application you test, not the default context.
  • Use URL regex patterns to precisely define the scope boundary.
  • The context isolation pattern parallels Doda Browser's profile system — separate contexts prevent cross-contamination of authentication states.

Common Mistakes with zap context define

  1. Mixing let bindings with <- bindings in do notation, producing type errors
  2. Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
  3. Non-exhaustive pattern matches that compile with warnings then crash at runtime

These mistakes appear frequently in real-world OWASP code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why are some URLs skipped during ZAP scanning?

Those URLs are not in the active context's "Include in Context" list. Either add them to the context or set them as "In Scope" from the Sites tree. Right-click the URL → "Include in Context" → select the context.

How does ZAP know when a user is logged in?

ZAP checks the "Logged-in regex" against page content. If the page matches the regex, ZAP considers the session authenticated. Configure this carefully — a regex that is too broad or narrow breaks authentication handling.

Can I use multiple contexts in one ZAP session?

Yes. Each context can have different scope, authentication, and user settings. Use different contexts for different applications or for different roles within the same application (admin, user, guest).

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro