Skip to content

Fix path injection, empty choices crash, and config inconsistencies#5

Draft
Copilot wants to merge 3 commits intofeature/agent-loopfrom
copilot/review-pr-4
Draft

Fix path injection, empty choices crash, and config inconsistencies#5
Copilot wants to merge 3 commits intofeature/agent-loopfrom
copilot/review-pr-4

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 3, 2026

Security and robustness fixes found during review of the agent loop implementation in PR #4.

Path injection in collect_artifacts

Artifact filenames from container ls output were interpolated into shell commands with only single-quote wrapping—vulnerable to traversal and injection. Now uses os.path.basename() + shlex.quote():

# Before
content = await self._container.exec(f"cat '{_ARTIFACTS_DIR}/{name}'", timeout=10)

# After
name = os.path.basename(name)
safe_path = shlex.quote(f"{_ARTIFACTS_DIR}/{name}")
content = await self._container.exec(f"cat {safe_path}", timeout=10)

Missing bounds check on response.choices[0]

  • LLMClient.chat(), AgentLoop.run(), AgentLoop._force_final(), and Level3Agent all accessed choices[0] without guarding against empty arrays → IndexError on malformed API responses
  • Added early-return/fallback at each call site

Unsafe full_name.split("/", 1) in handlers

  • Both PullRequestHandler and IssueCommentHandler would raise ValueError on malformed webhook payloads missing the / separator
  • Added validation with early return

Hardcoded exec timeout cap

  • ContainerManager.exec() capped timeout at 120s, silently overriding the configurable container_timeout (default 150s)
  • Changed to use self._settings.container_timeout as the cap

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits March 3, 2026 07:14
- Fix path injection in collect_artifacts: use shlex.quote() for filenames
- Add bounds check for empty response.choices across LLM call sites
- Validate full_name format before split in both handlers
- Use configurable container_timeout instead of hardcoded 120s cap
- Add tests for all fixes

Co-authored-by: sweettastebuds <49539676+sweettastebuds@users.noreply.github.com>
…ve test

- Use os.path.basename() to strip directory components from artifact names
- Improve test to verify path traversal is properly blocked

Co-authored-by: sweettastebuds <49539676+sweettastebuds@users.noreply.github.com>
Copilot AI changed the title [WIP] Review changes in pull request 4 Fix path injection, empty choices crash, and config inconsistencies Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants