fix: address Copilot PR review comments on agent-governance skill

- Use context manager and path validation for file reading example
- Block directory traversal attacks with os.path.realpath check
- Update terminology: whitelist/blacklist -> allowlist/blocklist

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Imran Siddique
2026-02-18 14:50:24 -08:00
parent da3dbec8b9
commit 070cb0222e

View File

@@ -499,7 +499,12 @@ policy = GovernancePolicy(
@govern(policy)
async def read_file(path: str) -> str:
"""Read file contents — governed."""
return open(path).read()
import os
safe_path = os.path.realpath(path)
if not safe_path.startswith(os.path.realpath(".")):
raise ValueError("Path traversal blocked by governance")
with open(safe_path) as f:
return f.read()
```
---