fix(parser): charge heredoc reinjection to parser fuel#1827
Merged
Conversation
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | 382417c | Commit Preview URL | Jun 02 2026, 09:28 AM |
ebfc651 to
382417c
Compare
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
<<heredocs on one logical line to repeatedly copy the same suffix and produce O(n^2) CPU work not accounted to parser fuel, enabling a CPU DoS.max_parser_operationswhile preserving heredoc semantics (pipes/redirects visible after the heredoc body).Description
Lexer::read_heredoc_with_strip_meteredwhich returns(content, rest_of_line_chars)so callers know how many characters were re-injected. The existingread_heredoc_with_stripdelegates to the new metered helper to preserve the public lexer API and tests.Parser::tick_units(units: usize)to consume multiple parser fuel units at once and fail early if fuel/timeouts are insufficient.rest_of_line_charsto fuel viatick_units(...)in the heredoc paths (both inline trailing-redirect andparse_heredoc_redirectflows), and adjustedparse_trailing_redirectsto returnResult<Vec<Redirect>>accordingly.test_chained_heredoc_reinjection_consumes_parser_fuelthat asserts chained: <<E && : <<E ...scripts consume parser fuel (fail withparser fuel exhausted), and documented the mitigation asTM-DOS-064inspecs/threat-model.md.Testing
cargo fmt --check(passed).cargo test -p bashkit parser:: --libwhich passed, including the new regression testtest_chained_heredoc_reinjection_consumes_parser_fuel(ok).cargo test -p bashkit --libwhich completed successfully (all tests passed).Codex Task