Skip to content

Python: Information-flow control based prompt injection defense - #5024

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 23 commits into
microsoft:feature/python-fidesfrom
shrutitople:ifc-pia-defense
Apr 16, 2026
Merged

Python: Information-flow control based prompt injection defense#5024
Eduard van Valkenburg (eavanvalkenburg) merged 23 commits into
microsoft:feature/python-fidesfrom
shrutitople:ifc-pia-defense

Conversation

@shrutitople

@shrutitople shrutitople commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Motivation and Context

LLM agents are vulnerable to prompt injection attacks — malicious instructions in external content (tool results, API responses) that cause data exfiltration or unauthorized actions.
This PR introduces FIDES, a deterministic defense based on information flow control (IFC). Instead of detecting injections, it tracks content provenance via labels and enforces policies — untrusted content can't influence trusted operations, private data can't leak to public channels.

Description

Security Primitives, Middleware & Tools — _security.py (single consolidated module)

  • Labels: IntegrityLabel (trusted/untrusted) × ConfidentialityLabel (public/private/user_identity)
  • Lattice combination: most-restrictive-wins via combine_labels()
  • Variable indirection: ContentVariableStore replaces untrusted content with opaque VariableReferenceContent placeholders — the LLM never sees raw untrusted data
  • LabelTrackingFunctionMiddleware — 3-tier automatic label propagation:
    1. Per-item embedded labels (additional_properties.security_label)
    2. Tool-level source_integrity declaration
    3. Join of input argument labels (fallback)
  • PolicyEnforcementFunctionMiddleware — blocks or requests approval when context confidentiality exceeds a tool's max_allowed_confidentiality
  • SecureAgentConfig — one-line setup wiring middleware, tools, and instructions
  • quarantined_llm — isolated LLM call (no tools) for safe summarization of untrusted content
  • inspect_variable — controlled access to hidden variables with label awareness
  • All results use list[Content] (aligned with upstream FunctionTool.invoke())

Framework Integration — _tools.py, DevUI

  • FunctionApprovalRequest content type for human-in-the-loop policy enforcement
  • DevUI maps approval requests to interactive approve/reject UI

Tests — test_security.py

  • 115 unit tests covering label propagation, variable indirection, policy enforcement, quarantine, 3-tier labeling, and edge cases

Samples — python/samples/02-agents/security/

Sample Demonstrates
email_security_example.py Integrity-based defense against injection in email content
repo_confidentiality_example.py Confidentiality-based data exfiltration prevention
github_mcp_labels_example.py Integration with GitHub MCP server labels

Documentation

  • FIDES_DEVELOPER_GUIDE.md (in python/samples/02-agents/security/), python/samples/02-agents/security/README.md, docs/features/FIDES_IMPLEMENTATION_SUMMARY.md

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible (115 new tests)
  • Is this a breaking change? No — all changes are additive; security middleware is opt-in via SecureAgentConfig

Copilot AI review requested due to automatic review settings April 1, 2026 10:00
@markwallace-microsoft Mark Wallace (markwallace-microsoft) added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python labels Apr 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Introduces FIDES, an information-flow control (IFC) security layer for the agent framework to deterministically mitigate prompt injection and data exfiltration via integrity/confidentiality labels, variable indirection, and policy enforcement.

Changes:

  • Add core security primitives (labels, variable store, lineage) plus security middleware for label propagation and policy enforcement.
  • Add security tools (quarantined_llm, inspect_variable) and DevUI support for displaying/handling policy-violation approval requests.
  • Add new security samples and extensive documentation/ADRs describing FIDES usage and design.

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
python/samples/getting_started/security/repo_confidentiality_example.py Sample demonstrating confidentiality-based exfiltration prevention.
python/samples/getting_started/security/github_mcp_labels_example.py Sample demonstrating parsing GitHub MCP label metadata and enforcing policies.
python/samples/getting_started/security/email_security_example.py Sample demonstrating integrity-based prompt injection defense + quarantine processing.
python/samples/getting_started/security/init.py Marks security samples as a package.
python/packages/devui/agent_framework_devui/_mapper.py Adds policy-violation details to approval request events sent to the UI.
python/packages/devui/agent_framework_devui/_executor.py Propagates policy-violation metadata through approval responses.
python/packages/core/agent_framework/_tools.py Adds policy-approval plumbing and placeholder replacement around tool approval flows.
python/packages/core/agent_framework/_security_tools.py Implements quarantine/inspection tools and tool-use instructions for hidden content.
python/packages/core/agent_framework/_security_middleware.py Implements label tracking, variable hiding, and policy enforcement middleware.
python/packages/core/agent_framework/_security.py Adds label types, label combination, variable store, and lineage/message labeling primitives.
python/packages/core/agent_framework/init.py Exposes security APIs and adds ai_function alias.
docs/decisions/0011-prompt-injection-defense.md ADR describing the FIDES design and rationale.
QUICK_START_FIDES.md Quick-start guide for configuring and using FIDES.
FIDES_IMPLEMENTATION_SUMMARY.md High-level implementation summary of FIDES components and deliverables.
FIDES_DEVELOPER_GUIDE.md Full developer guide for FIDES concepts, APIs, best practices, and examples.

Comment thread python/samples/getting_started/security/repo_confidentiality_example.py Outdated
Comment thread python/samples/02-agents/security/email_security_example.py
Comment thread python/packages/core/agent_framework/_security_middleware.py Outdated
Comment thread python/packages/core/agent_framework/_security_middleware.py Outdated
Comment thread python/packages/devui/agent_framework_devui/_executor.py Outdated
Comment thread python/samples/getting_started/security/github_mcp_labels_example.py Outdated
Comment thread docs/decisions/0011-prompt-injection-defense.md Outdated
@github-actions github-actions Bot changed the title Information-flow control based prompt injection defense Python: Information-flow control based prompt injection defense Apr 1, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code overall is looking good, I would like to see all _security*.py files folded into the _security.py file, that is more in line with the rest of the repo.

Comment thread python/packages/core/agent_framework/_tools.py Outdated
Comment thread python/packages/core/agent_framework/_security.py Outdated
Comment thread python/packages/core/agent_framework/_security_tools.py Outdated
Comment thread python/packages/core/agent_framework/_security_tools.py Outdated
Comment thread python/packages/core/agent_framework/_security_tools.py Outdated
Comment thread python/samples/getting_started/security/email_security_example.py Outdated
Comment thread python/samples/02-agents/security/FIDES_DEVELOPER_GUIDE.md
Comment thread python/samples/getting_started/security/__init__.py Outdated
Comment thread docs/features/FIDES_IMPLEMENTATION_SUMMARY.md
Comment thread python/samples/02-agents/security/README.md
Comment thread docs/decisions/0011-prompt-injection-defense.md
Comment thread python/packages/core/agent_framework/_tools.py Outdated
Comment thread PR_DESCRIPTION.md Outdated
Comment thread simple_agent_example.py Outdated
@moonbox3 Evan Mattson (moonbox3) added .NET Usage: [Issues, PRs], Target: .Net workflows Usage: [Issues, PRs], Target: Workflows labels Apr 13, 2026
@github-actions github-actions Bot changed the title Python: Information-flow control based prompt injection defense .NET: Python: Information-flow control based prompt injection defense Apr 13, 2026
@moonbox3

Evan Mattson (moonbox3) commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _security.py70119372%420–421, 439, 442–443, 518–519, 521, 570, 581, 596, 606, 673–674, 677, 681, 688–689, 691, 698–701, 703, 706–713, 715, 718–721, 723–725, 727–728, 731–732, 734–735, 738–739, 741–745, 748–752, 754, 1012, 1016–1017, 1020–1023, 1029–1030, 1060–1061, 1087–1095, 1116, 1219, 1223, 1254–1255, 1281–1282, 1286–1287, 1321–1324, 1406–1407, 1412–1417, 1422–1424, 1455, 1669, 1674–1675, 1679, 1683–1685, 1727, 1731–1732, 1734, 1738, 1742, 1745, 1748, 1754, 1761, 1771–1772, 1787, 1821, 1825–1827, 1830, 1834, 1837, 1840, 1846, 1851, 1861–1862, 1901, 1942–1943, 1968, 2064, 2092–2094, 2129–2131, 2139, 2147, 2370, 2402–2403, 2405, 2407–2409, 2412, 2418, 2427, 2433–2434, 2436, 2467, 2471–2474, 2476, 2621–2624, 2627–2628, 2632, 2634, 2636, 2639–2643, 2650, 2655, 2666–2667, 2669, 2671–2673, 2743, 2753–2754
   _tools.py9809390%190–191, 364, 366, 379, 404–406, 414, 432, 446, 453, 460, 483, 485, 492, 500, 539, 583, 587, 619–621, 623, 629, 674–676, 678, 701, 727, 731, 769–771, 775, 797, 909–915, 951, 963, 965, 967, 970–973, 994, 998, 1002, 1016–1018, 1362, 1372, 1391, 1456, 1476, 1494–1500, 1629, 1633, 1679, 1740–1741, 1853, 1878–1879, 1900, 1920, 1922, 1978, 2041, 2213–2214, 2234, 2290–2291, 2429–2430, 2497, 2502, 2509
TOTAL28414339988% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
5708 20 💤 0 ❌ 0 🔥 1m 29s ⏱️

@eavanvalkenburg Eduard van Valkenburg (eavanvalkenburg) changed the title .NET: Python: Information-flow control based prompt injection defense Python: Information-flow control based prompt injection defense Apr 15, 2026
@eavanvalkenburg Eduard van Valkenburg (eavanvalkenburg) removed the .NET Usage: [Issues, PRs], Target: .Net label Apr 15, 2026
@moonbox3 Evan Mattson (moonbox3) added the .NET Usage: [Issues, PRs], Target: .Net label Apr 15, 2026
@github-actions github-actions Bot changed the title Python: Information-flow control based prompt injection defense .NET: Python: Information-flow control based prompt injection defense Apr 15, 2026
@eavanvalkenburg
Eduard van Valkenburg (eavanvalkenburg) changed the base branch from main to feature/python-fides April 16, 2026 10:26
@eavanvalkenburg
Eduard van Valkenburg (eavanvalkenburg) merged commit becd2f7 into microsoft:feature/python-fides Apr 16, 2026
21 of 32 checks passed
@github-project-automation github-project-automation Bot moved this from Community PR to Done in Agent Framework Apr 16, 2026
Eduard van Valkenburg (eavanvalkenburg) pushed a commit that referenced this pull request May 4, 2026
* fides integration

* documentation

* documentation

* documentation

* human-approval on policy violation

* numenous hyena 'works'

* IFC based implementation

* minor edits in documentation

* rebasing the branch and running the email example

* Add security tests for IFC middleware

* Fix Role.TOOL NameError in approval handling

* tiered labelling scheme

* 3 tier labelling scheme in middleware

* Adapt security middleware to list[Content] tool results

* Refactor SecureAgentConfig as context provider and address Copilot review comments

* Update FIDES docs to reflect context provider pattern and update code for ContextProvider rename

* Fix security examples: use OpenAIChatClient instead of non-existent AzureOpenAIChatClient

* Address PR review: consolidate security modules, remove ContentLineage, update docs

* remove unrelated files

* remove comment from _tools.py and rename decision file

* Fix CI failures: Bandit B110, broken md links, hosted approval passthrough

* apply template to decision doc 0024

* minor fixes to decision doc 0024

---------

Co-authored-by: Aashish <t-akolluri@microsoft.com>
Giles Odigwe (giles17) pushed a commit to giles17/agent-framework that referenced this pull request May 5, 2026
…5331)

* Python: Information-flow control based prompt injection defense (microsoft#5024)

* fides integration

* documentation

* documentation

* documentation

* human-approval on policy violation

* numenous hyena 'works'

* IFC based implementation

* minor edits in documentation

* rebasing the branch and running the email example

* Add security tests for IFC middleware

* Fix Role.TOOL NameError in approval handling

* tiered labelling scheme

* 3 tier labelling scheme in middleware

* Adapt security middleware to list[Content] tool results

* Refactor SecureAgentConfig as context provider and address Copilot review comments

* Update FIDES docs to reflect context provider pattern and update code for ContextProvider rename

* Fix security examples: use OpenAIChatClient instead of non-existent AzureOpenAIChatClient

* Address PR review: consolidate security modules, remove ContentLineage, update docs

* remove unrelated files

* remove comment from _tools.py and rename decision file

* Fix CI failures: Bandit B110, broken md links, hosted approval passthrough

* apply template to decision doc 0024

* minor fixes to decision doc 0024

---------

Co-authored-by: Aashish <t-akolluri@microsoft.com>

* Python: follow up FIDES security flow (microsoft#5330)

* Python: follow up FIDES security flow

Refine the secure approval path, mark the security classes with the FIDES experimental feature label, and clean up the related docs/tests. Also fix workspace-level validation regressions uncovered while running the full Python check suite.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Python: remove FIDES GitHub MCP sample

Drop the GitHub MCP security sample from the FIDES follow-up branch while keeping the remaining security docs and samples intact.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Address PR review: fix paths and update FIDES implementation (microsoft#5352)

* Python: updated import naming and comment from review (microsoft#5421)

* updated import naming and comment from review

* Add approval replay None call-id test

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Python: Address PR 5331 comments and track sesssion while calling Agent in email_security_example (microsoft#5446)

* Address PR review: fix paths and update FIDES implementation

* Address PR comments and add session tracking in email example in samples

* Fix session creation and resolve merge conflict in docstring example

* Resolve merge conflict in docstring example

* Python: add test for empty-message pruning in approval result replacement (microsoft#5617)

Adds test coverage for the second-pass logic in
`_replace_approval_contents_with_results` that removes messages whose
`contents` list becomes empty after first-pass content removal.

Addresses review comment on PR microsoft#5331:
microsoft#5331 (comment)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: shrutitople <shruti.tople@gmail.com>
Co-authored-by: Aashish <t-akolluri@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python workflows Usage: [Issues, PRs], Target: Workflows

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants