Skip to content

Commit 59604a2

Browse files
docs: add Section 9 for Identity Propagation and Context
Adds technical guidance on propagating user identity (JWT) to backend tools to prevent privilege escalation in AI agents. Closes #2041.
1 parent 109a3b4 commit 59604a2

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

cheatsheets/AI_Agent_Security_Cheat_Sheet.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,33 @@ class SecureContextBuilder:
660660
context = "\n---\n".join(protected_docs)
661661
return context[:max_tokens * 4] # Rough char estimate
662662
```
663+
### 9. Identity Propagation & Context
664+
665+
-Enforce User Context Propagation:
666+
Require agents to pass the user's original authentication token (e.g., JWT) to any backend tool or API.
667+
-Validate at the Source:
668+
Ensure backend services validate the user's identity and permissions, preventing the agent from acting as a privileged "super-user".
669+
-Maintain Audit Trails:
670+
Log all agent actions with the associated user identity to ensure non-repudiation and clear accountability.
671+
-To ensure the agent only has the same permissions as the user (no "Super-User" powers).
672+
-Telling the database: This request is coming from User, only show him his own data.
673+
-Prevent Privilege Escalation: Ensure the agent only possesses the same permissions as the active user by acting as a passthrough for the user's authenticated identity.
674+
675+
Implementation: Passing User Identity to AI Tools (Python/FastAPI)
676+
```Python
677+
from fastapi import Header, HTTPException
678+
async def secure_ai_tool(data: dict, authorization: str = Header(None)):
679+
"""
680+
Ensures the AI Agent acts as a passthrough for the user's identity.
681+
"""
682+
# 1. Extract and validate the HUMAN user's identity from the bearer token
683+
user = verify_jwt(authorization)
684+
if not user:
685+
raise HTTPException(status_code=401, detail="Valid user context required")
686+
# 2. Perform the action using the specific human user's permissions
687+
return await db.execute_action(user_id=user.id, **data)
688+
```
689+
663690

664691
## Do's and Don'ts
665692

0 commit comments

Comments
 (0)