Fix double expansion in slash command arguments#152
Conversation
Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
|
@copilot a simpler solution would be to expand commands, and then expand the resulting content. |
Could you clarify what you mean by "expand commands, and then expand the resulting content"? I see a few possible interpretations:
The current fix parses before expanding to prevent slash command arguments from being expanded. Are you suggesting a different expansion order, or a code simplification? |
|
@copilot sorry, just do a single expansion over the whole content post slash command expansion. |
I've tried implementing a single expansion approach, but it conflicts with the The current fix already ensures single expansion per file:
A truly single expansion (one expand() call) would mean:
But this can't respect Should we:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a double expansion vulnerability in slash command arguments where values could be expanded twice: once at the task level and again when substituted into command templates. The fix enforces single-expansion semantics by parsing task content before any expansion occurs, expanding only text blocks while keeping slash command arguments as literals for later substitution.
Key Changes
- Modified task processing to parse content before expansion, ensuring text and commands are handled separately
- Text blocks are expanded with parameters, while slash command arguments remain literal
- Command files receive literal argument values that are substituted (not re-expanded) into templates
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/codingcontext/context.go | Refactored task processing to parse before expansion, preventing double expansion of slash command arguments |
| integration_test.go | Added two integration tests verifying single-expansion behavior for parameters and command arguments |
The implementation is correct and follows the established patterns in the codebase. The tests are comprehensive and properly verify the single-expansion guarantee. The rune-by-rune processing in the expand() function already provided the foundation for single-expansion, and this PR extends that guarantee to the task/command interaction layer.
Slash command arguments were being expanded at the task level, then potentially re-expanded when substituted into command templates, violating single-expansion semantics.
Root cause: Task content was expanded before parsing, causing expansion patterns in slash command arguments to execute prematurely.
Changes:
Example:
Recommended pattern for dynamic command parameters:
Added integration tests verifying single-expansion behavior for both text blocks and slash command arguments.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.