QA
Senior LevelAuthentication & Authorization

How do you resolve HTTP Header Bloat caused by large JWTs using compression or claim pruning?

❓ Interview Prompt: Explain HTTP 431 Request Header Fields Too Large errors, zlib/Brotli JWT compression, claims pruning, and reference tokens.

As enterprise systems add dozens of custom claims (roles, organization trees, feature toggles) to JWTs, token string size can grow to 4KB–8KB+. When sent in the 'Authorization' header of every request, this causes HTTP 431 (Request Header Fields Too Large) server crashes and severe network bandwidth overhead.

Mitigation Strategies:

1
Claims Pruning: Convert multi-kilobyte permission string arrays into compact bitmasks or integer flags.
2
ZLIB / Brotli Compression: Compress Base64 payloads prior to signing using DEFLATE or Brotli.
3
Reference Tokens (Opaque Handles): Convert heavy JWTs into opaque 128-bit reference handles, performing fast server-side cache lookups.

Code Implementation Example

typescript
import zlib from 'zlib';

// Deflate compressing heavy JWT payload strings
function compressJwtPayload(payloadObj: object): string {
  const jsonStr = JSON.stringify(payloadObj);
  const compressedBuffer = zlib.deflateRawSync(Buffer.from(jsonStr));
  return compressedBuffer.toString('base64url'); // Compact compressed payload
}

function decompressJwtPayload(compressedBase64Url: string): object {
  const compressedBuffer = Buffer.from(compressedBase64Url, 'base64url');
  const decompressedBuffer = zlib.inflateRawSync(compressedBuffer);
  return JSON.parse(decompressedBuffer.toString('utf-8'));
}
💡Compressing heavy JWT payloads using DEFLATE zlib compression.
🎯 Interview Key Takeaway

Resolve HTTP 431 header bloat by pruning claims, compressing payloads with DEFLATE/Brotli, or converting to reference tokens.

#Header Bloat#JWT Compression#Brotli#Optimization#Senior
Back to all Authentication & Authorization Questions→

More Authentication & Authorization Interview Questions

Beginner LevelAuthentication & Authorization

Compare JWT Token Authentication versus Stateful Sessions, and explain OAuth 2.0 PKCE flow.

Beginner LevelAuthentication & Authorization

What is the fundamental difference between Authentication (AuthN) and Authorization (AuthZ)?

Beginner LevelAuthentication & Authorization

Why should passwords never be stored in plain text and how do bcrypt and Argon2id work?