☼
⌃
☰

Javascript Recon and Source Analysis

Table of Contents

In a React SPA the entire application — routing logic, API endpoints, authentication flows, and sometimes secrets — ships to the browser as JavaScript. Before touching any vulnerability class, enumerate what the frontend reveals. This is the SPA- specific reconnaissance step that replaces directory brute-forcing as the primary content discovery method.

Related: React and Next.js Stack MERN Stack Web Application Testing Methodology API Testing Methodology Reconnaissance Feroxbuster

1. Initial Fingerprinting

Before fetching any JS, identify what framework and tooling you are dealing with. This determines where bundles live and what paths to target.

SHELL
# Check response headers for framework hints
curl -sI http://$IP | grep -i "x-powered-by\|server\|x-generator"
Indicator Likely stack
X-Powered-By: Next.js Next.js / React
/_next/static/ paths in source Next.js
/static/js/main.<hash>.js Create React App
__webpack_require__ in bundle Webpack-bundled SPA
window.__NUXT__ in page source Nuxt.js (Vue)
window.__NEXT_DATA__ in page Next.js SSR
SHELL
# Fetch the page source and grep for framework signals
curl -s http://$IP | grep -Ei "next\.js|react|webpack|nuxt|angular|vue"

2. Bundle Discovery

The JS bundle contains everything compiled from source. Find it before doing anything else.

Create React App layout

/static/js/main.<hash>.js        ← main application bundle
/static/js/<number>.<hash>.js    ← code-split chunks
/static/js/runtime-main.js       ← webpack runtime

Next.js layout

/_next/static/chunks/main.js
/_next/static/chunks/pages/_app.js
/_next/static/chunks/pages/index.js
/_next/static/chunks/pages/<route>.js   ← one per page
/_next/static/<build-id>/               ← build-specific assets
SHELL
# Fetch page source and extract all script src values
curl -s http://$IP | grep -oP 'src="[^"]+\.js[^"]*"' | sed 's/src="//;s/"//'

# For Next.js — list static chunks
curl -s http://$IP | grep -oP '/_next/static/[^"'\'']+\.js'

3. Source Map Extraction

Source maps (.map files) are the developer's debugging aid — they map the minified bundle back to the original source files, complete with directory structure, comments, and unminified logic. When present in production they represent a significant information disclosure: you can read the application as the developer wrote it.

Check for source maps

SHELL
# Append .map to any bundle path
curl -s http://$IP/static/js/main.abc123.js.map | head -5

# Next.js
curl -s http://$IP/_next/static/chunks/main.js.map | head -5

A valid source map starts with:

{"version":3,"sources":[...

Extract and analyse source maps

SHELL
# Download the map file
curl -s http://$IP/static/js/main.abc123.js.map -o main.js.map

# The "sources" array lists every original file path
python3 -c "
import json
with open('main.js.map') as f:
    m = json.load(f)
for s in m.get('sources', []):
    print(s)
"

The sources array reveals the full directory tree of the original project. The sourcesContent array (when present) contains the actual source of every file inline.

PYTHON
import json

with open("main.js.map") as f:
    smap = json.load(f)

sources = smap.get("sources", [])
contents = smap.get("sourcesContent", [])

for path, content in zip(sources, contents):
    if content and any(k in content for k in
                       ["password", "secret", "token", "api", "key", "auth"]):
        print(f"\n=== {path} ===")
        for line in content.splitlines():
            if any(k in line.lower() for k in
                   ["password", "secret", "token", "key", "api", "auth"]):
                print(line)

4. Searching the Bundle

When source maps are absent, search the minified bundle directly. It is less readable but still yields API endpoints, keys, and routing logic.

SHELL
# Download the bundle
curl -s http://$IP/static/js/main.abc123.js -o bundle.js

# API endpoints — look for string patterns
grep -oP '"/api/[^"]+' bundle.js | sort -u

# Hardcoded secrets and keys
grep -iP '(secret|apikey|api_key|token|password|Bearer)\s*[:=]\s*["\x27][^"'\'']+' bundle.js

# Route definitions — React Router pattern
grep -oP 'path:\s*["\x27][^"'\'']+' bundle.js | sort -u

