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.
- Decode the session cookie
- Identify the unsafe gadget marker
- Submit a payload that executes code
- Capture the flag
Browser cookie to session middleware
Where to look before you type a payload
The application reads a cookie, hidden field, import file or queue message that the attacker can influence.
The transport wrapper such as base64, URL encoding or compression is removed; this is not a security control.
The deserializer reconstructs objects, resolves types and may evaluate function markers or magic methods.
Attacker-controlled behavior runs in the application process, often before authorization or logging.
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 cookie-deserialize deserializer evaluates values containing _$$ND_FUNC$$_. Put function(){return process.env.LAB_FLAG} after the marker in the auth cookie.
Hint 4 · near the answer
The flag appears only when the deserialized result contains the evaluated function output.
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.
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 — The Cookie Deserializer
- Family: Insecure Deserialization
- Lab ID: web-deserialization-cookie-deserialize
- Date: 2026-12-05
## Workflow
### Observe
- [ ] Open "The Cookie Deserializer" 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 _$$ND_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 auth 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.
The full request, the reasoning and the debrief unlock after a successful capture. That is deliberate: struggle first, then consolidate.
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
- 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.
Deserialization غير الآمنة تنشأ عندما يتحول المحتوى الذي يتحكم به المهاجم إلى كائنات قابلة للتنفيذ. قد تحمل مكتبات مثل node-serialize أو YAML وسومًا تنفّذ دوال أثناء تحميل الجلسة. الحل: لا تفكّك بيانات غير موثوقة إلى كائنات قابلة للتنفيذ، استخدم JSON مع مخطط صارم، واشترط توقيعًا يُتحقق منه قبل التحليل، وقيّد الأنواع وعطّل الدوال والوسوم، وشغّل التحليل في بيئة محدودة الصلاحيات.