[Bug] FollowBench post-processing runs eval() on model output (arbitrary code execution)

Author: linhongyu510Created Sep 25, 2026Updated Sep 25, 2026

Description

post_process_followbench in opencompass/datasets/subjective/followbench.py parses a list extracted from the model's own generation with the built-in eval():

python
satisfy_list = re.search(r'\[.*\]', satisfy)
if satisfy_list:
    satisfy_list = eval(satisfy_list.group())   # <-- runs model output as code

satisfy is derived from item['prediction'] (the evaluated model's text). eval() executes arbitrary Python, so a model completion such as [__import__('os').system('...')] would run during scoring. The intended payload is only a small list of string labels (e.g. ['YES', 'NO', 'PARTIAL']), so the full power of eval() is never needed.

Impact

  • Security: arbitrary code execution driven by untrusted model output while post-processing FollowBench results.
  • Robustness: non-literal expressions raise unexpected exception types.

Fix

Use ast.literal_eval, which only parses Python literals. Legal label lists parse identically; anything else raises ValueError/SyntaxError, which the existing try/except around the function already turns into the (-1, -1) invalid-result path — so behaviour on well-formed output is unchanged. PR to follow.

Source: open-compass/opencompass