找出工具执行器里的 bug

来自 AI 编程智能体
Python 3.14 进阶 6分钟 找出 3处问题

找出这个生成式工具执行器中的安全问题。

Python
from pathlib import Path
import subprocess

WORKSPACE = Path("/srv/project")

def read_file(raw_path: str) -> str:
    resolved = Path(raw_path).resolve()
    if not str(resolved).startswith(str(WORKSPACE.resolve())):
        raise PermissionError(raw_path)
    return resolved.read_text()

def run(command: str) -> str:
    result = subprocess.run(
        command, shell=True, capture_output=True, text=True
    )
    return result.stdout
在试验场中打开
报告错误