# GHSA-2H3Q-9P6M-4HM4: ag2 authorization bypass

- Database: GitHub
- Severity: medium (stated by ghsa, no CVSS score)
- Published: 2026-09-25
- Modified: 2026-09-25

## Affected versions

- ag2 (PyPI): from 0.12.0, fixed in 1.1.0
- autogen (PyPI): from 0.12.0, through 0.14.1

## Description

## Summary

In AG2 (PyPI `ag2`), the `approval_required` middleware stores the user's "always" approval as a nested dict in `context.variables["ag:approval_required:always"]` (ag2/middleware/builtin/tools/approval.py:14, 56-72), documented as scoped to "the same context" (approval.py:101-103). When a parent agent delegates a subtask, `run_task` seeds the child with `variables=parent_context.variables.copy()` (ag2/tools/subagents/run_task.py:174) — a *shallow* copy, so the nested bypass dict is shared by reference. The consequence is bidirectional:

(a) forward — a tool the user approved with "always" in the parent is silently executed without prompting inside any delegated subtask;
(b) reverse — a single "always" answer given inside a subtask is written directly into the parent's bypass dict, so the parent subsequently executes that tool without prompting (concurrent sibling tasks likewise).

This contradicts run_task.py's own comment that child mutations are "intentionally not synced back" to the parent (run_task.py:169-173), and the library's own `isolate_variables` helper (ag2/acp/executor.py:324-341) documents that a shallow copy is not enough precisely because a nested "approval list" stays shared by reference.

## Affected version

- Originally found in: ag2 1.0.5.
- Retested against: **ag2 1.0.6** (latest PyPI release as of 2026-09-23, `pip download ag2 --no-deps`, unpacked and inspected).
- Retest conclusion: **still vulnerable**. ag2/tools/subagents/run_task.py:174 still reads `variables=parent_context.variables.copy()`; no deep copy or `isolate_variables` call was introduced on this delegation path, and the surrounding "intentionally not synced back" comment is unchanged.

## Vulnerable code path

| # | Location | Content |
|---|---|---|
| 1 | ag2/middleware/builtin/tools/approval.py:14, 56-72 | `BYPASS_KEY = "ag:approval_required:always"`; nested dict keyed by tool name permanently bypasses the prompt; documented contract "in the same context" (:101-103) |
| 2 | ag2/tools/subagents/run_task.py:169-174 | `variables=parent_context.variables.copy()` — shallow copy seeds the child; the comment claims child mutations do not sync back to the parent |
| 3 | ag2/agent.py:1545 | `self._agent_variables \| (variables or {})` — shallow merge keeps nested dicts shared |
| 4 | ag2/acp/executor.py:324-341 | `isolate_variables` deep-copies nested values; its docstring names "an approval list" as exactly the kind of value that must be isolated by value |
| 5 | ag2/tools/subagents/subagent_tool.py:55-62 | `Agent.as_tool` delegation reaches the same `run_task` call site |

## PoC

Offline runtime PoC against released ag2 1.0.5 with a scripted (TestConfig) model — fully offline, 15/15 assertions, exit 0:

- Forward leak: answer "always" once for a `deploy` tool in the parent → the delegated subtask (a different context) calls `deploy` with zero prompts; the bypass dict in the child `is` the same object as the parent's (object-identity check).
- Reverse leak: answer "always" once for a `purge_cache` tool inside the subtask → the authorization lands in the *parent's* dict → the parent then calls `purge_cache` with zero prompts.
- Control (documented behavior): a second call in the parent's own context is not re-prompted — the per-context contract itself holds; only cross-context sharing is broken.
- Fix control: seeding the child with the library's own `isolate_variables` (deepcopy) restores full bidirectional isolation — the child re-prompts for a tool the parent had approved, authorizations stay confined to the child, and the parent re-prompts afterwards. This demonstrates that the shared mutable object is the defect entity (inheritance of pre-delegation approvals would be a policy question, not this bug).

Offline, harmless marker-file PoC available on request.

## Impact

Any deployment using `TaskConfig` / `run_subtask` / `as_tool` delegation gets distorted approval semantics: one human approval effectively covers the parent, all subtasks and concurrent sibling tasks. Because subtasks can be initiated by the model itself (prompt-injection controllable), a single "always" induced inside a subtask silently amplifies the parent agent's permissions. Approval audit records (who approved what, in which context) no longer match the actual bypass scope.

## Suggested fix

Replace the shallow `variables.copy()` at ag2/tools/subagents/run_task.py:174 with the library's existing `isolate_variables(parent_context.variables)` (deep copy of nested values); audit the shallow merge at ag2/agent.py:1545 as well. Whether approvals that already exist before delegation should be inherited into subtasks should be an explicit policy parameter rather than an artifact of object sharing.

## Discoverer

Chengzhi Yi (GitHub @Tardfyou), contact: yimou@hust.edu.cn

## Related prior art

ag2 issue #3255 (2026-09-16, open) reports the same underlying design weakness — approval state stored in shared mutable `context.variables` — via a different vector (A2A context-variable sync silently disabling `approval_required()`). This report covers a distinct vector (run_task shallow-copy leak between parent and sub-task contexts, both directions) against the same state-store; the fixes likely coincide but the vectors are independently reachable.

## References

- https://github.com/ag2ai/ag2/security/advisories/GHSA-2h3q-9p6m-4hm4

Page: https://cve.now/GHSA-2H3Q-9P6M-4HM4

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
