APIKeyAuth cookie mode overwrites existing Cookie headers

Open Beginner friendly
#9,706 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@Kiko0301 is already working on this.

Since Nov 24, 2026.

  • #9711 by @Kiko0301 — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python

Research direction

Start in lib/crewai/src/crewai/a2a/auth/client_schemes.py at APIKeyAuth.apply_auth, where the cookie branch replaces the entire Cookie header. Copy the reproduction snippet into a scratch script to confirm the session and theme pairs disappear, then make the branch look up an existing header case-insensitively and append ; name=key instead of assigning. Existing and new cases live in lib/crewai/tests/a2a/test_client_schemes.py; run that file to check preservation, creation when absent, and lowercase cookie reuse. Note the reporter says a fix PR will follow, so check with a maintainer before duplicating work.

Written by the indexing model from the issue text.

Description

Description

In lib/crewai/src/crewai/a2a/auth/client_schemes.py, APIKeyAuth.apply_auth handles the cookie location by assigning the whole Cookie header:

if self.location == "header":
    headers[self.name] = self.api_key
elif self.location == "cookie":
    headers["Cookie"] = f"{self.name}={self.api_key}"

Any cookies already present on the request are discarded. A client that carries a session cookie (or any other cookie) and uses API key auth in cookie mode loses those cookies, so the server sees only the API key pair.

Reproduction

import asyncio
from crewai.a2a.auth.client_schemes import APIKeyAuth

auth = APIKeyAuth(api_key="secret", location="cookie", name="api_key")
headers = {"Cookie": "session=abc123; theme=dark"}

print(asyncio.run(auth.apply_auth(None, headers)))
# {'Cookie': 'api_key=secret'}

On current main (d1aa368749f932311a6c1916e63a756877cab55a) the pre-existing session=abc123; theme=dark pair is gone.

Expected behavior

The API key is added as an additional cookie pair (session=abc123; theme=dark; api_key=secret), preserving existing cookies and the header's original casing when it is already present.

Suggested fix

Look up an existing Cookie header case-insensitively, append ; <name>=<key> when one exists, and create the header only when absent. A fix PR will follow.

Tests

New tests in lib/crewai/tests/a2a/test_client_schemes.py cover preserving an existing Cookie header, creating it when absent, and reusing a lowercase cookie header name. Two of the three fail on unmodified main.

Prepared with an AI coding agent. Please apply the llm-generated label; this account cannot set repository labels.

Dominant language
Python
Stars
61.2k
Forks
9.2k
Avg merge
1d 12h
Merged PRs (30d)
228

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from crewAIInc/crewAI

All issues in crewAIInc/crewAI

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.