[PR #14781] x/agent: fix false positive deny pattern matching in heredocs #77127

Open
opened 2026-05-05 09:49:23 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/14781
Author: @moktamd
Created: 3/11/2026
Status: 🔄 Open

Base: mainHead: fix/agent-deny-pattern-false-positives


📝 Commits (2)

  • dedf0de x/agent: fix false positive deny pattern matching in heredocs
  • 341d256 address review: add $() and backtick to command prefixes, expand tests

📊 Changes

2 files changed (+184 additions, -7 deletions)

View changed files

📝 x/agent/approval.go (+130 -6)
📝 x/agent/approval_test.go (+54 -1)

📄 Description

The IsDenied function uses naive substring matching against the full command string, which causes false positives when heredoc bodies contain substrings matching deny patterns (e.g. su matching inside words like "result" or "ensure").

Two changes to fix this:

  • Strip heredoc bodies before checking deny patterns
  • Require command-like patterns (su, nc, sudo, etc.) to appear at a shell command position rather than anywhere in the string

Fixes #14766


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/14781 **Author:** [@moktamd](https://github.com/moktamd) **Created:** 3/11/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/agent-deny-pattern-false-positives` --- ### 📝 Commits (2) - [`dedf0de`](https://github.com/ollama/ollama/commit/dedf0de9831b141f9f1c7b4ca0d3f028035c584f) x/agent: fix false positive deny pattern matching in heredocs - [`341d256`](https://github.com/ollama/ollama/commit/341d2562cb00b661eeabfdcd5f92e2888a599286) address review: add $() and backtick to command prefixes, expand tests ### 📊 Changes **2 files changed** (+184 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `x/agent/approval.go` (+130 -6) 📝 `x/agent/approval_test.go` (+54 -1) </details> ### 📄 Description The `IsDenied` function uses naive substring matching against the full command string, which causes false positives when heredoc bodies contain substrings matching deny patterns (e.g. `su ` matching inside words like "result" or "ensure"). Two changes to fix this: - Strip heredoc bodies before checking deny patterns - Require command-like patterns (`su`, `nc`, `sudo`, etc.) to appear at a shell command position rather than anywhere in the string Fixes #14766 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-05 09:49:23 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#77127