# Fetch/axios calls reveal backend endpoints
grep -oP "(fetch|axios)\(['\"][^'\"]+['\"]" bundle.js | sort -u

5. Extracting API Endpoints Systematically

Combine multiple extraction methods to build a full API surface map before starting vulnerability testing.

SHELL
# 1. All string literals that look like API paths
grep -oP '"(/api/[^"]*)"' bundle.js | tr -d '"' | sort -u > endpoints.txt

# 2. Fetch calls
grep -oP "fetch\(['\"][^'\"]+['\"]" bundle.js \
  | grep -oP "['\"][^'\"]+['\"]" | tr -d "'\""  >> endpoints.txt

# 3. Axios calls
grep -oP "axios\.(get|post|put|delete|patch)\(['\"][^'\"]+['\"]" bundle.js \
  | grep -oP "['\"][^'\"]+['\"]" | tr -d "'\""  >> endpoints.txt

sort -u endpoints.txt

Feed this list into feroxbuster or use it as a manual testing checklist in Burp Suite.

6. Environment Variable Leakage

Developers frequently prefix client-side variables with a framework-specific marker (NEXT_PUBLIC_, REACT_APP_) and accidentally include secrets this way.

SHELL
# Next.js client-side env vars (anything NEXT_PUBLIC_ ships to browser)
grep -oP 'NEXT_PUBLIC_\w+' bundle.js | sort -u

# Create React App equivalent
grep -oP 'REACT_APP_\w+' bundle.js | sort -u

# Look for the values alongside the keys
grep -oP 'NEXT_PUBLIC_\w+["\s:=]+["\x27][^"'\'']+' bundle.js

Also check for exposed .env files directly:

SHELL
for f in .env .env.local .env.production .env.development; do
    echo "--- $f ---"
    curl -s http://$IP/$f
done

7. Authentication Logic in the Bundle

The client-side auth implementation tells you what the developer intended to protect — which routes require a token, what roles exist, what the token structure looks like.

SHELL
# Role and privilege references
grep -iP "(role|admin|isAdmin|privilege|permission)" bundle.js | head -20

# Token handling — where it is read from and sent
grep -iP "(localStorage|sessionStorage|getItem|Authorization|Bearer)" bundle.js | head -20

# Route guard logic
grep -iP "(PrivateRoute|RequireAuth|isAuthenticated|isLoggedIn)" bundle.js | head -20

This tells you exactly what client-side checks exist — and therefore what to bypass when testing API endpoints directly.

8. Methodology Checklist

Use this in sequence at the start of every SPA target.

  • [ ] Fingerprint the framework from headers and page source
  • [ ] Locate all JS bundle paths from the page HTML
  • [ ] Check every bundle path for a corresponding .map file
  • [ ] If source maps present: extract sources and sourcesContent, search for secrets and endpoints
  • [ ] If no source maps: grep the minified bundle for API paths, fetch/axios calls, and secrets
  • [ ] Check for NEXT_PUBLIC_ / REACT_APP_ env var leakage
  • [ ] Check for exposed .env files
  • [ ] Extract route definitions to understand the full app structure
  • [ ] Note all auth-related code: token storage location, role checks, route guards
  • [ ] Feed discovered API endpoints into Burp Suite target scope
  • [ ] Validate each API endpoint independently — not just what the UI calls

Tips

  • Always do JS recon before directory brute-forcing a SPA — the bundle usually gives you the full API surface in minutes
  • Source maps in production are an immediate finding: Information Disclosure, Medium severity at minimum; High if secrets are exposed in the content
  • The gap between what the UI renders and what the API exposes is where the most interesting vulnerabilities live — find both
  • window.__NEXT_DATA__ on Next.js SSR pages contains the server-rendered props as JSON in the page source — read it before fetching any bundles
  • On the exam: if you find an API endpoint in the bundle that the UI never calls, test it — it is likely either an admin route or a deprecated endpoint with weaker controls