← Insecure Deserialization lesson
Advanced / Zero-DayInsecure DeserializationAdvanced45 min+100 XP

Serialize JavaScript

The State Service deserializes a base64 cookie into a JavaScript object and evaluates a serialize-javascript gadget. Turn the cookie into code execution and return the lab flag.

“The session cookie was base64 JSON, but one field contained a function marker and the server executed it while rebuilding the object.”

OWASP Deserialization Cheat SheetCWE-502: Deserialization of Untrusted DataCVE-2017-5941: node-serialize remote code executionJSON Schema specification for strict data contractsNode.js vm and child_process security guidance
The story
Deserialization is a trust boundary where bytes become objects, and some object models can carry behavior. If an attacker controls the serialized form and the library instantiates functions, classes or tags, data becomes code before any authorization check runs.

Unsafe deserializers do more than parse: they reconstruct types, call constructors, resolve magic methods or evaluate tagged values. Markers such as node-serialize's _$$ND_FUNC$$_, YAML's !!js/function or an eval field turn a cookie into a code path. Because the payload executes during session loading, it often runs before authentication, logging or input validation.

Your objective
  • Decode the session cookie
  • Identify the unsafe gadget marker
  • Submit a payload that executes code
  • Capture the flag
Boundary under test

Browser cookie to session middleware

Field guide · request anatomy

Where to look before you type a payload

01Accept

The application reads a cookie, hidden field, import file or queue message that the attacker can influence.

02Decode

The transport wrapper such as base64, URL encoding or compression is removed; this is not a security control.

03Rebuild

The deserializer reconstructs objects, resolves types and may evaluate function markers or magic methods.

04Execute

Attacker-controlled behavior runs in the application process, often before authorization or logging.

Progressive hints

Open one hint at a time. The first two build the model; the last two point at the boundary.

Hint 1

Open the lab and decode the sample cookie or the value shown in the page.

Hint 2

Look for the marker documented by the lab; that marker tells the deserializer to rebuild behavior, not just data.

Hint 3

The serialize-javascript deserializer evaluates values containing __FUNC__. Put function(){return process.env.LAB_FLAG} after the marker in the state cookie.

Hint 4 · near the answer

The flag appears only when the deserialized result contains the evaluated function output.

Guided workbench

Observe → Hypothesize → Test → Prove → Explain

This is the same loop a reviewer expects in a report. Your draft stays in this browser; nothing is submitted until you choose to export it.

0/15steps complete
Observe0/3
Hypothesize0/3
Test0/3
Prove0/3
Explain0/3

Evidence log

Write for a reviewer who was not in the room. Every claim needs a request, response or state change behind it.

Preview the evidence report
# Lab evidence report — Serialize JavaScript

- Family: Insecure Deserialization
- Lab ID: web-deserialization-serialize-javascript
- Date: 2026-12-05

## Workflow

### Observe

- [ ] Open "Serialize JavaScript" and record the entry point, the HTTP method and the role you are given.
- [ ] List every parameter, header, cookie and object identifier the normal flow exposes.
- [ ] Save a baseline response: status, body shape, timing and the fields that change by user.

### Hypothesize

- [ ] Name the server decision that protects the entry point, and the evidence it should use.
- [ ] Use the clue as a constraint, not an answer: Submit a JSON value with the marker __FUNC__ followed by function(){return process.env.LAB_FLAG}. The deserializer evaluates it.
- [ ] Predict the exact status, body or state change that would prove the decision is missing.

### Test

- [ ] Start from the baseline and change one value: the state serialized value.
- [ ] Keep the request replayable; vary encoding, method or identifier location only after the first result.
- [ ] Capture the full request and response for the winning attempt, including the flag.

### Prove

- [ ] Capture the flag and name the exact foreign object, role or state change it proves.
- [ ] Repeat from a clean session and confirm the result is not cached or stale.
- [ ] State impact precisely: what data or action did you actually obtain?

### Explain

- [ ] State the root cause without naming the payload: which decision failed?
- [ ] Name the control that prevents recurrence and the layer where it belongs.
- [ ] Write one regression test that fails before the fix and passes after it.

## Evidence

### Target and baseline

_Not recorded._

### Hypothesis

_Not recorded._

### Winning request

_Not recorded._

### Proof

_Not recorded._

### Root cause

_Not recorded._

### Control and regression test

_Not recorded._

## Analyst conclusion

The proof demonstrates the missing control above. The regression test should fail against the vulnerable behavior and pass after remediation.
Solution and debrief
Locked until you capture the flag.

The full request, the reasoning and the debrief unlock after a successful capture. That is deliberate: struggle first, then consolidate.

What a reviewer will ask

False positives to rule out

  • The cookie is base64 JSON and the application only calls JSON.parse; no function marker is evaluated.
  • A payload causes a parser error or a 500 response but no code runs and no secret is returned.
  • The value is signed and the signature is verified before parsing; tampering is rejected.

Regression tests to name

  • Function marker is rejected: The request is rejected without evaluating the function
  • Signature checked before parse: Verification fails before any deserialization occurs
  • Unknown fields rejected: Validation fails and no dynamic evaluation occurs
The defender's move
  • Do not deserialize untrusted data into executable object graphs; use plain JSON with a strict schema and reject unknown fields.
  • Use signed, opaque server-side sessions or encrypted tokens, and verify integrity before parsing.
  • If a serializer is unavoidable, allowlist types, disable function and tag resolution, and run parsing in a sandbox with least privilege.
  • Add monitoring for deserialization errors and unexpected child processes, and keep serialization libraries patched.
See the secure-code pattern and all 4 regression tests →
الخلاصة

Deserialization غير الآمنة تنشأ عندما يتحول المحتوى الذي يتحكم به المهاجم إلى كائنات قابلة للتنفيذ. قد تحمل مكتبات مثل node-serialize أو YAML وسومًا تنفّذ دوال أثناء تحميل الجلسة. الحل: لا تفكّك بيانات غير موثوقة إلى كائنات قابلة للتنفيذ، استخدم JSON مع مخطط صارم، واشترط توقيعًا يُتحقق منه قبل التحليل، وقيّد الأنواع وعطّل الدوال والوسوم، وشغّل التحليل في بيئة محدودة الصلاحيات.