fix(interpreter): bound IFS word splitting to prevent resource exhaustion#2048
Closed
chaliy wants to merge 1 commit into
Closed
fix(interpreter): bound IFS word splitting to prevent resource exhaustion#2048chaliy wants to merge 1 commit into
chaliy wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens the interpreter’s IFS word-splitting logic to mitigate CPU/memory DoS from attacker-controlled IFS and unbounded eager splitting by introducing O(1) IFS membership checks and per-split resource caps enforced during expansion.
Changes:
- Added new
ExecutionLimitscaps for IFS word splitting (max_word_split_fields,max_word_split_bytes) plus builder setters and tests. - Introduced
IfsClassifierand rewroteifs_split/ifs_split_limitedto use it, returningResultand enforcing caps viaLimitExceeded::Memory. - Propagated splitting errors to callers and added regression tests for field/byte limit enforcement.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/bashkit/src/limits.rs | Adds execution limit knobs for word-splitting field/byte caps, with defaults and builder/test updates. |
| crates/bashkit/src/interpreter/mod.rs | Replaces O(n) IFS scanning + eager splitting with a classifier-based splitter that enforces limits and propagates errors; adds regression tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+8836
to
8839
| if !current.is_empty() { | ||
| bytes = bytes.saturating_add(current.len()); | ||
| fields = self.push_ifs_field(fields, current, limit, bytes)?; | ||
| } |
Comment on lines
4616
to
4618
| let expanded = self.expand_word(word).await?; | ||
| for field in self.ifs_split_limited(&expanded, remaining) { | ||
| for field in self.ifs_split_limited(&expanded, remaining)? { | ||
| next_arr.insert(idx, field); |
Comment on lines
+8783
to
+8786
| { | ||
| bytes = bytes.saturating_add(field.len()); | ||
| fields = self.push_ifs_field(fields, field.to_string(), limit, bytes)?; | ||
| } |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | 58ebf00 | Commit Preview URL | Jun 12 2026, 01:38 AM |
chaliy
added a commit
that referenced
this pull request
Jun 12, 2026
Closes #2048 IFS word-splitting had no upper bound on the number of fields or total bytes produced, enabling DoS via command substitutions that emit large outputs. Adds max_word_split_fields (default 100 000) and max_word_split_bytes (default 10 MB) to ExecutionLimits; exceeding either returns an error.
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.
Superseded by #2060 — rebased cleanly on main.