MPP: credential is always sent in Authorization, ignoring header="Payment-Authorization" in the challenge

未關閉 適合新手
#702 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@abhiramshaji-cyber 已經在處理了。

開始於 2026年10月27日。

  • #719 來自 @abhiramshaji-cyber —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
68/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python
領域
api, backend

研究方向

從 bedrock_agentcore/payments/manager.py 中的 PaymentManager._generate_mpp_payment_header 開始,追蹤選定的 challenge header 如何傳遞至 generate_payment_header。檢查 Strands handler 和 LangGraph middleware 如何套用傳回的 header,並為 Payment-Authorization 和預設的 Authorization 行為新增或執行針對性測試。當選定的 header 帶有憑證,且呼叫端既有的 Authorization 值獲得保留時,即表示完成。

由索引模型根據 Issue 內容生成。

描述

bug

Describe the bug

The MPP core spec lets a challenge choose the request header for the credential. With header="Payment-Authorization", the client must send the credential in Payment-Authorization, so that Authorization stays free for the client's own authentication (draft-httpauth-payment-01, section "Credentials"). The server accepts the credential only from the selected field, and a client that does not support Payment-Authorization must not send a credential for such a challenge.

PaymentManager._generate_mpp_payment_header always returns {"Authorization": "Payment <credential>"}, whatever the selected challenge says. For a challenge with header="Payment-Authorization", the SDK:

  • pays it (ProcessPayment is called);
  • returns the credential under Authorization, where the server does not look for it;
  • replaces the caller's own Authorization value (for example a Bearer token) when the Strands plugin or the LangGraph middleware applies the header to the retried request (apply_payment_header updates the headers dict).

mppx servers send this parameter when created with Mppx.create({ requiresAuth: true, ... }) (added in mppx 0.9.0), and then read the credential only from Payment-Authorization.

To Reproduce

bedrock-agentcore 1.24.1 (main at b70e0b7), Python 3.10:

import base64
import json
from unittest.mock import MagicMock, patch

from bedrock_agentcore.payments.integrations.handlers import GenericPaymentHandler
from bedrock_agentcore.payments.manager import PaymentManager

request = {
    "amount": "1000",
    "currency": "0x036CbD53842c5426634e7929541eC2318f3dCF71",
    "recipient": "0x742d35Cc6634C0532925a3b844Bc9e7595f8fE00",
    "methodDetails": {"chainId": 84532},
}
encoded = base64.urlsafe_b64encode(json.dumps(request, separators=(",", ":")).encode()).decode().rstrip("=")
challenge = (
    f'Payment id="x7Tg2pLqR9mKvNwY3hBcZa", realm="api.example.com", method="evm", intent="charge", '
    f'header="Payment-Authorization", request="{encoded}"'
)

with patch("boto3.Session") as session:
    session.return_value.region_name = "us-west-2"
    manager = PaymentManager(
        payment_manager_arn="arn:aws:bedrock-agentcore:us-west-2:123456789012:payment-manager/pm-abc123",
        region_name="us-west-2",
    )
manager._payment_client = MagicMock()
manager._payment_client.get_payment_instrument.return_value = {
    "paymentInstrument": {"paymentInstrumentDetails": {"embeddedCryptoWallet": {"network": "ETHEREUM"}}}
}
manager._payment_client.process_payment.return_value = {
    "processPayment": {
        "status": "PROOF_GENERATED",
        "paymentOutput": {"mpp": {"selectedPaymentId": "x7Tg2pLqR9mKvNwY3hBcZa", "paymentCredential": "eyJ0b2tlbiI6MX0"}},
    }
}

payment_header = manager.generate_payment_header(
    user_id="user-1",
    payment_instrument_id="pi-1",
    payment_session_id="ps-1",
    payment_required_request={"statusCode": 402, "headers": {"WWW-Authenticate": challenge}, "body": {}},
)
print("ProcessPayment calls:", manager._payment_client.process_payment.call_count)
print("payment header:", payment_header)

tool_input = {"url": "https://api.example.com/resource", "headers": {"Authorization": "Bearer mF_9.B5f-4.1JqM"}}
GenericPaymentHandler().apply_payment_header(tool_input, payment_header)
print("retried request headers:", tool_input["headers"])

Output:

ProcessPayment calls: 1
payment header: {'Authorization': 'Payment eyJ0b2tlbiI6MX0'}
retried request headers: {'Authorization': 'Payment eyJ0b2tlbiI6MX0'}

Expected behavior

For a challenge with header="Payment-Authorization", generate_payment_header returns {"Payment-Authorization": "Payment <credential>"}, and the retried request keeps its own Authorization header. A challenge without header keeps using Authorization, as now. Until the field is supported, such a challenge should not be selected or paid.

Additional context

  • The parameter was added to the spec in tempoxyz/mpp-specs#328 (2026-08-25), a week after MPP support landed here in #643 (2026-08-18).
  • The spec also asks the client to echo header in the credential's challenge object. The raw challenge, including header, is already forwarded to ProcessPayment, so that part may be handled by the service; I could not check it.
主要語言
Python
星號
786
分支
163
平均合併
4 小時
30 天內合併 PR
22

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

aws/bedrock-agentcore-sdk-python 的其他 Issue

查看 aws/bedrock-agentcore-sdk-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。