Skip to content

Potential fix for code scanning alert no. 1: Shell command built from environment values - #150

Merged
athal7 merged 2 commits into
mainfrom
alert-autofix-1
Aug 24, 2026
Merged

Potential fix for code scanning alert no. 1: Shell command built from environment values#150
athal7 merged 2 commits into
mainfrom
alert-autofix-1

Conversation

@athal7

@athal7 athal7 commented Aug 19, 2026

Copy link
Copy Markdown
Owner

Potential fix for https://github.com/athal7/opencode-devcontainers/security/code-scanning/1

To fix this without changing functionality, sanitize/validate workspace before embedding it into the Docker label filter so it cannot inject or corrupt filter syntax. The best minimal fix is to reject workspace values containing control characters (especially newline/NUL) and normalize to string before use. This keeps valid paths working (including spaces) while blocking dangerous parser-breaking characters and prevents uncontrolled argument semantics.

Apply this in plugin/core/devcontainer.js inside isContainerRunning(workspace), right before constructing the runCommand args. Add a small helper (local function) to validate label values and use its sanitized output in the --filter argument. No new dependencies are required.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

@athal7
athal7 marked this pull request as ready for review August 19, 2026 12:06
@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1b84c460-9ff1-4369-b6a9-89937e587f93

📥 Commits

Reviewing files that changed from the base of the PR and between abdb7a4 and aa919c8.

📒 Files selected for processing (6)
  • plugin/core/devcontainer.js
  • plugin/core/docker-filter.js
  • plugin/core/ports.js
  • test/unit/devcontainer.test.js
  • test/unit/docker-filter.test.js
  • test/unit/ports.test.js

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


Walkthrough

Added sanitizeDockerFilterValue to reject non-string values and control characters in Docker filter values. Updated container lookup, running-state checks, and port retrieval to sanitize workspaces before constructing Docker label filters. Added tests for valid values, invalid control characters, safe failure paths, and prevention of Docker process execution.

Merge Risk: ⚪ Minimal · up to aa919

The PR adds workspace validation before constructing the Docker label filter while preserving valid workspace paths; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title identifies the security alert and the main change to prevent unsafe command construction from environment values.
Description check ✅ Passed The description explains the workspace validation change and its purpose, which directly matches the changeset.
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
plugin/core/devcontainer.js (1)

683-689: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add regression tests for the new validation.

The existing isContainerRunning test covers only /nonexistent/workspace. Add cases for \0, \r, \n, and paths containing spaces. Assert that invalid values return false and do not invoke Docker.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 49c5a24c-fe59-4e24-9ca4-42d0cd75e565

📥 Commits

Reviewing files that changed from the base of the PR and between 9b52baf and abdb7a4.

📒 Files selected for processing (1)
  • plugin/core/devcontainer.js

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.

Comment thread plugin/core/devcontainer.js Outdated
athal7 and others added 2 commits August 24, 2026 10:11
… environment values

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
CodeRabbit flagged that the autofix only sanitized isContainerRunning,
leaving findContainerId (devcontainer.js) and getContainerPort
(ports.js) still vulnerable to filter-syntax injection via control
characters in the workspace path.

- Move sanitizeDockerFilterValue into a shared plugin/core/docker-filter.js
  module and apply it at all three --filter sinks.
- Validate before loadUserConfig() runs, so an invalid workspace fails
  fast without doing unrelated config/auto-detect work.
- Add regression tests: direct unit tests for the shared validator, and
  per-sink tests proving malicious workspace values (newline, NUL) are
  rejected without ever invoking the Docker CLI.

Co-Authored-By: anthropic/claude-sonnet-5 <noreply@anthropic.com>
@athal7
athal7 merged commit 5e2c7da into main Aug 24, 2026
6 checks passed
@athal7
athal7 deleted the alert-autofix-1 branch August 24, 2026 15:30
athal7 added a commit that referenced this pull request Aug 24, 2026
* fix(ci): enforce conventional commit format on pr titles

Squash-merging PR #150 landed a security fix (docker filter injection
sanitization, alert-autofix-1) but used the PR's non-conventional
title as the squash commit subject. commit-analyzer only inspects
commit headers, so semantic-release found no releasable commit type
and silently skipped publishing — the fix is on main but was never
shipped to npm.

Add a PR-title lint (reused verbatim from opencode-pilot/opencode-cmd/kb)
that rejects non-Conventional-Commits titles at PR open/edit time, so
every future squash-merge commit is analyzable. This commit's own
fix: type also triggers the release semantic-release owes for #150.

Co-Authored-By: anthropic/claude-sonnet-5 <noreply@anthropic.com>

* fix(ci): run title validator from base branch on every push

Address CodeRabbit review on #152:
- Use pull_request_target so the check runs the workflow definition
  from main, not the PR branch (a PR can't edit/remove its own title
  check). Safe here since this workflow never checks out PR code.
- Add synchronize so the check re-validates on every new commit
  instead of leaving a stale result on the initial commit SHA.

Co-Authored-By: anthropic/claude-sonnet-5 <noreply@anthropic.com>

---------

Co-authored-by: anthropic/claude-sonnet-5 <noreply@anthropic.com>
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.

1 participant