Back to Blog
Tutorials

Kasada Bot Protection: Polyglot Script and ips.js Technical Analysis

Deep dive into Kasada's unique polyglot-based bot protection, ips.js script analysis, CD token mechanism, proof-of-work challenges, and WASM components used by Twitch and Kickstarter.

Astify Team·2025-01-20·18 min read
#kasada#polyglot#bot-protection#enterprise

What Makes Kasada Different

In the bot protection landscape, Kasada stands apart with a fundamentally different approach to client-side verification. While most bot protection vendors rely on JavaScript-only sensor scripts, Kasada employs polyglot files -- single files that are simultaneously valid as multiple formats. This innovative technique makes Kasada's protection particularly challenging to analyze using traditional JavaScript deobfuscation tools.

Kasada protects high-profile platforms including Twitch, Kickstarter, various financial institutions, and gaming platforms. For security researchers, understanding Kasada's unique protection architecture offers insights into cutting-edge anti-bot engineering.

Kasada Architecture

The Polyglot Concept

A polyglot file is a file that is valid when interpreted as multiple different file formats. Kasada's primary protection script can be simultaneously valid as:

  • JavaScript: When loaded via a script tag, the browser executes the JavaScript portions of the file
  • Image (PNG/GIF): The file contains valid image headers, meaning it can be loaded as an image without error
  • Binary data: Portions of the file contain binary-encoded data that is extracted and processed at runtime

This polyglot nature serves multiple purposes. Analysis tools that expect pure JavaScript will choke on the binary sections. Image analysis tools will see a valid but meaningless image. Binary analysis tools lack the JavaScript execution context needed to understand the code.

How the Polyglot Works

1// Simplified polyglot structure concept:
2// The file begins with valid image header bytes
3// that also happen to be valid JavaScript syntax.
4
5// For example, a GIF header can be embedded as:
6var GIF89a = undefined;
7// 'GIF89a' is a valid JS variable name!
8
9// The JavaScript portion extracts binary data
10// from specific offsets in the file itself:
11var xhr = new XMLHttpRequest();
12xhr.open('GET', document.currentScript.src);
13xhr.responseType = 'arraybuffer';
14xhr.onload = function() {
15  var buffer = xhr.response;
16  // Extract binary payload from known offset
17  var wasmBytes = buffer.slice(OFFSET, OFFSET + SIZE);
18  // Initialize WebAssembly module
19  WebAssembly.instantiate(wasmBytes, imports);
20};
21xhr.send();

The ips.js Script

Kasada's main protection script is commonly known as ips.js (Integrity Protection Script). This is the polyglot file that implements the client-side protection.

Script Delivery

1// Kasada script URLs follow UUID-based paths:
2// /149e9513-01fa-4fb0-aad4-566afd725d1b/
3//   2d206a39-8ed7-437e-a3be-862e0f06eea3/p.js
4
5// The UUIDs are customer and configuration specific
6// The script is served with specific cache headers
7// to ensure fresh versions are loaded

Initialization Flow

  1. The browser loads ips.js as a regular script tag
  2. JavaScript execution begins, initializing the protection framework
  3. The script fetches its own content as an ArrayBuffer to extract binary data
  4. WebAssembly modules are extracted and instantiated from the binary payload
  5. The WASM module handles core detection logic and proof-of-work computation
  6. A CD (Challenge Data) token is generated and attached to subsequent requests

CD Token Mechanism

The CD token is Kasada's equivalent of Cloudflare's cf_clearance. It represents the client's proof of having completed the challenge successfully.

Token Generation

1// Deobfuscated CD token generation flow:
2
3// 1. Collect browser fingerprint
4var fingerprint = collectBrowserSignals();
5
6// 2. Solve proof-of-work challenge
7var challenge = {
8  difficulty: serverDifficulty,
9  prefix: serverPrefix,
10  timestamp: Date.now()
11};
12var solution = solveProofOfWork(challenge);
13
14// 3. Combine fingerprint and solution
15var payload = {
16  fp: fingerprint,
17  pow: solution,
18  ts: challenge.timestamp,
19  v: scriptVersion
20};
21
22// 4. Encode and sign the payload
23var cdToken = encodePayload(payload);
24
25// 5. Attach to requests via header
26// x-kpsdk-cd: [cdToken]
27// x-kpsdk-ct: [challenge timestamp]

Token Validation

The CD token is validated server-side by Kasada's edge infrastructure. The validation checks:

  • Proof-of-work solution correctness
  • Timestamp freshness (tokens expire)
  • Fingerprint consistency with previous requests
  • Payload integrity (cryptographic signature)

