MediumPro challengeJavaScriptTypeScript

Insecure Deserialization — Guard Against Prototype Pollution

TypeScriptSecurityInsecure Deserialization

The config-loading function below parses untrusted JSON with no safeguards.

The bug: a JSON payload containing a "__proto__" key can pollute Object.prototype for the entire running process once merged into an existing object elsewhere in the app — turning a "just parse some JSON" operation into a vector for corrupting unrelated code, bypassing security checks, or crashing the server.

Your task: fix solve(json) so it parses the JSON and returns the result normally — but returns null instead if the parsed value (at any nesting level) contains a __proto__, constructor, or prototype key, or if the JSON is malformed.

Sample tests

Test #1Normal config parses through
Input: ["{\"port\": 3000}"]
Output: {"port":3000}
Test #2Top-level __proto__ key rejected
Input: ["{\"__proto__\": {\"polluted\": true}}"]
Output: null
Test #3Malformed JSON fails safely, no throw
Input: ["invalid json{"]
Output: null