mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-09-07 04:30:51 +00:00
fix: allow valid heredoc commands in sandbox audit (#3786)
* fix: allow valid heredoc sandbox audit commands * test: cover unparseable heredoc sandbox audit path
This commit is contained in:
parent
cb3f9ac723
commit
b0ce4b513c
@ -150,8 +150,9 @@ def _classify_single_command(command: str) -> str:
|
|||||||
if pattern.search(joined):
|
if pattern.search(joined):
|
||||||
return "block"
|
return "block"
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# shlex.split fails on unclosed quotes — treat as suspicious
|
# Heredocs and other multiline shell forms may be valid bash but
|
||||||
return "block"
|
# unparseable by shlex. Raw high-risk patterns were already checked.
|
||||||
|
pass
|
||||||
|
|
||||||
for pattern in _MEDIUM_RISK_PATTERNS:
|
for pattern in _MEDIUM_RISK_PATTERNS:
|
||||||
if pattern.search(normalized):
|
if pattern.search(normalized):
|
||||||
|
|||||||
@ -183,6 +183,14 @@ class TestClassifyCommand:
|
|||||||
def test_safe_classified_as_pass(self, cmd):
|
def test_safe_classified_as_pass(self, cmd):
|
||||||
assert _classify_command(cmd) == "pass", f"Expected 'pass' for: {cmd!r}"
|
assert _classify_command(cmd) == "pass", f"Expected 'pass' for: {cmd!r}"
|
||||||
|
|
||||||
|
def test_unparseable_heredoc_classified_as_pass(self):
|
||||||
|
cmd = "python3 << 'EOF'\necho it's fine\nEOF"
|
||||||
|
assert _classify_command(cmd) == "pass"
|
||||||
|
|
||||||
|
def test_unparseable_heredoc_with_high_risk_pattern_still_blocks(self):
|
||||||
|
cmd = "python3 << 'EOF'\necho it's fine\ncat /etc/shadow\nEOF"
|
||||||
|
assert _classify_command(cmd) == "block"
|
||||||
|
|
||||||
# --- Compound commands: sub-command splitting ---
|
# --- Compound commands: sub-command splitting ---
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user