Proof-of-Work Challenges

Kasada's proof-of-work (PoW) system is a distinctive feature that adds computational cost to every challenge completion.

How PoW Works in Kasada

1// Deobfuscated proof-of-work concept:
2function solveProofOfWork(difficulty, prefix) {
3  var nonce = 0;
4  while (true) {
5    var candidate = prefix + nonce.toString();
6    var hash = computeHash(candidate);
7
8    // Check if hash meets difficulty requirement
9    if (meetsDifficulty(hash, difficulty)) {
10      return {
11        nonce: nonce,
12        hash: hash
13      };
14    }
15    nonce++;
16  }
17}
18
19// The difficulty is calibrated so that:
20// - A real browser solves in 0.5-2 seconds
21// - Making thousands of requests becomes costly
22// - WASM implementation is faster than pure JS
23//   giving browsers an advantage

Why PoW is Effective

  • Economic deterrent: Each challenge costs CPU time, making large-scale automation expensive
  • Asymmetric verification: Solving takes seconds; verifying takes microseconds
  • Rate limiting by computation: Faster hardware only provides linear scaling advantages
  • WASM advantage: The WASM implementation runs faster in browsers than equivalent JavaScript, giving legitimate browsers a speed advantage

WebAssembly Components

Kasada makes extensive use of WebAssembly for critical protection logic.

WASM in Kasada's Architecture

1// Deobfuscated WASM initialization
2var wasmImports = {
3  env: {
4    getTimestamp: function() {
5      return Date.now();
6    },
7    getNavigatorProp: function(propId) {
8      switch (propId) {
9        case 0: return navigator.userAgent;
10        case 1: return navigator.platform;
11        case 2: return navigator.language;
12      }
13    },
14    reportSignal: function(signalId, value) {
15      signals[signalId] = value;
16    },
17    performCanvasOp: function(opCode, params) {
18      // WASM directs canvas operations
19      // for fingerprinting through JS bridge
20    }
21  },
22  memory: new WebAssembly.Memory({
23    initial: 256, maximum: 512
24  })
25};
26
27// The WASM module handles:
28// 1. Proof-of-work hash computation
29// 2. Fingerprint data processing and encoding
30// 3. Anti-tampering integrity checks
31// 4. Token generation and signing

Why WASM Matters for Protection

  • Harder to analyze: WASM bytecode requires specialized tools to decompile
  • Performance: Critical computations run at near-native speed
  • Integrity: WASM modules loaded from binary are harder to modify at runtime
  • Browser validation: WASM execution behavior provides additional signals about the environment

Client Integrity Checks

1// Kasada verifies browser API behavior, not just existence
2
3// Example: Verify Date.now() returns sensible values
4var t1 = Date.now();
5var t2 = Date.now();
6if (t2 - t1 < 0 || t2 - t1 > 1000) {
7  signals.timeAnomaly = true;
8}
9
10// Example: Verify Math functions
11var mathTest = Math.tan(Math.PI / 4);
12if (Math.abs(mathTest - 1) > 0.0001) {
13  signals.mathAnomaly = true;
14}
15
16// Stack integrity analysis
17function checkStackIntegrity() {
18  try {
19    throw new Error('stack check');
20  } catch (e) {
21    var stack = e.stack;
22    // Check for unexpected frames from
23    // proxy or instrumentation layers
24    return analyzeStack(stack);
25  }
26}

Anti-Debugging Measures

Kasada implements aggressive anti-debugging that goes beyond simple debugger statements:

  • Timing gates: Critical code sections are timed; if execution takes longer than expected (indicating a breakpoint), the challenge fails
  • Function integrity: Native function toString() output is verified to detect monkey-patching
  • Source access prevention: The polyglot structure makes extracting clean JavaScript source difficult
  • DevTools detection: Multiple techniques detect open developer tools, including dimension checks and getter traps

Real Sites Using Kasada

Streaming and Entertainment

  • Twitch: Protects against automated account creation, follow/view botting, and chat spam. Twitch's implementation is one of the most visible Kasada deployments.

Crowdfunding

  • Kickstarter: Protects project pages and backer information from automated scraping and prevents bot-driven pledge manipulation.

Financial Services

  • Banking institutions: Login and transaction endpoints with highest security configuration
  • Trading platforms: API abuse prevention for high-frequency data access

Analysis Methodology with Astify

Step 1: Identify Kasada Presence

