Skip to content

fix: add prompt injection guard for file content read by the agent #875

Description

@HttpGetBinary

Hey, found a security issue while looking at how the agent reads files from user repos.

The issue

When the agent reads files into its context window, there is no filter on the content. A malicious repo can embed instructions like "ignore all previous instructions" in a README or config file. Given this agent has shell execution and git access across multiple repos, a successful injection could cause real damage.

What this PR adds

A sanitizer at packages/agent/lib/prompt-injection-guard.ts that:

  • Scans file content for common injection patterns before it enters the context
  • Replaces matches with a visible [REDACTED] marker so the agent knows content was removed
  • Logs a warning with the file path for operator auditing

Usage

import { sanitizeFileContent } from "../lib/prompt-injection-guard";
const raw = await fs.readFile(path, "utf8");
const { content } = sanitizeFileContent(raw, path);
return content;

Happy to follow up with a second PR wiring this into the specific tools if preferred.


Patch available at: https://github.com/HttpGetBinary/open-agents/tree/fix/prompt-injection-agent-input

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions