Harden launcher against argument injection#341
Merged
Conversation
replaceVars joined args on spaces, substituted, then split back on spaces, re-tokenizing any substituted value containing a space into extra argv elements. Since cluster/incident IDs come from PagerDuty alert data and the command is passed to exec.Command, an attacker-controlled cluster_id like "x --evil-flag y" could inject extra arguments. Two layers: (1) rewrite replaceVars to substitute per-arg so a value never crosses argv boundaries; (2) add exported ocm.ValidClusterID and validate cluster IDs in getUniqueClusters so malformed values never reach the launcher. New replaceVars test asserts on the []string slice (the existing TestLoginCommandBuild compares via strings.Join, which is boundary-blind). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #341 +/- ##
==========================================
+ Coverage 66.33% 66.38% +0.04%
==========================================
Files 50 50
Lines 8154 8160 +6
==========================================
+ Hits 5409 5417 +8
+ Misses 2369 2368 -1
+ Partials 376 375 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
replaceVarsjoined args on spaces →ReplaceAll→ split on spaces,re-tokenizing any substituted value containing a space into extra argv
elements. Cluster/incident IDs come from PagerDuty alert data and the command
is passed to
exec.Command, so an attacker-controlledcluster_idlikex --evil-flag ycould inject extra arguments (not shell RCE — argv injection).Two layers:
replaceVarsrewritten to substitute per-arg — a value with spaces staysone argv element.
ocm.ValidClusterID;getUniqueClustersnow drops anycluster_idfailing^[a-zA-Z0-9_-]+$before it reaches the launcher.Test plan
TestReplaceVars_PreservesArgBoundariesasserts on the[]stringslice,not a joined string — the existing
TestLoginCommandBuildcompares viastrings.Joinand is boundary-blind, so this closes that gapTestValidClusterID+TestGetUniqueClusters_RejectsMalformedClusterIDmake test-allgreen (fmt, vet, lint, test, race, test-fixtures)skip-readme: internal security hardening, no user-facing config/flag/keybinding changes.🤖 Generated with Claude Code