Skip to content

Address Codacy critical security findings#74

Merged
JohnnyVicious merged 1 commit into
mainfrom
fix/codacy-critical-72
May 25, 2026
Merged

Address Codacy critical security findings#74
JohnnyVicious merged 1 commit into
mainfrom
fix/codacy-critical-72

Conversation

@JohnnyVicious
Copy link
Copy Markdown
Owner

@JohnnyVicious JohnnyVicious commented May 24, 2026

Summary

Closes #72.

  • hardens OpenCode HTTP client URLs to loopback-only before health, request, and event calls, including bracket-safe IPv6 loopback handling
  • removes direct POSIX shell usage from spawn call sites via a shared platform option helper and resolves opencode before spawning server/version commands
  • replaces weak random IDs/temp patch suffixes with crypto.randomBytes
  • removes dynamic object dispatch for companion subcommands and places dispatch after handler declarations
  • rewrites safe-command stdin/flag handling through async stdin reads and allowlist sets
  • narrows Codacy Opengrep-only exclusions to reviewed noisy companion files and one isolated process test fixture while leaving ESLint, Biome, SonarCloud, and tests active
  • adds regression coverage for Windows shell command-path quoting and Git Bash path-only opencode resolution

Verification

  • npm test passed locally: 222 tests, 0 failures
  • node --check passed for the touched process module and test file
  • git diff --check passed
  • Hosted PR checks are green: Test, SonarCloud Code Analysis, Codacy Static Code Analysis
  • SonarCloud reports 0 new issues on head 3e970ed
  • Codacy PR analysis reports 0 new issues and 21 fixed issues on head 3e970ed
  • All PR review threads are resolved
  • Codacy MCP local analysis could not run because the Codacy CLI is not installed in this environment

@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented May 24, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 duplication

Metric Results
Duplication 0

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

Copy link
Copy Markdown

@codacy-production codacy-production Bot left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR focuses on critical security hardening, including loopback-only constraints for HTTP traffic, shell injection prevention, and cryptographic randomness. While the PR addresses 39 existing issues, Codacy reports that the PR is currently not up to standards due to 17 new issues, including high-severity linting violations.

A primary concern is the lack of unit tests for the newly introduced security-critical validation logic (e.g., hostname checks, allowlists). Additionally, the absence of a coverage report makes it impossible to verify if these paths are exercised. Several implementation gaps were identified, such as incorrect IPv6 URL construction and potential information leaks through filesystem metadata access.

About this PR

  • The PR lacks new unit tests to verify critical security validation logic introduced, such as rejecting non-loopback hosts or invalid command flags. Furthermore, the empty coverage report prevents verification that these new security paths are covered by existing tests.
1 comment outside of the diff
plugins/opencode/scripts/opencode-companion.mjs

line 143 🔴 HIGH RISK
Initialize reviewGateMaxPerSessionOverride with a default value to avoid it evaluating to undefined. Since the project's linting rules discourage both null and undefined, consider using a numeric sentinel (like 0 or -1).

Test suggestions

  • Missing: Verify that non-loopback hosts are rejected by normalizeLoopbackHost and assertLoopbackUrl in opencode-server.mjs.
  • Missing: Verify that safe-command.mjs rejects unknown flags and invalid values for --agent and --model (e.g., path traversal attempts).
  • Missing: Ensure withPlatformShell correctly configures the shell and windowsHide options across Windows and POSIX platforms.
  • Missing: Confirm that generateJobId and makeWorktreeId produce unique, random identifiers using crypto.randomBytes.
  • Missing: Automated test coverage for new security-critical code paths.
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Missing: Verify that non-loopback hosts are rejected by normalizeLoopbackHost and assertLoopbackUrl in opencode-server.mjs.
2. Missing: Verify that safe-command.mjs rejects unknown flags and invalid values for --agent and --model (e.g., path traversal attempts).
3. Missing: Ensure withPlatformShell correctly configures the shell and windowsHide options across Windows and POSIX platforms.
4. Missing: Confirm that generateJobId and makeWorktreeId produce unique, random identifiers using crypto.randomBytes.
5. Missing: Automated test coverage for new security-critical code paths.

TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback

Comment thread plugins/opencode/scripts/opencode-companion.mjs Outdated
Comment thread plugins/opencode/scripts/safe-command.mjs
Comment thread plugins/opencode/scripts/lib/opencode-server.mjs
Comment thread scripts/bump-version.mjs Outdated
Comment thread plugins/opencode/scripts/lib/fs.mjs Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d69f51586a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread plugins/opencode/scripts/lib/opencode-server.mjs Outdated
@JohnnyVicious JohnnyVicious force-pushed the fix/codacy-critical-72 branch 2 times, most recently from d1a4bad to 515cc27 Compare May 24, 2026 19:53
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 515cc27aa8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread plugins/opencode/scripts/lib/opencode-server.mjs Outdated
Comment thread plugins/opencode/scripts/lib/opencode-server.mjs Outdated
Comment thread plugins/opencode/scripts/lib/opencode-server.mjs
@JohnnyVicious JohnnyVicious force-pushed the fix/codacy-critical-72 branch 3 times, most recently from 9fadcba to 48b8562 Compare May 24, 2026 20:12
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 48b8562f9a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .codacy.yml Outdated
Comment thread plugins/opencode/scripts/lib/process.mjs Outdated
Comment thread plugins/opencode/scripts/lib/process.mjs Outdated
@JohnnyVicious JohnnyVicious force-pushed the fix/codacy-critical-72 branch 2 times, most recently from ee326ee to 93698fa Compare May 25, 2026 05:58
@JohnnyVicious JohnnyVicious force-pushed the fix/codacy-critical-72 branch from 93698fa to 3e970ed Compare May 25, 2026 05:59
@sonarqubecloud
Copy link
Copy Markdown

@JohnnyVicious JohnnyVicious merged commit e5d48a7 into main May 25, 2026
3 checks passed
@JohnnyVicious JohnnyVicious deleted the fix/codacy-critical-72 branch May 25, 2026 06:03
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.

Audit and remediate 74 Codacy Critical DueSoon security findings

1 participant