Skip to content

fix(security): remediate OS command injection in DiagnosticPing (CWE-78)#34

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

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

Conversation

Copilot AI commented Jul 9, 2026

Copy link
Copy Markdown

DiagnosticPing concatenated a request-controlled host parameter directly into a shell command string, enabling arbitrary command execution via the /diagnostics/ping endpoint.

Changes

internal/handlers/cwe.go

  • DiagnosticPing: replaced shell-interpolated invocation with validated fixed-argv exec:
// Before (vulnerable)
out, err := exec.Command("sh", "-c", "ping -c 1 "+host).CombinedOutput()

// After
if !safety.AllowedHostname(host) {
    http.Error(w, "invalid host", http.StatusBadRequest)
    return
}
out, err := exec.Command("ping", "-c", "1", host).CombinedOutput()
if err != nil {
    log.Printf("ping %s: %v: %s", host, err, out)
    http.Error(w, "ping failed", http.StatusBadGateway)
    return
}
  • SafeDiagnosticPing: already guarded with AllowedHostname + fixed argv — no change required.

Remediation units

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

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

- Add AllowedHostname validation to DiagnosticPing (blocks shell metacharacters)
- Replace shell invocation `exec.Command("sh", "-c", "ping -c 1 "+host)` with
  fixed argv `exec.Command("ping", "-c", "1", host)`
- Log command failures server-side and return generic "ping failed" to client
- SafeDiagnosticPing already has AllowedHostname guard + fixed argv (RCH-RULE-a755ac83 already safe)
Copilot AI changed the title [WIP] Remediate selected batch of 3 units fix(security): remediate OS command injection in DiagnosticPing (CWE-78) Jul 9, 2026
Copilot AI requested a review from al1dazzi July 9, 2026 15:08
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