01 / 20

SSRF & Deserialization
Risks

Understand how Server-Side Request Forgery and insecure deserialization can compromise systems, and learn high-level mitigations to defend against them.

Cyber Security

What is SSRF?

Server-Side Request Forgery (SSRF) is an attack where an adversary tricks a server into making HTTP requests to an unintended destination. Instead of the user fetching a resource, the server itself becomes the unwitting proxy, reaching internal services that should never be exposed.

How SSRF Works

Attacker Web Server Internal DB Metadata API Admin Panel Crafted URL Firewall

What is Deserialization?

Serialization converts an in-memory object into a storable or transmittable format (bytes, JSON, XML). Deserialization reverses this, reconstructing the object from that format. If the incoming data is untrusted, an attacker can craft a malicious payload that executes code when the server rebuilds the object.

Serialization
Object → Byte stream / JSON / XML for storage or transmission
Deserialization
Byte stream → Object reconstructed in memory, potentially triggering embedded code

Insecure Deserialization Flow

Attacker Crafts payload Malicious Serialized Data Server Deserializes data Code Execution 1 2 3

Why These Risks Matter

Both SSRF and insecure deserialization appear in the OWASP Top 10, the industry standard list of the most critical web application security risks. They can lead to devastating outcomes even from a single vulnerable endpoint.

Data Breaches
Access to internal databases, credentials, and sensitive configuration files
System Takeover
Remote code execution can give attackers full control of the server
Lateral Movement
Compromised servers become launchpads to attack other internal systems

The SSRF Attack Surface

Vulnerable Endpoint URL Parameters File Fetch / Upload Webhooks PDF Generators

The Deserialization Attack Surface

1
Session tokens: Applications that store serialized objects in cookies or session storage are vulnerable if an attacker can modify the token.
2
API payloads: Endpoints accepting serialized data (Java ObjectInputStream, Python pickle, PHP unserialize) without type validation.
3
Message queues: Inter-service communication using binary serialization formats can be intercepted and tampered with.
4
Caching layers: Cached serialized objects that can be poisoned allow persistent exploitation.

SSRF vs Deserialization

SSRF Insecure Deserialization
Attack Vector Crafted URL / network request Crafted serialized object
Who Acts The server makes the request The runtime rebuilds the object
Primary Impact Access internal resources Remote code execution
OWASP 2021 A10: SSRF A08: Software & Data Integrity
Data Flow Network layer (HTTP/S, DNS) Application layer (object parsing)

Mitigating SSRF

1
Allowlist destinations: Only permit requests to known, pre-approved URLs or domains. Deny everything else by default.
2
Block internal IPs: Reject requests to private IP ranges (127.0.0.1, 10.x.x.x, 169.254.169.254) and localhost.
3
Network segmentation: Place the application server in a DMZ so it cannot directly reach sensitive internal services.
4
Disable redirects: Do not follow HTTP redirects from user-supplied URLs, as they can bypass allowlists.
5
Validate and sanitize: Parse the URL, resolve DNS, and verify the resolved IP is not internal before making the request.

Mitigating Deserialization

1
Avoid native serialization: Use safe data formats like JSON or Protocol Buffers instead of language-native binary serialization.
2
Integrity checks: Sign serialized data with HMAC or digital signatures so tampering is detected before deserialization.
3
Type allowlisting: If you must deserialize, restrict which classes can be instantiated using a strict allowlist.
4
Isolate deserialization: Run deserialization in a sandboxed, low-privilege environment to contain any exploit.
5
Monitor and log: Flag and alert on deserialization failures or unexpected class instantiation attempts.

Example 1: Basic SSRF

User Browser App Server 169.254 .169.254 /fetch?url= http://169.254.169.254/metadata 1 2 Server returns cloud credentials

Example 2: Java Deserialization

Session Cookie Base64-encoded object Attacker Modifies Injects gadget chain Java Server ObjectInputStream RCE Gadget Chain: ClassA → ClassB → Runtime.exec()

Example 3: SSRF Redirect Bypass

Attacker App Server Attacker's Server Internal API 1 2 302 3: follows Allowlist says "external OK" ✓ But lands here ✕

Common Mistakes

✕ Blocklist Only
Using a blocklist of "bad" IPs instead of an allowlist. Attackers bypass blocklists with DNS rebinding, IPv6 mappings, and encoding tricks.
✕ Trusting Format
Assuming JSON is always safe. JSON deserialization with type hints (e.g., Jackson polymorphic typing) can still lead to code execution.
✕ Client-Side Only
Validating URLs in the browser but not on the server. Attackers bypass frontend validation entirely by sending requests directly.

Defense Summary

Defense Layer SSRF Deserialization
Input Validation URL allowlisting Integrity signatures (HMAC)
Network Controls Block internal IPs, segmentation Sandbox deserialization process
Architecture DMZ, disable redirects Use JSON/Protobuf instead
Runtime Protection DNS re-resolution checks Class allowlisting
Monitoring Log outbound requests Alert on deserialization errors

Question 1 of 5

In an SSRF attack, which component is tricked into making the unauthorized request?

Question 2 of 5

Which of the following is the most effective defense against SSRF?

Question 3 of 5

Insecure deserialization is dangerous primarily because it can lead to:

Question 4 of 5

A developer switches from Java's native serialization to JSON for API communication. Which risk does this primarily mitigate?

Question 5 of 5

An attacker uses an external server that responds with a 302 redirect to bypass an SSRF allowlist. What mitigation would prevent this?