Skip to content

fix(agents): keep authenticated A2A config on Agent.copy() - #9503

Open
HanYuanLu wants to merge 1 commit into
crewAIInc:mainfrom
HanYuanLu:fix/issue-9447
Open

HanYuanLu wants to merge 1 commit into
crewAIInc:mainfrom
HanYuanLu:fix/issue-9447

Conversation

@HanYuanLu

Copy link
Copy Markdown
Contributor

Related issue

Fixes #9447

Summary

Agent.copy() rebuilt the agent from model_dump(). An authenticated A2A
config became a plain dict and could not be validated against the abstract
ClientAuthScheme. Keep a2a out of the dump and pass a deep copy through,
the same way llm, tools, and knowledge are already passed.

Verification

  • Tests added or updated for the changed behavior
  • Relevant tests and quality checks pass locally

uv run pytest lib/crewai/tests/agents/test_agent.py::test_agent_copy_keeps_a2a_auth -q --allowed-hosts=127.0.0.1

Additional context

None.

@strix-security

strix-security Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Strix Security Review

✅ No open security findings.

PR summary: `Agent.copy()` rebuilt the agent from `model_dump()`, which flattened an authenticated A2A client config into a plain dict that failed validation against the abstract `ClientAuthScheme`, so copying such an agent raised. The PR excludes `a2a` from the dump and passes a `deepcopy` of the config to the constructor, with a regression test asserting the auth scheme and token survive the copy as distinct objects.

Review summary

This PR fixes BaseAgent.copy() so an agent with an authenticated A2A client config can be copied at all: a2a is kept out of the model_dump() round-trip and the live config is passed to the constructor as a deepcopy, the same pattern already used for llm, tools, and knowledge.

No security issues were confirmed. Every candidate was traced and rejected: the copy path performs no network I/O and never persists or logs the dumped data, so the preserved credential is a per-instance deepcopy that stays inside the same object graph; the copy neither reads nor re-derives auth, so it cannot downgrade or drop a scheme; and the surrounding A2A code (auth-store keying, card-nominated transport URL, server-side auth enforcement) is byte-identical with and without this PR and is not reached by copy(). One behaviour note that is not security-relevant: the a2a keyword is passed unconditionally to type(self)(...), which in-repo adapters ignore via pydantic's default extra="ignore".

Ruled out (6)
  • Can the deepcopied A2A auth config leak its token, or be shared so one principal acts as another?
    The dump in copy() is a local value splatted into the constructor and never logged or serialized, and the deepcopy gives the copy its own auth instance and token cache, so nothing is aliased between the original and the copy.
  • Does the new deepcopy place one principal's OAuth2 token into a store slot another principal reads?
    The auth store and its static-config hash key live entirely in unchanged A2A code, copy() never fetches an agent card or writes that store, and delegation passes the config's own auth instance, so the collision behaves identically without this PR.
  • Can a remote agent card nominate the host that receives the operator's A2A credentials?
    That URL negotiation lives in unchanged transport and delegation code that is reachable without copy(); copy() performs no network I/O, and the operator's configured peer already receives the credential when the card is fetched.
  • Does the a2a passthrough make a copied agent's A2A server auth go unenforced or get downgraded?
    No code path in the repository calls ServerAuthScheme.authenticate, copy() never reads or re-derives auth, and the deepcopied scheme object is validated and stored unchanged on the copy, so enforcement is exactly as absent as before.
  • Does passing the a2a keyword to BaseAgent subclasses that do not declare the field break copies?
    It is a developer-side compatibility concern with no attacker-controlled input: the in-repo adapters inherit pydantic's default extra=ignore and never carry an a2a config, so nothing is dropped or mis-typed.
  • Does copy() carrying the source agent's accumulated tools_results expose one user's tool output to another?
    The field was already outside the exclusion set before this PR and the changed lines do not touch it, and a copy is of the same agent rather than a cross-principal one.

Review 1 on this PR · 9f42384 · requested Nov 17 06:28 UTC when the PR was opened


Reviewed by Strix
Re-run review · Configure security review settings · Try a deeper review with @strix-security /deep

@HanYuanLu HanYuanLu closed this Nov 20, 2026
@HanYuanLu HanYuanLu reopened this Nov 20, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Agent.copy() / Crew.copy() fails with TypeError when A2A config has auth (ClientAuthScheme is abstract)

1 participant