A conceptual look at modern web protection systems* contact @Nixnode on telegram for more info.
Kasada is an enterprise-grade bot protection system used by major websites (PlayStation, Sony, Ticketmaster, etc.) to prevent automated access. Unlike simple rate limiting, Kasada uses sophisticated client-side challenges to distinguish humans from bots.
When you try to access a Kasada-protected API:
import requests
response = requests.post('https://protected-site.com/api/endpoint')
print(response.status_code) # 429/403 ForbiddenYou get blocked. Not because of your IP or user agent, but because you're missing cryptographic proof that you're a legitimate client.
Kasada-protected requests include custom headers that prove the client is legitimate:
x-kpsdk-ct: Client Token (CT)
x-kpsdk-cd: Client Data (CD) - contains proof-of-work answers
x-kpsdk-h: signature validating CT and CD match
x-kpsdk-v: Version identifier
x-kpsdk-r: Request identifier
Layer 1: The p.js Script
- Kasada injects a JavaScript file (p.js) into protected pages
- This script is heavily obfuscated using VM bytecode
- Contains a complete virtual machine that runs encrypted bytecode
- Reverse engineering this is extremely difficult
Layer 2: Proof-of-Work Challenges
- The script fetches cryptographic puzzles from Kasada servers
- Client must solve these challenges (similar to crypto mining)
- Solutions are included in the CD token
- Server validates that answers are correct
Layer 3: Token Properties
- CT Token: Expensive to generate, valid for 30 minutes, reusable
- CD Token: Cheaper to generate, SINGLE-USE ONLY, must be fresh
- HMAC Signature: Links CT and CD together, prevents token mixing/tampering
The tokens contain:
- Timestamps that must be recent
- Challenge solutions that must match server-issued puzzles
- HMAC signatures that validate token authenticity
- Unique IDs tracked server-side to prevent reuse
While Kasada does check TLS fingerprints, even with a perfect Chrome fingerprint, you still need:
- Valid CT and CD tokens
- Proof-of-work solutions
- Correct HMAC signatures
This is the critical insight:
Normal flow:
1. Browser makes request
2. KPSDK adds CT + CD headers
3. Request sent to server
4. Server validates and marks CD as "used"
5. CD token is now consumed
If you capture tokens from a completed request, the CD is already consumed. You can't reuse it.
CT Token Generation:
- Generated when page first loads
- Contains client fingerprint data
- Expensive to compute
- Valid for ~30 minutes
- Same CT used across multiple requests
CD Token Generation:
- Generated fresh for each request
- Contains timestamp and challenge answers
- Cheaper to compute
- SINGLE-USE only
- Must be recent (typically < 5 seconds old)
** Validation:**
This signature proves:
- CT and CD come from the same session
- Tokens haven't been tampered with
- Request is authentic
The breakthrough insight:
Standard approach (doesn't work):
1. Make request → KPSDK adds tokens → Request completes
2. Capture tokens from completed request
3. CD is already consumed ❌
Since CT is expensive but reusable, and CD is cheap but single-use.
The Kasada script uses multiple obfuscation layers:
- VM Obfuscation: Core logic compiled to bytecode executed by embedded VM
- String Encryption: All strings encrypted and decrypted at runtime
- Control Flow Flattening: Code flow made non-linear and hard to trace
- Dead Code Injection: Fake code paths that never execute
- Variable Name Mangling: All variables renamed to meaningless names
This makes static analysis extremely difficult.
The CD token contains solutions to cryptographic challenges:
Challenge Structure:
- Server provides puzzle parameters (difficulty, prefix, etc.)
- Client must find solutions (like crypto mining)
- Solutions are included in CD token
- Server validates solutions match the challenge.
The "answers" array in CD contains these solutions.
Server-side validates multiple aspects:
Timestamp Validation:
- CD must be recent (typically < 5 seconds old)
- Prevents replay attacks with old tokens
Uniqueness Validation:
- Each CD has unique ID tracked server-side
- Once used, marked as consumed
- Prevents reuse of same CD
Challenge Validation:
- Solutions must match server-issued challenges
- Can't fake answers without solving
Signature Validation:
- Signature binds CT and CD together
- Prevents mixing tokens from different sessions
- Ensures tokens haven't been modified
Found this interesting? Have questions? Want to collaborate?
- ⭐ Star the repo if you learned something
- 💬 Start a discussion to share insights
- 🤝 Contribute improvements
