Skip to content

Security: eval() used to parse gateway response in helpers/tools.py (arbitrary code execution) #23

Description

@DjuOuiddoo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions