Skip to main content

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

1

Clone or Navigate to Your Codebase

2

Run Whitebox Pentest

Use the --cwd flag to enable whitebox mode:
3

Review Results

Apex will:
  • Analyze your source code to map all endpoints
  • Identify authentication and authorization logic
  • Generate pentest objectives for each route
  • Test discovered endpoints against the live target
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:
From the CLI implementation:

Whitebox Attack Surface Discovery

When cwd is provided, Apex uses the WhiteboxAttackSurfaceAgent instead of the blackbox agent:
The whitebox agent performs a deterministic workflow:
1

Repository Analysis

Identify the repository structure:
  • Monorepo vs single app
  • Package manager (npm, yarn, pnpm, bun)
  • Framework detection (Next.js, Express, FastAPI, Django, etc.)
2

App Discovery

Find all apps/services in the codebase:
  • Web frontends
  • API services
  • Background workers
  • Microservices
3

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
4

Objective Generation

Generate pentest objectives for each endpoint:
  • Input validation testing
  • Authentication bypass attempts
  • Authorization checks (BOLA, privilege escalation)
  • Business logic flaws

Agent Architecture

The agent uses specialized coding subagents (via spawn_coding_agent) to analyze each app in parallel, providing high-fidelity endpoint extraction.

Whitebox vs Blackbox

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

Apex will:
  1. Detect the Next.js framework from package.json and file structure
  2. Parse app/ or pages/ directory to find all routes
  3. Extract API routes from app/api/ or pages/api/
  4. Identify server actions and their authentication
  5. Test each endpoint against the live staging URL

Testing a Monorepo

Apex will:
  1. Detect the monorepo structure (Nx, Turborepo, Lerna, etc.)
  2. Discover all apps in apps/ or packages/
  3. Spawn parallel coding agents to analyze each app
  4. Aggregate results into a unified attack surface map
  5. Prioritize high-value targets for testing

Testing an Express API

Apex will:
  1. Read your Express route definitions (app.get, app.post, etc.)
  2. Extract middleware (authentication, validation)
  3. Map all endpoints with their HTTP methods
  4. Generate test cases for each route
  5. Test against your local dev server

Best Practices

1. Use Whitebox for Pre-Deployment Reviews

Run whitebox tests before merging to production. This catches vulnerabilities at the code level before they’re exposed externally.

2. Provide Both Source and Live Target

Whitebox mode requires both --cwd and --target:
  • --cwd tells Apex where to read your source code
  • --target tells Apex where to test the discovered endpoints

3. Use Version Control

Ensure your codebase is under version control (Git) for best results:
Apex may use Git metadata to understand the repository structure.

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:
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:
  1. Ensure you have a package.json (JS/TS) or similar manifest
  2. Check that the --cwd path points to the repository root
  3. Verify the directory contains source code (not a build output folder)

“No apps discovered”

Cause: Apex couldn’t find any application entrypoints. Solution:
  1. For monorepos, ensure apps are in standard locations (apps/, packages/)
  2. For single apps, ensure there’s a clear entrypoint (index.js, main.py, etc.)
  3. Check that your framework is supported

”Whitebox analysis timed out”

Cause: The codebase is very large or complex. Solution:
  1. Use a smaller scope—point --cwd to a specific app subdirectory
  2. Increase timeouts in your session configuration
  3. Split monorepo analysis into multiple runs (one per app)

Combining Whitebox and Blackbox

Strategy: Use whitebox for discovery, blackbox for validation
  1. Phase 1: Whitebox Discovery
    Result: Complete endpoint map from source code.
  2. Phase 2: Blackbox Testing
    Result: Validate that production behaves as expected (no extra exposed endpoints).
  3. 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