MediumPro challengePython

Fix Insecure Deserialization

PythonSecurityDeserialization

The function below decodes a base64 auth token and unpickles it to check an admin flag.

The bug: this is the real behavior of OWASP's PyGoat (a deliberately-vulnerable Django app used for security training) — its insec_des_lab view runs pickle.loads(base64.b64decode(cookie)) on a token the client fully controls. pickle.loads can execute arbitrary code embedded in the payload via a crafted __reduce__ method — this isn't just "an attacker can lie about being admin," it's remote code execution on your server.

Your task: fix solve(token_b64) so it decodes the token as JSON, not pickle — json.loads can only ever produce plain data (str/int/float/bool/None/list/dict), never code. Return {'is_admin': True} when the decoded payload has admin == 1, and {'is_admin': False} for anything else (including malformed input).

Sample tests

Test #1Valid token with admin=1
Input: ["eyJhZG1pbiI6MX0="]
Output: {"is_admin":true}
Test #2Valid token with admin=0
Input: ["eyJhZG1pbiI6MH0="]
Output: {"is_admin":false}
Test #3Valid token missing the admin field
Input: ["eyJuYW1lIjoiYWxpY2UifQ=="]
Output: {"is_admin":false}
Test #4Malformed base64 fails safely
Input: ["not-valid-base64!!!"]
Output: {"is_admin":false}