Overview
Whitebox testing with Pensar Apex provides full source code access to the AI agent, enabling deep static analysis of your application’s attack surface before deployment. Unlike blackbox testing, whitebox analysis directly reads your codebase to understand routes, endpoints, authentication logic, and data flows. This approach is ideal for:- Pre-deployment security reviews - catch vulnerabilities before code reaches production
- Shift-left security - integrate security testing early in the development lifecycle
- Comprehensive coverage - discover all endpoints, including those not exposed externally
- CI/CD integration - automate security checks in your build pipeline
Quick Start
The
--target URL is still required in whitebox mode—Apex uses it to test discovered endpoints against your live staging/dev environment.How Whitebox Testing Works
The --cwd Flag
The --cwd (current working directory) flag signals Apex to perform source code analysis instead of external reconnaissance:
Whitebox Attack Surface Discovery
Whencwd is provided, Apex uses the WhiteboxAttackSurfaceAgent instead of the blackbox agent:
Repository Analysis
Identify the repository structure:
- Monorepo vs single app
- Package manager (npm, yarn, pnpm, bun)
- Framework detection (Next.js, Express, FastAPI, Django, etc.)
App Discovery
Find all apps/services in the codebase:
- Web frontends
- API services
- Background workers
- Microservices
Endpoint Mapping
For each app, use coding agents to extract:
- All API routes and their HTTP methods
- Web pages and their URL paths
- Authentication requirements
- Authorization logic
- Input validation rules
Agent Architecture
spawn_coding_agent) to analyze each app in parallel, providing high-fidelity endpoint extraction.
Whitebox vs Blackbox
| Feature | Blackbox | Whitebox |
|---|---|---|
| Source Code Access | ❌ No | ✅ Yes (via --cwd) |
| Discovery Method | External probing (HTTP requests, port scans) | Static analysis (reads files directly) |
| Speed | Slower (network latency) | Faster (local filesystem) |
| Coverage | Only exposed endpoints | All endpoints (including internal/undocumented) |
| Accuracy | May miss hidden endpoints | Complete endpoint mapping |
| Use Case | Production/staging testing | Pre-deployment security review |
| Best For | External security posture | Code-level vulnerability detection |
Whitebox testing is faster and more comprehensive because it doesn’t rely on fuzzing or guessing endpoints—it reads your code directly.
Example Workflows
Testing a Next.js App
- Detect the Next.js framework from
package.jsonand file structure - Parse
app/orpages/directory to find all routes - Extract API routes from
app/api/orpages/api/ - Identify server actions and their authentication
- Test each endpoint against the live staging URL
Testing a Monorepo
- Detect the monorepo structure (Nx, Turborepo, Lerna, etc.)
- Discover all apps in
apps/orpackages/ - Spawn parallel coding agents to analyze each app
- Aggregate results into a unified attack surface map
- Prioritize high-value targets for testing
Testing an Express API
- Read your Express route definitions (
app.get,app.post, etc.) - Extract middleware (authentication, validation)
- Map all endpoints with their HTTP methods
- Generate test cases for each route
- Test against your local dev server
Best Practices
1. Use Whitebox for Pre-Deployment Reviews
2. Provide Both Source and Live Target
Whitebox mode requires both--cwd and --target:
--cwdtells Apex where to read your source code--targettells Apex where to test the discovered endpoints
3. Use Version Control
Ensure your codebase is under version control (Git) for best results:4. Exclude Sensitive Files
If your codebase contains secrets or PII in test fixtures:Apex never sends source code to AI providers—it runs local static analysis tools and only sends structured metadata (endpoint names, HTTP methods) to the AI.
5. Review Whitebox Results
Whitebox analysis outputs structured JSON with complete endpoint maps:Supported Frameworks
Apex’s whitebox analysis supports:| Language | Frameworks |
|---|---|
| JavaScript/TypeScript | Next.js, Express, Fastify, NestJS, Remix |
| Python | FastAPI, Django, Flask |
| Go | Gin, Echo, Chi |
| Ruby | Rails, Sinatra |
| PHP | Laravel, Symfony |
| Java | Spring Boot |
Framework support is constantly expanding. If your framework isn’t listed, Apex will still attempt generic route extraction.
Troubleshooting
”Could not determine repository type”
Cause: Apex couldn’t identify the project structure. Solution:- Ensure you have a
package.json(JS/TS) or similar manifest - Check that the
--cwdpath points to the repository root - Verify the directory contains source code (not a build output folder)
“No apps discovered”
Cause: Apex couldn’t find any application entrypoints. Solution:- For monorepos, ensure apps are in standard locations (
apps/,packages/) - For single apps, ensure there’s a clear entrypoint (
index.js,main.py, etc.) - Check that your framework is supported
”Whitebox analysis timed out”
Cause: The codebase is very large or complex. Solution:- Use a smaller scope—point
--cwdto a specific app subdirectory - Increase timeouts in your session configuration
- Split monorepo analysis into multiple runs (one per app)
Combining Whitebox and Blackbox
Strategy: Use whitebox for discovery, blackbox for validation-
Phase 1: Whitebox Discovery
Result: Complete endpoint map from source code.
-
Phase 2: Blackbox Testing
Result: Validate that production behaves as expected (no extra exposed endpoints).
-
Compare Results
- Whitebox found 47 endpoints in the code
- Blackbox found 52 endpoints externally
- Investigation: What are the 5 extra endpoints? Old code? Misconfigurations?
CI/CD Integration
GitHub Actions Example
GitLab CI Example
Next Steps
Blackbox Testing
Learn external testing without source code
Authentication
Configure credentials for authenticated endpoints
Docker Setup
Run Apex in a containerized environment
vLLM Setup
Use local models for offline whitebox analysis

