Skip to content

fix(security): remediate OS command injection in DiagnosticPing#29

Draft
al1dazzi with Copilot wants to merge 2 commits into
mainfrom
copilot/rch-task-8b731ed73849e324-remediate-selected-batch
Draft

fix(security): remediate OS command injection in DiagnosticPing#29
al1dazzi with Copilot wants to merge 2 commits into
mainfrom
copilot/rch-task-8b731ed73849e324-remediate-selected-batch

Conversation

Copilot AI commented Jun 23, 2026

Copy link
Copy Markdown

DiagnosticPing passed an unvalidated, user-controlled host query parameter directly into a shell string, enabling arbitrary OS command injection.

Changes

internal/handlers/cwe.goDiagnosticPing

  • Add host validation via safety.AllowedHostname (allowlist regex ^[a-zA-Z0-9.-]{1,253}$); reject invalid input with HTTP 400
  • Replace shell invocation with fixed-argv exec — eliminates the injection vector entirely
  • Return generic error to client; log command failure details server-side only
// Before — injectable
exec.Command("sh", "-c", "ping -c 1 "+host).CombinedOutput()

// After — validated + fixed argv
if !safety.AllowedHostname(host) {
    http.Error(w, "invalid host", http.StatusBadRequest)
    return
}
exec.Command("ping", "-c", "1", host).CombinedOutput()

internal/handlers/cwe.goSafeDiagnosticPing

  • Already validated and using fixed argv; no change required.

Remediation status

Rule Status
RCH-RULE-877450ee — cmdi via shell exec fixed
RCH-RULE-7059753c — unguarded taint→exec in DiagnosticPing fixed
RCH-RULE-a755ac83 — unguarded taint→exec in SafeDiagnosticPing already safe, no change

…RULE-877450ee, RCH-RULE-7059753c)

- Validate host parameter against AllowedHostname allowlist before use
- Replace shell invocation (sh -c) with fixed argv exec.Command("ping", "-c", "1", host)
- Return generic client-safe error on command failure; log details server-side
- SafeDiagnosticPing was already safe (no change needed, RCH-RULE-a755ac83)
Copilot AI changed the title [WIP] Remediate selected batch of 3 units fix(security): remediate OS command injection in DiagnosticPing Jun 23, 2026
Copilot AI requested a review from al1dazzi June 23, 2026 15:23
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