fix(terminal): prevent safety filter false positives on keywords inside quoted strings#20066
Open
kshitijk4poor wants to merge 1 commit into
Open
Conversation
…de quoted strings The _foreground_background_guidance() function matched background-wrapper keywords (nohup/disown/setsid) anywhere in the command text, including inside quoted strings, Python -c code, commit messages, and PR body text. Two-layer fix: 1. Strip single-quoted, double-quoted, and backtick-quoted content before pattern matching via _strip_quotes() helper. 2. Tighten the regex to only match keywords at command-start positions (after ^, ;, &, &&, ||, or $() — not mid-argument. Both layers are needed: quote stripping handles the common case of keywords in string literals, and the position-aware regex handles unquoted cases like 'export FOO=setsid' (word boundary match, wrong position). Fixes NousResearch#20064
Collaborator
|
Fixes #20064 — same root cause (naive regex in _foreground_background_guidance()). |
1 similar comment
Collaborator
|
Fixes #20064 — same root cause (naive regex in _foreground_background_guidance()). |
This was referenced May 5, 2026
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.
Problem
The terminal tool's safety filter blocks legitimate commands when keywords like
nohup,disown, orsetsidappear inside quoted strings — e.g., in commit messages, Python-ccode,gh pr create --bodytext, orgreppatterns.Examples that get incorrectly blocked:
Root Cause
_foreground_background_guidance()intools/terminal_tool.pyuses:This matches the keyword anywhere in the full command text, including inside quoted strings.
Fix
Two-layer approach:
_strip_quotes()helper — Removes single-quoted, double-quoted, and backtick-quoted content before pattern matching, so keywords inside strings are invisible to the regexes.Position-aware regex — Tightened to only match keywords at shell command positions (after
^,;,&&,||,$() rather than at any word boundary.Both layers are needed: quote stripping handles the common case (keywords in string literals), and the position-aware regex handles unquoted edge cases.
Testing
test_terminal_tool.pytests passtest_terminal_compound_background.py+test_terminal_foreground_timeout_cap.pytests passFixes #20064