APIKeyAuth cookie mode overwrites existing Cookie headers

Đang mở Phù hợp với người mới
#9,706 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@Kiko0301 đang làm issue này rồi.

Từ ngày 24/11/2026.

  • #9711 của @Kiko0301 — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
api, authentication

Hướng nghiên cứu

Bắt đầu từ lib/crewai/src/crewai/a2a/auth/client_schemes.py tại APIKeyAuth.apply_auth, nơi nhánh cookie thay thế toàn bộ header Cookie. Sao chép đoạn mã tái hiện vào một script thử nghiệm để xác nhận các cặp session và theme bị mất, sau đó sửa nhánh này để tìm header hiện có mà không phân biệt chữ hoa chữ thường và nối thêm ; name=key thay vì gán lại. Các trường hợp hiện có và mới nằm trong lib/crewai/tests/a2a/test_client_schemes.py; chạy file này để kiểm tra việc giữ nguyên giá trị, tạo mới khi header chưa tồn tại và tái sử dụng cookie viết thường. Người báo lỗi cho biết sẽ có PR sửa lỗi theo sau, vì vậy hãy hỏi maintainer trước khi làm trùng công việc.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
61.2k
Fork
9.2k
Merge trung bình
1 ngày 13 giờ
Pull request đã merge (30 ngày)
221

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của crewAIInc/crewAI

Tất cả issue của crewAIInc/crewAI

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.