Repository navigation
fix(api): stop comma-splitting -H/--field/--raw-field values - #14
Merged
emsearcy merged 3 commits intoOct 14, 2026
Merged
Conversation
urfave/cli v3 splits every StringSliceFlag value on "," by default, with no escape for a literal comma. A single --raw-field 'a=x,b=y' was therefore delivered as two elements and marshalled into two JSON body keys, and -H 'X: a,Authorization: z' set a second (overriding) header. A wrapper script interpolating untrusted text into one flag value could inject arbitrary body fields or headers into a request sent with the user's bearer token. Set DisableSliceFlagSeparator on the api command so each flag occurrence is exactly one element. It has to live on the api command itself: urfave/cli applies the separator config of the command parsing the flag and does not inherit it from the root. Repeating the flag remains the way to pass multiple fields or headers. Add regression tests that parse through the real api command. Signed-off-by: David Deal <ddeal@linuxfoundation.org> Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kvw34hYiaHVuYdeVXA7TLd
Guard against the regression tests passing vacuously if parsing ever short-circuits (e.g. help is shown) without invoking the action. Signed-off-by: David Deal <ddeal@linuxfoundation.org> Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kvw34hYiaHVuYdeVXA7TLd
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused parser change correctly addresses the issue and is covered by command-level regression tests.
Review effort: Balanced
Findings: None
What changed in this PR
Prevents comma-containing API flag values from being split into unintended fields or headers.
Changes:
- Disables slice-value comma splitting for
lfx api. - Adds regression tests for comma-containing fields and headers.
| File | Description |
|---|---|
internal/commands/api.go |
Preserves each slice-flag occurrence as one value. |
internal/commands/api_test.go |
Verifies comma-safe field and header parsing. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
emsearcy
approved these changes
Oct 14, 2026
emsearcy
deleted the
claude/autopatch-scan-29eb251e-vuln-4956725-1o1rj1
branch
October 14, 2026 23:21
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
lfx apideclares-H/--header,-F/--fieldand--raw-fieldas urfave/cli v3StringSliceFlags. By default urfave/cli splits every slice flag value on,, and there is no way to escape a literal comma. So one flag value turned into several entries:--raw-field 'a=x,b=y'produced the body{"a":"x","b":"y"}instead of{"a":"x,b=y"}--field 'note=hi,active=true'also added"active": trueas a boolean-H 'X: a,Authorization: z'set a second header, and because headers useHeader.Set, it replaced theAuthorization/Content-Typevalues the command had already setIf a wrapper script puts untrusted text into a single flag value, whoever controls that text can add arbitrary body fields or headers to a request sent with the user's bearer token. The endpoint, method and token can't be changed this way. It also broke ordinary values that contain commas, such as
Accept: a, banddesc=hello, world.Changes
internal/commands/api.go: setDisableSliceFlagSeparator: trueon theapicommand, so each flag occurrence becomes exactly one element. This setting has to go onapiand not the root command: urfave/cli uses the setting of the command that parses the flag and does not take it from parent commands. You still pass multiple fields or headers by repeating the flag.internal/commands/api_test.go: regression tests that run the realapicommand under a root command:--raw-field 'a=x,b=y'→{"a":"x,b=y"}--field 'c=1,active=true'→{"c":"1,active=true"}-H 'X: a,Authorization: z'→ one header valueBehavior change
Anyone who relied on
-H 'A: 1,B: 2'or-F a=1,b=2meaning two entries now needs to repeat the flag. This splitting was never documented in the README.Testing
go test ./...passes. Without the fix, the new tests fail and show the injected entries.make checkpasses (go vet,golangci-lint: 0 issues).--flag v,--flag=v,-H v,-H=v, flags after the path, root flags beforeapi) and found each one now produces a single entry.🤖 Generated with Claude Code
https://claude.ai/code/session_01Kvw34hYiaHVuYdeVXA7TLd
Generated by Claude Code