How to Define Context in OWASP ZAP
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
- Mixing let bindings with <- bindings in do notation, producing type errors
- Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
- 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
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro