JavaScript API Endpoint Extraction Methodology
In a separate front-end/back-end architecture, the JS bundle is the largest source of information about API endpoints — 10 times more efficient than directory scanning.
⛔ Further Reading (Must Read)
- JS analysis regex library + extraction scripts → references/js-extract-patterns.md
Phase 1: JS File Collection
1.1 Collect from the Page HTML
# Grab every JS reference in the page
curl -s "$TARGET" | grep -oE '(src|href)="[^"]*\.js[^"]*"' | sed 's/.*="\(.*\)"/\1/'
# Recursive crawl (including iframes/dynamic loading)
curl -s "$TARGET" | grep -oP '(?:src|href|url)\s*[=:]\s*["\x27]([^"\x27]*\.js[^"\x27]*)["\x27]' | sort -u
1.2 Recover from Source Maps
# Check the sourceMappingURL at the end of the JS file
curl -s "$TARGET/static/js/app.xxx.js" | tail -1
# If there is //# sourceMappingURL=app.xxx.js.map
curl -s "$TARGET/static/js/app.xxx.js.map" -o sourcemap.json
# A source map exposes the full source code — equivalent to obtaining the front-end source
1.3 Collect from the Webpack Manifest
# Common chunk manifest files
/static/js/manifest.json
/asset-manifest.json
/webpack-manifest.json
/build/asset-manifest.json
/static/js/runtime~main.xxx.js # the runtime chunk contains the mapping of all chunks
1.4 Historical Versions
# Use the Wayback Machine to fetch old JS (may contain APIs that were deleted but not decommissioned)
curl -s "https://web.archive.org/cdx/search/cdx?url=$DOMAIN/*.js&output=text&fl=original" | sort -u
Phase 2: API Endpoint Extraction
2.1 Path Pattern Extraction
# Extract API paths from the JS content (the most critical step)
curl -s "$JS_URL" | grep -oP '["'"'"'](/(?:api|v[0-9]|rest|service|graphql|ws|internal|admin|auth|user|public)[^\s"'"'"']*?)["'"'"']' | sort -u
# Concatenated path extraction (common front-end pattern: baseURL + path)
curl -s "$JS_URL" | grep -oP '(?:baseURL|BASE_URL|API_URL|apiPrefix|apiBase)\s*[=:]\s*["'"'"']([^"'"'"']+)["'"'"']'
# Generic path extraction (including relative paths)
curl -s "$JS_URL" | grep -oP '["'"'"'](/[a-zA-Z][a-zA-Z0-9_/\-]{2,}(?:\?[^"'"'"']*)?)["'"'"']' | sort -u | grep -v '\.\(js\|css\|png\|jpg\|svg\|ico\|woff\|ttf\)'
2.2 Full URL Extraction
# Extract complete HTTP(S) URLs
curl -s "$JS_URL" | grep -oP 'https?://[^\s"'"'"'<>]+' | sort -u
# Extract internal domains/subdomains
curl -s "$JS_URL" | grep -oP 'https?://[a-zA-Z0-9._-]+\.DOMAIN\.com[^\s"'"'"']*' | sort -u
2.3 Key Information Extraction
# API Key / Secret / Token
curl -s "$JS_URL" | grep -oiP '(?:api[_-]?key|secret|token|auth|password|credential)\s*[=:]\s*["'"'"']([^"'"'"']{8,})["'"'"']'
# WebSocket endpoints
curl -s "$JS_URL" | grep -oP 'wss?://[^\s"'"'"']+' | sort -u
# Internal IPs/domains
curl -s "$JS_URL" | grep -oP '(?:10|172\.(?:1[6-9]|2\d|3[01])|192\.168)\.\d+\.\d+' | sort -u
Phase 3: Endpoint Classification and Prioritization
After extraction, classify by security value:
| Priority |
Characteristics |
Description |
| 🔴 High |
/admin/, /internal/, /debug/, /manage/ |
Administrative functions that may lack authentication |
| 🔴 High |
/upload, /import, /export, /download |
File operations that may allow path traversal/arbitrary read-write |
| 🔴 High |
/user/, /account/, /profile/, /order/ |
User data operations, prime IDOR territory |
| 🟡 Medium |
/auth/, /login/, /register/, /reset/ |
Authentication flows that may allow logic bypass |
| 🟡 Medium |
/search, /query, /filter |
Query interfaces, prime SQL injection territory |
| 🟢 Low |
/static/, /public/, /health, /status |
Static resources/health checks |
Phase 4: Batch Validation
# Validate each extracted endpoint for liveness
for path in $(cat extracted_paths.txt); do
code=$(curl -s -o /dev/null -w "%{http_code}" "$TARGET$path" --connect-timeout 5 -m 10)
echo "$code $path"
done | grep -v "^404 " | sort
Key indicators:
200 → directly accessible, inspect the response content
401/403 → exists but requires authentication, attempt a bypass
405 → the endpoint exists but the method is wrong, try POST/PUT/DELETE
500 → backend error, there may be an injection point
301/302 → follow the redirect target
Output Requirements
After extraction, output:
- JS file inventory — which JS files were analyzed
- List of discovered API endpoints — sorted by priority
- Exposed sensitive information — API keys, internal domains, tokens
- Recommended next tests — which endpoints should be fuzzed first
1---2name: js-api-extract3description: "JavaScript static analysis to extract hidden API endpoints. Use when the target is an SPA with a separate front-end/back-end architecture, when the page uses Vue/React/Angular, or when regular directory scanning yields little. Extracts API paths, keys, internal domains, and WebSocket endpoints by analyzing JS bundles. This is the information-gathering stage of API penetration testing. Once endpoints are found → use api-fuzz for semantic fuzzing"4zh-signals: "通过静态分析 JavaScript bundle 提取隐藏 API 端点、密钥与内部域名。信号:JS分析,API提取,SPA,bundle,信息收集"5when-to-use: "Use during reconnaissance against SPA or separate front-end/back-end targets to extract API paths, keys, internal domains, and WebSocket endpoints from JS bundles."6metadata:7 source: https://skillmd.com/skills/dangeroussong/js-api-extract8 tags: "js,javascript,api,extract,spa,vue,react,angular,webpack,bundle,endpoint,front-end analysis"9 category: "recon"10---1112# JavaScript API Endpoint Extraction Methodology13- 攻击大类:C10 API与业务逻辑攻击1415In a separate front-end/back-end architecture, the JS bundle is the **largest source of information** about API endpoints — 10 times more efficient than directory scanning.1617## ⛔ Further Reading (Must Read)1819- JS analysis regex library + extraction scripts → [references/js-extract-patterns.md](references/js-extract-patterns.md)2021---2223## Phase 1: JS File Collection2425### 1.1 Collect from the Page HTML26```bash27# Grab every JS reference in the page28curl -s "$TARGET" | grep -oE '(src|href)="[^"]*\.js[^"]*"' | sed 's/.*="\(.*\)"/\1/'2930# Recursive crawl (including iframes/dynamic loading)31curl -s "$TARGET" | grep -oP '(?:src|href|url)\s*[=:]\s*["\x27]([^"\x27]*\.js[^"\x27]*)["\x27]' | sort -u32```3334### 1.2 Recover from Source Maps35```bash36# Check the sourceMappingURL at the end of the JS file37curl -s "$TARGET/static/js/app.xxx.js" | tail -138# If there is //# sourceMappingURL=app.xxx.js.map39curl -s "$TARGET/static/js/app.xxx.js.map" -o sourcemap.json4041# A source map exposes the full source code — equivalent to obtaining the front-end source42```4344### 1.3 Collect from the Webpack Manifest45```bash46# Common chunk manifest files47/static/js/manifest.json48/asset-manifest.json49/webpack-manifest.json50/build/asset-manifest.json51/static/js/runtime~main.xxx.js # the runtime chunk contains the mapping of all chunks52```5354### 1.4 Historical Versions55```bash56# Use the Wayback Machine to fetch old JS (may contain APIs that were deleted but not decommissioned)57curl -s "https://web.archive.org/cdx/search/cdx?url=$DOMAIN/*.js&output=text&fl=original" | sort -u58```5960## Phase 2: API Endpoint Extraction6162### 2.1 Path Pattern Extraction63```bash64# Extract API paths from the JS content (the most critical step)65curl -s "$JS_URL" | grep -oP '["'"'"'](/(?:api|v[0-9]|rest|service|graphql|ws|internal|admin|auth|user|public)[^\s"'"'"']*?)["'"'"']' | sort -u6667# Concatenated path extraction (common front-end pattern: baseURL + path)68curl -s "$JS_URL" | grep -oP '(?:baseURL|BASE_URL|API_URL|apiPrefix|apiBase)\s*[=:]\s*["'"'"']([^"'"'"']+)["'"'"']'6970# Generic path extraction (including relative paths)71curl -s "$JS_URL" | grep -oP '["'"'"'](/[a-zA-Z][a-zA-Z0-9_/\-]{2,}(?:\?[^"'"'"']*)?)["'"'"']' | sort -u | grep -v '\.\(js\|css\|png\|jpg\|svg\|ico\|woff\|ttf\)'72```7374### 2.2 Full URL Extraction75```bash76# Extract complete HTTP(S) URLs77curl -s "$JS_URL" | grep -oP 'https?://[^\s"'"'"'<>]+' | sort -u7879# Extract internal domains/subdomains80curl -s "$JS_URL" | grep -oP 'https?://[a-zA-Z0-9._-]+\.DOMAIN\.com[^\s"'"'"']*' | sort -u81```8283### 2.3 Key Information Extraction84```bash85# API Key / Secret / Token86curl -s "$JS_URL" | grep -oiP '(?:api[_-]?key|secret|token|auth|password|credential)\s*[=:]\s*["'"'"']([^"'"'"']{8,})["'"'"']'8788# WebSocket endpoints89curl -s "$JS_URL" | grep -oP 'wss?://[^\s"'"'"']+' | sort -u9091# Internal IPs/domains92curl -s "$JS_URL" | grep -oP '(?:10|172\.(?:1[6-9]|2\d|3[01])|192\.168)\.\d+\.\d+' | sort -u93```9495## Phase 3: Endpoint Classification and Prioritization9697After extraction, classify by security value:9899| Priority | Characteristics | Description |100|--------|------|------|101| 🔴 High | `/admin/`, `/internal/`, `/debug/`, `/manage/` | Administrative functions that may lack authentication |102| 🔴 High | `/upload`, `/import`, `/export`, `/download` | File operations that may allow path traversal/arbitrary read-write |103| 🔴 High | `/user/`, `/account/`, `/profile/`, `/order/` | User data operations, prime IDOR territory |104| 🟡 Medium | `/auth/`, `/login/`, `/register/`, `/reset/` | Authentication flows that may allow logic bypass |105| 🟡 Medium | `/search`, `/query`, `/filter` | Query interfaces, prime SQL injection territory |106| 🟢 Low | `/static/`, `/public/`, `/health`, `/status` | Static resources/health checks |107108## Phase 4: Batch Validation109110```bash111# Validate each extracted endpoint for liveness112for path in $(cat extracted_paths.txt); do113 code=$(curl -s -o /dev/null -w "%{http_code}" "$TARGET$path" --connect-timeout 5 -m 10)114 echo "$code $path"115done | grep -v "^404 " | sort116```117118**Key indicators**:119- `200` → directly accessible, inspect the response content120- `401/403` → exists but requires authentication, attempt a bypass121- `405` → the endpoint exists but the method is wrong, try POST/PUT/DELETE122- `500` → backend error, there may be an injection point123- `301/302` → follow the redirect target124125## Output Requirements126127After extraction, output:1281. **JS file inventory** — which JS files were analyzed1292. **List of discovered API endpoints** — sorted by priority1303. **Exposed sensitive information** — API keys, internal domains, tokens1314. **Recommended next tests** — which endpoints should be fuzzed first