Skip to content

fix(interpreter): bound IFS word splitting to prevent resource exhaustion#2048

Closed
chaliy wants to merge 1 commit into
mainfrom
2026-06-12-propose-fix-for-ifs-splitting-vulnerability
Closed

fix(interpreter): bound IFS word splitting to prevent resource exhaustion#2048
chaliy wants to merge 1 commit into
mainfrom
2026-06-12-propose-fix-for-ifs-splitting-vulnerability

Conversation

@chaliy

@chaliy chaliy commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Superseded by #2060 — rebased cleanly on main.

Copilot AI review requested due to automatic review settings June 12, 2026 01:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ExecutionLimits caps for IFS word splitting (max_word_split_fields, max_word_split_bytes) plus builder setters and tests.
  • Introduced IfsClassifier and rewrote ifs_split/ifs_split_limited to use it, returning Result and enforcing caps via LimitExceeded::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)?;
}
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 12, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit 58ebf00 Commit Preview URL Jun 12 2026, 01:38 AM

@chaliy chaliy closed this Jun 12, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants