Repository navigation
Python: Protect standalone FIDES session state from AG-UI request state - #9367
Conversation
Reserve the session-state key used by standalone FIDES security middleware, including any configured session_state_key visible on the agent or its client, so request and stored Shared State is no longer merged over it. The key stays in private Session Continuation State. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
The narrowly scoped protection is consistent with existing state ownership handling and has comprehensive coverage.
0 open findings
What changed in this PR
Protects standalone FIDES security state from untrusted AG-UI Shared State while preserving private session continuation.
Changes:
- Protects default and discoverable custom FIDES state keys.
- Adds endpoint and helper coverage for middleware configurations and malformed state.
- Documents protection and discovery boundaries.
| File | Description |
|---|---|
python/packages/ag-ui/agent_framework_ag_ui/_agent_run.py |
Discovers and protects FIDES state keys. |
python/packages/ag-ui/tests/ag_ui/test_run.py |
Tests key discovery and continuation serialization. |
python/packages/ag-ui/tests/ag_ui/test_endpoint.py |
Adds end-to-end security and persistence tests. |
python/packages/ag-ui/README.md |
Documents user-facing behavior. |
python/packages/ag-ui/AGENTS.md |
Records implementation invariants. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: No findings
Scope: full PR (1 commit(s)): 888506743616
Model: gpt-5.6-sol
Overview
The PR filters the default and discoverable custom standalone FIDES namespaces at the AG-UI Shared State merge boundary while preserving those namespaces in private Session Continuation State. The implementation is backed by default-key parity, middleware-location, malformed-state, snapshot-forgery, and cross-request continuation tests. No PR-introduced Critical, High, or Medium defect remained after reconciliation.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
No publishable findings remained after source verification for this scope.
Motivation & Context
AG-UI request Shared State is client-owned and is merged into
AgentSession.state, except for a protected set of server-owned namespaces. Standalone FIDES security middleware (LabelTrackingFunctionMiddleware,PolicyEnforcementFunctionMiddleware) keeps its context label, hidden variables, and pending policy approvals inAgentSession.stateunder__agent_framework_fides_security__(or its configuredsession_state_key), but that key was not in the protected set. This extends the protected-namespace handling used for tool approval state (#8714) to that security state.Description & Review Guide
_request_state_protected_keysnow also protects the standalone FIDES session-state key. The default key is always protected; a configuredsession_state_keyis discovered from FIDES function middleware on the agent or its client.AGENTS.mdand README are updated.AgentSession.state. Server-produced FIDES state persists across requests as before, and ordinary Shared State is unchanged. No public API, dependency, or core changes.session_state_keyon middleware that is injected after the run starts, or hidden behind a wrapper that does not expose its key, is not discovered. The default key is always protected, andSecureAgentConfig(provider state under itssource_id) is unaffected. This boundary is documented._security_session_state_keyattribute (cross-package private usage perCODING_STANDARD.md), and spelling the default key literally because importingagent_framework.securityemits its experimental-feature warning for every AG-UI user. A test pins the literal to the core constant._RESERVED_SERVICE_SESSION_STATE_KEYS, which would also drop it from private Session Continuation State.Related Issue
N/A - no existing issue. This extends the protected-namespace handling from #8714 to another server-owned session-state key.
AI Assistance
AI assistance details: Implementation, tests, documentation, and this PR description were AI-assisted (GitHub Copilot).
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.