Repository navigation
fix(expansion): keep operand quote state out of variable data - #1948
Merged
chaliy merged 1 commit intoJun 5, 2026
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens parameter-expansion operand processing for pattern-removal operators by moving quote-boundary state out of variable/expansion data, preventing attacker-controlled bytes from toggling quoted-literal protection and ensuring quoted glob metacharacters remain literal.
Changes:
- Replaces the fixed in-band quote marker with a per-operand marker chosen to be absent from the operand source.
- Refactors
expand_operandto consume quote markers only from parsed literal parts and to escape metacharacters in expanded data based on out-of-band quote state. - Adds a regression test ensuring
$'\x01'in quoted variable data cannot disable quoted glob-literal behavior.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+8908
to
+8913
| fn operand_quote_mark(operand: &str) -> char { | ||
| (1..=char::MAX as u32) | ||
| .filter_map(char::from_u32) | ||
| .find(|&ch| ch != '\0' && !operand.contains(ch)) | ||
| .expect("Unicode contains at least one char absent from any valid operand") | ||
| } |
Comment on lines
+8931
to
8941
| fn push_operand_char(out: &mut String, ch: char, in_marked: bool) { | ||
| if in_marked | ||
| && matches!( | ||
| ch, | ||
| '*' | '?' | '[' | ']' | '(' | ')' | '|' | '+' | '@' | '!' | ||
| ) | ||
| { | ||
| out.push('\\'); | ||
| } | ||
| out.push(ch); | ||
| } |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | 91be266 | Commit Preview URL | Jun 05 2026, 08:08 PM |
chaliy
deleted the
2026-06-05-propose-fix-for-quoted-wildcard-vulnerability
branch
June 5, 2026 20:54
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.
Motivation
Description
quote_markthat is guaranteed absent from the source operand viaoperand_quote_mark(operand).\expand_operandto process parsed literal parts and expanded variable/arithmetic/parameter expansion data separately so quote boundaries are consumed only from parsed literal text and cannot be toggled by expanded data.\strip_operand_quotes(operand)withstrip_operand_quotes(operand, quote_mark)and add helperspush_marked_literal,push_operand_expansion, andpush_operand_charto escape glob metacharacters in expanded data according to out-of-band quote state.\OPERAND_QUOTE_MARKconstant and the oldescape_marked_glob_literalspath.\test_quoted_remove_prefix_operand_marker_byte_keeps_glob_literalthat ensures ANSI-C$'\x01'bytes in quoted variable data do not toggle quote protection.Testing
cargo test -p bashkit remove_prefix_operand -- --nocaptureand the targeted tests executed successfully (the three related tests passed).\cargo fmt --checkand formatting check succeeded.\Codex Task