Look for the characteristic UUID-based script paths, the x-kpsdk-cd and x-kpsdk-ct headers on requests, or the kpsdk cookie prefix in the browser.

Step 2: Capture the ips.js Script

Download the polyglot script. Note that the file will contain binary data interspersed with JavaScript, so standard text editors may not display it correctly.

Step 3: Extract JavaScript Portions

Separate the JavaScript code from the binary payload. Astify can handle this extraction automatically, identifying the JavaScript boundaries within the polyglot file.

Step 4: Deobfuscate with Astify

Upload the extracted JavaScript to Astify. The AI engine applies standard deobfuscation transformations to the JavaScript layer. Note that WASM components require separate analysis.

Step 5: Analyze WASM Interactions

The deobfuscated JavaScript reveals the interface between JS and WASM. Map the import/export functions to understand what data flows between the two layers.

Browser Fingerprinting via WASM Bridge

One of the most interesting aspects of Kasada's architecture is how fingerprinting operations are orchestrated by the WASM module but executed through JavaScript bridges. This design means that the fingerprinting logic (what to collect and how to process it) is hidden in compiled WASM bytecode, while the actual browser API calls must still go through JavaScript.

1// Deobfuscated WASM-to-JS fingerprint bridge
2// The WASM module calls these JS functions
3// to access browser APIs:
4
5var fpBridge = {
6  // Canvas operations
7  createCanvas: function(w, h) {
8    var c = document.createElement('canvas');
9    c.width = w;
10    c.height = h;
11    return c;
12  },
13  getCanvasContext: function(canvas) {
14    return canvas.getContext('2d');
15  },
16  canvasToData: function(canvas) {
17    return canvas.toDataURL();
18  },
19
20  // Navigator access
21  getUA: function() {
22    return navigator.userAgent;
23  },
24  getPlatform: function() {
25    return navigator.platform;
26  },
27
28  // WebGL access
29  getWebGLRenderer: function() {
30    var c = document.createElement('canvas');
31    var gl = c.getContext('webgl');
32    if (!gl) return '';
33    var ext = gl.getExtension(
34      'WEBGL_debug_renderer_info'
35    );
36    return ext ? gl.getParameter(
37      ext.UNMASKED_RENDERER_WEBGL
38    ) : '';
39  }
40};

Network Communication Patterns

Kasada's protection uses specific network communication patterns that are identifiable in traffic analysis:

  • Initial challenge request: A GET request to the ips.js endpoint returns the polyglot script
  • Challenge data submission: A POST request containing the CD token and proof-of-work solution
  • Token refresh: Periodic requests to renew the CD token before expiry
  • Custom headers: x-kpsdk-cd (challenge data), x-kpsdk-ct (challenge timestamp), x-kpsdk-v (version), and x-kpsdk-r (referrer) headers identify Kasada-protected requests

Comparison with Other Solutions

Kasada's approach differs significantly from other bot protection vendors:

  • vs. Cloudflare: While Cloudflare uses JavaScript-only scripts, Kasada's polyglot and WASM approach makes analysis fundamentally harder. However, Kasada is a smaller vendor with fewer enterprise customers.
  • vs. PerimeterX: Both collect extensive behavioral data, but Kasada's proof-of-work adds a computational cost dimension that PerimeterX lacks.
  • vs. DataDome: DataDome emphasizes server-side speed, while Kasada emphasizes client-side complexity. They represent opposite ends of the detection philosophy spectrum.

Challenges for Analysts

Kasada presents unique challenges for security researchers:

  1. Polyglot extraction: Separating JavaScript from binary data requires understanding the file format at a byte level
  2. WASM analysis: The core logic in WebAssembly requires decompilation tools like wasm2c, wasm-decompile, or Ghidra's WASM support
  3. Proof-of-work replication: Understanding and replicating the PoW algorithm requires analyzing both the JS and WASM layers
  4. Rapid versioning: Kasada frequently updates their scripts, invalidating previous analysis

Conclusion

Kasada's polyglot approach represents one of the most innovative solutions in the bot protection space. By combining valid-as-multiple-formats files, WebAssembly computation, and proof-of-work challenges, Kasada creates a protection layer that is significantly harder to analyze than pure JavaScript solutions. The bridge between WASM and JavaScript creates an additional analysis burden, as researchers must understand both layers and their interaction. For security researchers, studying Kasada's architecture with tools like Astify provides insights into the future direction of client-side bot protection and the growing role of WebAssembly in security applications.

Try Astify Today

Experience AI-powered JavaScript deobfuscation in seconds

Start Deobfuscating