Summary
helpers/tools.py parses the payment gateway response (IPN/return payload) with eval() instead of json.loads(). That payload reaches the server over HTTP, so evaluating it as Python code exposes the payment path to arbitrary code execution (CWE-95).
Affected code
Seen in current versions (e.g. 4.3.1), several functions in helpers/tools.py do:
answer = eval(json.dumps(post, ensure_ascii=False)).get("kr-answer")
order_cycle = eval(answer).get('orderCycle')
eval(json.dumps(post, ...)) is an identity round-trip over a dict, and eval(answer) evaluates the raw kr-answer string from the request. The module even defines null/true/false globals so eval() can parse JSON literals — a clear sign json.loads() was intended.
Impact
Any value reaching these functions is executed as Python. On the payment return/IPN path this is a code-injection sink.
Suggested fix
eval(json.dumps(post, ...)) → direct dict access on post
eval(answer) → json.loads(answer)
- remove the
null/true/false globals
- use
hmac.compare_digest() in check_hash() (constant-time)
Behavior-preserving. We run this fix in production and will open a PR against develop.
Summary
helpers/tools.pyparses the payment gateway response (IPN/return payload) witheval()instead ofjson.loads(). That payload reaches the server over HTTP, so evaluating it as Python code exposes the payment path to arbitrary code execution (CWE-95).Affected code
Seen in current versions (e.g. 4.3.1), several functions in
helpers/tools.pydo:eval(json.dumps(post, ...))is an identity round-trip over a dict, andeval(answer)evaluates the rawkr-answerstring from the request. The module even definesnull/true/falseglobals soeval()can parse JSON literals — a clear signjson.loads()was intended.Impact
Any value reaching these functions is executed as Python. On the payment return/IPN path this is a code-injection sink.
Suggested fix
eval(json.dumps(post, ...))→ direct dict access onposteval(answer)→json.loads(answer)null/true/falseglobalshmac.compare_digest()incheck_hash()(constant-time)Behavior-preserving. We run this fix in production and will open a PR against
develop.