[GH-ISSUE #14766] Bash tool falsely blocked by denyPatterns when using --experimental #71606

Open
opened 2026-05-05 02:14:27 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @EmilioSchi on GitHub (Mar 10, 2026).
Original GitHub issue: https://github.com/ollama/ollama/issues/14766

What is the issue?

When Ollama is used with the --experimental flag, it seems that when the bash tool is called and a long piece of code is written, if the code contains any stuffs or pattern that includes one of the strings in the denyPatterns, the command gets blocked like this:

blocked: Bash: cat > foobar.py << 'EOF'
#!/usr/bin/env python3
\"\"\"A Foo Bar python code\"\"\"
import ...
matches dangerous pattern: su

The problem is located in func IsDenied located in file x/agent/approval.go

In this case, the substring su is detected as a dangerous pattern, even though it is not being used for privilege escalation or related purposes, but only appears as part of another word or variable. This leads to false positives that incorrectly block legitimate commands.

Originally created by @EmilioSchi on GitHub (Mar 10, 2026). Original GitHub issue: https://github.com/ollama/ollama/issues/14766 ### What is the issue? When Ollama is used with the --experimental flag, it seems that when the bash tool is called and a long piece of code is written, if the code contains any stuffs or pattern that includes one of the strings in the `denyPatterns`, the command gets blocked like this: ``` blocked: Bash: cat > foobar.py << 'EOF' #!/usr/bin/env python3 \"\"\"A Foo Bar python code\"\"\" import ... matches dangerous pattern: su ``` The problem is located in `func IsDenied` located in file `x/agent/approval.go` In this case, the substring su is detected as a dangerous pattern, even though it is not being used for privilege escalation or related purposes, but only appears as part of another word or variable. This leads to false positives that incorrectly block legitimate commands.
GiteaMirror added the bug label 2026-05-05 02:14:27 -05:00
Author
Owner

@EmilioSchi commented on GitHub (Mar 10, 2026):

Thinking about an implementation solution, it could be useful—although it would be a costly task—to introduce a parser that uses a BNF (Backus–Naur Form) grammar for bash commands.
This would make it possible to block commands only when a token is actually associated with a command, and in some cases when specific combinations of commands and parameters occur.

Not only that, but instead of printing a single
fmt.Fprintf(os.Stderr, " matches dangerous pattern: %s\n", pattern) line 380 of x/cmd/run.go
it would be useful to indicate where this pattern was found, so that in the next agentic loop the task can be executed without using malicious patterns.

<!-- gh-comment-id:4034426557 --> @EmilioSchi commented on GitHub (Mar 10, 2026): Thinking about an implementation solution, it could be useful—although it would be a costly task—to introduce a parser that uses a BNF (Backus–Naur Form) grammar for bash commands. This would make it possible to block commands only when a token is actually associated with a command, and in some cases when specific combinations of commands and parameters occur. Not only that, but instead of printing a single `fmt.Fprintf(os.Stderr, " matches dangerous pattern: %s\n", pattern)` `line 380` of `x/cmd/run.go` it would be useful to indicate where this pattern was found, so that in the next agentic loop the task can be executed without using malicious patterns.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#71606