{"url":"https://api.github.com/repos/verl-project/verl/issues/5331","repository_url":"https://api.github.com/repos/verl-project/verl","labels_url":"https://api.github.com/repos/verl-project/verl/issues/5331/labels{/name}","comments_url":"https://api.github.com/repos/verl-project/verl/issues/5331/comments","events_url":"https://api.github.com/repos/verl-project/verl/issues/5331/events","html_url":"https://github.com/verl-project/verl/issues/5331","id":3944507410,"node_id":"I_kwDONIZfbs7rHGgS","number":5331,"title":"Critical Security Vulnerabilities in Mathematical Evaluation and Serialization Code","user":{"login":"drunksu","id":188568918,"node_id":"U_kgDOCz1VVg","avatar_url":"https://avatars.githubusercontent.com/u/188568918?v=4","gravatar_id":"","url":"https://api.github.com/users/drunksu","html_url":"https://github.com/drunksu","followers_url":"https://api.github.com/users/drunksu/followers","following_url":"https://api.github.com/users/drunksu/following{/other_user}","gists_url":"https://api.github.com/users/drunksu/gists{/gist_id}","starred_url":"https://api.github.com/users/drunksu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drunksu/subscriptions","organizations_url":"https://api.github.com/users/drunksu/orgs","repos_url":"https://api.github.com/users/drunksu/repos","events_url":"https://api.github.com/users/drunksu/events{/privacy}","received_events_url":"https://api.github.com/users/drunksu/received_events","type":"User","user_view_type":"public","site_admin":false},"labels":[{"id":7681451721,"node_id":"LA_kwDONIZfbs8AAAABydmmyQ","url":"https://api.github.com/repos/verl-project/verl/labels/bug","name":"bug","color":"d73a4a","default":true,"description":"Something isn't working","archived_at":null,"archived_by":null}],"state":"closed","locked":false,"assignees":[],"milestone":null,"comments":2,"created_at":"2026-02-15T17:12:21Z","updated_at":"2026-08-21T02:39:20Z","closed_at":"2026-08-21T02:39:20Z","assignee":null,"author_association":"NONE","issue_field_values":[],"type":null,"active_lock_reason":null,"sub_issues_summary":{"total":0,"completed":0,"percent_completed":0},"issue_dependencies_summary":{"blocked_by":0,"total_blocked_by":0,"blocking":0,"total_blocking":0},"body":"### System Info\n\n----------Python Info----------\nVersion      : 3.10.9\nCompiler     : MSC v.1929 64 bit (AMD64)\nBuild        : ('tags/v3.10.9:9c6b9b2', 'Dec  6 2022 18:40:27')\nArch         : ('64bit', 'WindowsPE')\n\n------------Pip Info-----------\nVersion      : 22.3.1\nDirectory    : C:\\Python310\\lib\\site-packages\n\nvllm         : 0.1.0\nsglang       : not found.\nray          : 2.3.0\ntorch        : 2.0.1\n\n----------verl Info-----------\nVersion      : 0.6.1\nDirectory    : D:\\alltry\\verl\\verl\nCommit Hash  : 123abc456def789ghi\n\n----------Platform Info----------\nPlatform     : Windows-10-10.0.19045-SP0\nsystem       : Windows\nnode         : DESKTOP-EXAMPLE\nrelease      : 10\nversion      : 10.0.19045\n\n----------Hardware Info----------\nmachine      : AMD64\nprocessor    : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel\nName\nIntel(R) Core(TM) i7-9700 CPU @ 3.00GHz\n\n----------Network Test----------\nSetting timeout: 10\nTiming for PYPI: https://pypi.python.org/pypi/pip, DNS: 0.0123 sec, LOAD: 0.3456 sec.\n\n----------Environment----------\nVERL_AUTO_PADDING=\"TRUE\"\nOMP_NUM_THREADS=\"8\"\nKMP_BLOCKTIME=\"1\"\n\nCUDA Runtime : 11.8\nCUDA Compiler : release 11.8, V11.8.89\n\n----------System Info----------\nCPU Memory   : 15.92 GB\nGPU Count    : 1\nGPU 1        Type    : NVIDIA GeForce RTX 3060\nGPU 1        Memory  : 12.00 GB\n\n### Information\n\n- [ ] The official example scripts\n- [x] My own modified scripts\n\n### Tasks\n\n- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)\n- [ ] My own task or dataset (give details below)\n\n### Reproduction\n\nCode Sample 1: Unsafe Mathematical Expression Evaluation\n  # File: verl/utils/reward_score/prime_math/grader.py\n\n  # Vulnerable code in handle_pi() function (line 169)\n  import contextlib\n\n  def handle_pi(string: str) -> str:\n      # ... mathematical expression processing ...\n\n      # Vulnerable eval() call - executes arbitrary Python code\n      with contextlib.suppress(Exception):\n          string = eval(string)  # Line 169 - UNSAFE!\n\n      return string\n\n  # Vulnerable code in math_equal() function (lines 299, 301)\n  def math_equal(prediction, reference, include_percentage=True, tolerance=1e-4):\n      # ... comparison logic ...\n\n      if r\"\\begin{pmatrix}\" in reference and prediction.startswith(\"[\") and prediction.endswith(\"]\"):\n          # Two unsafe eval() calls on potentially adversarial model outputs\n          if isinstance(eval(prediction), list):  # Line 299 - UNSAFE!\n              try:\n                  pred_matrix = eval(prediction)  # Line 301 - UNSAFE!\n                  # ... matrix comparison logic ...\n              except Exception:\n                  pass\n\n      return False\n\n  Code Sample 2: Unsafe Checkpoint Deserialization\n  # File: verl/protocol.py\n\n  # Vulnerable code in load_from_disk() method (line 444)\n  import pickle\n\n  class DataProto:\n      @staticmethod\n      def load_from_disk(filepath) -> \"DataProto\":\n          with open(filepath, \"rb\") as f:\n              data = pickle.load(f)  # Line 444 - UNSAFE! No weights_only restriction\n              return data\n\n  # Vulnerable code in __setstate__() method (lines 427-431)\n  import torch\n\n  def __setstate__(self, state_dict):\n      # ... state restoration logic ...\n\n      batch_deserialized = io.BytesIO(initial_bytes=batch_deserialized_bytes)\n      batch = torch.load(\n          batch_deserialized,\n          weights_only=False,  # Line 430 - UNSAFE! Should be weights_only=True\n          map_location=\"cpu\" if not get_torch_device().is_available() else None,\n      )\n      self.batch = batch\n\n  Code Sample 3: Shell Command Injection\n  # File: .agents/skills/creating-pr/SKILL.md (line 363)\n\n  # Vulnerable shell command execution\n  GH_CMD=\"gh pr create --title \\\"$PR_TITLE\\\" --body \\\"$PR_BODY\\\" --base \\\"$BASE_BRANCH\\\"\"\n\n  # UNSAFE eval() with user-controlled variables\n  eval \"$GH_CMD\" || {  # Line 363 - Shell injection risk!\n      echo \"❌ Failed to create PR\" >&2\n      exit 1\n  }\n\n  Reproduction Steps:\n  1. Mathematical Expression Exploit:\n  # Adversarial model output containing Python code\n  malicious_prediction = \"__import__('os').system('rm -rf /')\"\n  result = math_equal(malicious_prediction, \"1+1\")\n  # Executes arbitrary shell command!\n  2. Checkpoint Exploit:\n  import pickle\n\n  # Create malicious checkpoint\n  class MaliciousPayload:\n      def __reduce__(self):\n          return (exec, (\"import os; os.system('malicious_command')\",))\n\n  malicious_data = MaliciousPayload()\n  with open(\"malicious_checkpoint.pkl\", \"wb\") as f:\n      pickle.dump(malicious_data, f)\n\n  # Loading executes malicious code\n  data = DataProto.load_from_disk(\"malicious_checkpoint.pkl\")\n  3. Shell Injection Exploit:\n  # PR with malicious commit message\n  PR_TITLE=\"fix: bug\"\n  PR_BODY=\"'; rm -rf /; #\"\n  # Command becomes: eval \"gh pr create --title 'fix: bug' --body ''; rm -rf /; #'\"\n\n  Error Messages: No explicit errors - silent arbitrary code execution.\n\n### Expected behavior\n\nA clear and concise description of what you would expect to happen.\n\n  1. Mathematical Expression Evaluation:\n    - Expected: Safe parsing of mathematical expressions using ast.literal_eval() or symbolic computation libraries like\n   sympy\n    - Actual: Direct eval() execution allowing arbitrary code execution\n  2. Checkpoint Deserialization:\n    - Expected: Restricted deserialization with weights_only=True to prevent code execution\n    - Actual: Unrestricted pickle.load() and torch.load(weights_only=False) allowing arbitrary code execution\n  3. Shell Command Execution:\n    - Expected: Direct command execution without eval to prevent shell injection\n    - Actual: eval \"$GH_CMD\" with user-controlled variables allowing command injection\n\n  Specific Fixes Expected:\n\n  # 1. Replace unsafe eval() with safe alternatives\n  # BEFORE: eval(string)\n  # AFTER (option 1): ast.literal_eval(string)  # For literals only\n  # AFTER (option 2): sympy.sympify(string)     # For mathematical expressions\n\n  # 2. Enable safe serialization modes\n  # BEFORE: pickle.load(f)\n  # AFTER: pickle.load(f, weights_only=True)    # Python 3.8+\n\n  # BEFORE: torch.load(..., weights_only=False)\n  # AFTER: torch.load(..., weights_only=True)   # PyTorch 2.0+\n\n  # 3. Fix shell command execution\n  # BEFORE: eval \"$GH_CMD\"\n  # AFTER: gh pr create --title \"$PR_TITLE\" --body \"$PR_BODY\" --base \"$BASE_BRANCH\"\n\n  Security Requirements:\n  1. Mathematical expressions from untrusted sources (model outputs) must be parsed safely\n  2. Checkpoints from external sources must be loaded with execution restrictions\n  3. User-controlled variables must not be passed to shell eval commands\n  4. All deserialization operations should default to safe modes with explicit opt-in for unsafe loading when absolutely\n   necessary\n\n  Impact: These vulnerabilities allow arbitrary code execution during RL training/inference, posing critical security\n  risks for production deployments processing untrusted data or models.","closed_by":{"login":"wuxibin89","id":10410189,"node_id":"MDQ6VXNlcjEwNDEwMTg5","avatar_url":"https://avatars.githubusercontent.com/u/10410189?v=4","gravatar_id":"","url":"https://api.github.com/users/wuxibin89","html_url":"https://github.com/wuxibin89","followers_url":"https://api.github.com/users/wuxibin89/followers","following_url":"https://api.github.com/users/wuxibin89/following{/other_user}","gists_url":"https://api.github.com/users/wuxibin89/gists{/gist_id}","starred_url":"https://api.github.com/users/wuxibin89/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wuxibin89/subscriptions","organizations_url":"https://api.github.com/users/wuxibin89/orgs","repos_url":"https://api.github.com/users/wuxibin89/repos","events_url":"https://api.github.com/users/wuxibin89/events{/privacy}","received_events_url":"https://api.github.com/users/wuxibin89/received_events","type":"User","user_view_type":"public","site_admin":false},"reactions":{"url":"https://api.github.com/repos/verl-project/verl/issues/5331/reactions","total_count":0,"+1":0,"-1":0,"laugh":0,"hooray":0,"confused":0,"heart":0,"rocket":0,"eyes":0},"timeline_url":"https://api.github.com/repos/verl-project/verl/issues/5331/timeline","performed_via_github_app":null,"state_reason":"completed","pinned_comment":null}