osintteam.blog 3 min read Original Source

How I Find Hidden Vulnerabilities Inside JavaScript Files: Step-by-Step Bug Bounty Guide

Whenever we do bug bounty on a target most of us only look at the main website — login page, forms, APIs. But one goldmine that a lot of people miss is JavaScript files.

JS files often have things developers accidentally left behind:

  • API keys and tokens
  • Hidden/internal endpoints
  • Admin panel URLs
  • Subdomain names
  • Database credentials
  • Debug/test routes

In this article, I’ll walk you through the exact process from recon to exploitation that I personally use on my own targets.

Step 1: Collect all the JS files of the target

First, we need to build a list of all the JS files on the target. For this, we use a few tools.

Tool 1 — waybackurls (fetches old and current JS files):

js_files.txt” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-1/2 -translate-y-1/2 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

waybackurls target.com | grep ".js$" > js_files.txt
waybackurls target.com | grep ".js$" > js_files.txt

Tool 2 — gau (GetAllUrls, also pulls URLs from archives):

> js_files.txt” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-1/2 -translate-y-1/2 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

gau target.com | grep ".js$" >> js_files.txt
gau target.com | grep ".js$" >> js_files.txt

Tool 3 — katana (does live crawling, more accurate):

> js_files.txt” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-1/2 -translate-y-1/2 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

katana -u https://target.com -jc -o katana_js.txt
grep ".js$" katana_js.txt >> js_files.txt
katana -u https://target.com -jc -o katana_js.txt
grep ".js$" katana_js.txt >> js_files.txt

Now remove duplicate URLs:

sort -u js_files.txt -o js_files.txt
sort -u js_files.txt -o js_files.txt

Step 2: Check which JS files are live

Not all files will be live, so we check with httpx :

cat js_files.txt | httpx -silent -mc 200 -o live_js.txt
cat js_files.txt | httpx -silent -mc 200 -o live_js.txt

This command will list only the files that are still accessible status code 200.

Step 3: Pull out secrets and sensitive info

Now the real work begins hunting for secrets inside these JS files.

Tool: SecretFinder (pulls out API keys, tokens, etc.):

python3 SecretFinder.py -i live_js.txt -o cli
python3 SecretFinder.py -i live_js.txt -o cli

Tool: trufflehog (regex + entropy based secret scan):

trufflehog filesystem live_js.txt --json
trufflehog filesystem live_js.txt --json

You can also search manually with “grep” if a tool feels slow:

cat live_js.txt | while read url; do
  curl -s "$url" | grep -Eo "(api_key|apikey|secret|token|password|aws_access_key_id)["']?s[:=]s["'][^"']+["']"
done
cat live_js.txt | while read url; do
  curl -s "$url" | grep -Eo "(api_key|apikey|secret|token|password|aws_access_key_id)["']?s[:=]s["'][^"']+["']"
done

This regex will look for secrets around common keywords.

Step 4: Pull out hidden endpoints and paths

Every JS file has a lot of API endpoints hidden inside it. The best tool to extract these is LinkFinder:

python3 linkfinder.py -i https://target.com/app.js -o cli
python3 linkfinder.py -i https://target.com/app.js -o cli

If you want to do it in bulk across all files:

> endpoints.txt
done” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-1/2 -translate-y-1/2 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

for url in $(cat live_js.txt); do
  python3 linkfinder.py -i "$url" -o cli >> endpoints.txt
done
for url in $(cat live_js.txt); do
  python3 linkfinder.py -i "$url" -o cli >> endpoints.txt
done

You’ll then need to manually test the endpoints you find sometimes these turn out to be unauthenticated internal APIs that return sensitive data directly.

Step 5: Validate the endpoints are they accessible?

Once you’ve cleaned up the list of endpoints you found, check them again with “httpx”:

cat endpoints.txt | sort -u | httpx -silent -mc 200,401,403 -o valid_endpoints.txt
cat endpoints.txt | sort -u | httpx -silent -mc 200,401,403 -o valid_endpoints.txt

What the status codes mean:

  • 200 : the endpoint is live and directly accessible
  • 401/403 : the endpoint exists but has authentication/authorization in place (this is where you can try IDOR or auth bypass)

Step 6: Check JS files for library versions known CVEs

Old JS libraries (jQuery, Angular, Lodash, etc.) often have known vulnerabilities. To check this, we use retire.js:

retire --js --path live_js.txt
retire --js --path live_js.txt

If you find an outdated library with a public CVE, note it down these are easy, legitimate findings.

Step 7: Beautify and read manually

Minified JS is hard to read, so we need to beautify it first:

js-beautify app.min.js -o app_beautified.js
js-beautify app.min.js -o app_beautified.js

Then open this file manually and read through it carefully, looking for:

  • Developer notes in comments
  • Hardcoded URLs (staging, dev, internal)
  • Function names that hint at an admin feature

Step 8: Automate everything together

If doing this manually every time feels time-consuming, you can build a simple bash script that runs all these steps together:

js_files.txt
gau $domain | grep ".js$" >> js_files.txt
sort -u js_files.txt -o js_files.txt
cat js_files.txt | httpx -silent -mc 200 -o live_js.txt
python3 SecretFinder.py -i live_js.txt -o cli” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

#!/bin/bash
domain=$1
waybackurls $domain | grep ".js$" > js_files.txt
gau $domain | grep ".js$" >> js_files.txt
sort -u js_files.txt -o js_files.txt
cat js_files.txt | httpx -silent -mc 200 -o live_js.txt
python3 SecretFinder.py -i live_js.txt -o cli
#!/bin/bash
domain=$1
waybackurls $domain | grep ".js$" > js_files.txt
gau $domain | grep ".js$" >> js_files.txt
sort -u js_files.txt -o js_files.txt
cat js_files.txt | httpx -silent -mc 200 -o live_js.txt
python3 SecretFinder.py -i live_js.txt -o cli

Run it:

bash js_recon.sh target.com
bash js_recon.sh target.com

Important: Responsible disclosure

Whatever secret or endpoint you find, only test it within the authorized scope where the company has allowed it as part of their bug bounty program. Never misuse real credentials; only take a screenshot for proof-of-concept and report it.

Final Thoughts

JS files are an underrated attack surface the deeper you dig into them, the higher your chances of finding hidden bugs. This is the method I follow on every new target, and it has gotten me several valid findings.

In my next article, I’ll show you how to use these endpoints to find IDOR and Broken Access Control — stay tuned!

THANK YOU ✨

If this guide helped you, consider buying me a coffee ☕ — it keeps me motivated to dig up and write more bugs like this

Monika
Hi, I’m Monika ✨I break down real-world bug bounty reports into simple, practical write-ups.If my articles help you…