Skip to content

Commit 5751d31

Browse files
authored
fix(server): send PushNotificationConfig.authentication as an Authorization header (a2aproject#1271)
## What Spec [4.3.3](https://a2a-protocol.org/latest/specification/#433-push-notification-payload) gives the webhook request an `Authorization: {authentication_scheme} {credentials}` header, built from `PushNotificationConfig.authentication`. `BasePushNotificationSender` never read that field - the only header it has ever sent is `X-A2A-Notification-Token`, from the sibling `token`. A receiver therefore had no credential to check and no way to tell a genuine push from a forged one, which is the whole point of registering `authentication` in the first place. Nothing suggests this was left to the application. The constructor docstring explicitly justifies delegating URL screening, on the grounds that the spec makes it a SHOULD, and says nothing about auth, which the spec makes a MUST. The code already reads the field next to it. This reads as an omission. ## Only when both halves are present `AuthenticationInfo` is a message, so a config can set `scheme` without `credentials`. Sending on that would put `Bearer ` with nothing after it on the wire - a header that looks like a credential and is not. Both must be non-empty. Note the singular `scheme`. Only the v0.3 compat type has repeated `schemes`, and `conversions.py:252-261` collapses it to `schemes[0]` on the way in, so the sender only ever deals with one. ## Heads-up on the ACTS side `SEC-PUSH-001`, `SEC-PUSH-002` and `PUSH-DELIV-001` currently pass in nightly CI for every SDK, so this may look like a fix to something that was not broken. It is not: the assertion that inspects the delivered request is new, added in [a2aproject/A2A@82c277f](a2aproject/A2A@82c277f). The corpus CI runs predates it, and the older tests only checked that the config API accepted the config - which, as that commit's own note puts it, "a server that stores it and pushes anonymously, or never pushes, satisfies". A consequence worth stating: no other SDK has been measured against the real assertion yet, so unlike the rest of this stack there is no cross-SDK corroboration here. The code is the evidence - `push_info.authentication` appears nowhere under `src/a2a/server/` before this change. ## Result Clears `SEC-PUSH-001`, `SEC-PUSH-002` (`must`) and `PUSH-DELIV-001` (`may`) on all three bindings, and with them the **last failing MUST**: | binding | must | verdict | | --- | --- | --- | | jsonrpc | 59/59 | CONFORMANT | | grpc | 47/47 | CONFORMANT | | rest | 49/49 | CONFORMANT | The three PRs after this one are SHOULD-level and change the verdict for nobody; they take the remaining non-MUST failures to zero. Closes a2aproject#585
1 parent c25022f commit 5751d31

2 files changed

Lines changed: 105 additions & 9 deletions

File tree

‎src/a2a/server/tasks/base_push_notification_sender.py‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,23 @@ async def _dispatch_notification(
9797
):
9898
return False
9999
try:
100-
headers = None
100+
headers: dict[str, str] = {}
101101
if push_info.token:
102-
headers = {'X-A2A-Notification-Token': push_info.token}
102+
headers['X-A2A-Notification-Token'] = push_info.token
103+
auth = push_info.authentication
104+
if push_info.HasField('authentication'):
105+
if auth.scheme and auth.credentials:
106+
headers['Authorization'] = (
107+
f'{auth.scheme} {auth.credentials}'
108+
)
109+
elif auth.scheme:
110+
logger.warning(
111+
'Push config %s sets an authentication scheme with no '
112+
'credentials; sending no Authorization header for '
113+
'task_id=%s',
114+
push_info.id,
115+
task_id,
116+
)
103117

104118
response = await self._client.post(
105119
url,

‎tests/server/tasks/test_push_notification_sender.py‎

Lines changed: 89 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
BasePushNotificationSender,
1010
)
1111
from a2a.types.a2a_pb2 import (
12+
AuthenticationInfo,
1213
StreamResponse,
1314
Task,
1415
TaskArtifactUpdateEvent,
@@ -36,8 +37,11 @@ def _create_sample_push_config(
3637
url: str = 'http://example.com/callback',
3738
config_id: str = 'cfg1',
3839
token: str | None = None,
40+
authentication: AuthenticationInfo | None = None,
3941
) -> TaskPushNotificationConfig:
40-
return TaskPushNotificationConfig(id=config_id, url=url, token=token)
42+
return TaskPushNotificationConfig(
43+
id=config_id, url=url, token=token, authentication=authentication
44+
)
4145

4246

4347
class TestBasePushNotificationSender(unittest.IsolatedAsyncioTestCase):
@@ -73,7 +77,7 @@ async def test_send_notification_success(self) -> None:
7377
self.mock_httpx_client.post.assert_awaited_once_with(
7478
config.url,
7579
json=MessageToDict(StreamResponse(task=task_data)),
76-
headers=None,
80+
headers={},
7781
)
7882
mock_response.raise_for_status.assert_called_once()
7983

@@ -103,6 +107,84 @@ async def test_send_notification_with_token_success(self) -> None:
103107
)
104108
mock_response.raise_for_status.assert_called_once()
105109

110+
async def _post_headers_for(self, **config_kwargs) -> dict[str, str] | None:
111+
"""Sends one notification and returns the headers it posted with."""
112+
task_data = _create_sample_task(task_id='task_auth')
113+
self.mock_config_store.get_info_for_dispatch.return_value = [
114+
_create_sample_push_config(**config_kwargs)
115+
]
116+
self.mock_httpx_client.post.return_value = AsyncMock(
117+
spec=httpx.Response, status_code=200
118+
)
119+
120+
await self.sender.send_notification(task_data.id, task_data)
121+
122+
return self.mock_httpx_client.post.await_args.kwargs['headers']
123+
124+
async def test_authentication_becomes_an_authorization_header(self) -> None:
125+
"""Authentication becomes `Authorization: {scheme} {credentials}`."""
126+
headers = await self._post_headers_for(
127+
authentication=AuthenticationInfo(
128+
scheme='Bearer', credentials='test-token'
129+
)
130+
)
131+
132+
assert headers == {'Authorization': 'Bearer test-token'}
133+
134+
async def test_authentication_and_token_are_sent_together(self) -> None:
135+
headers = await self._post_headers_for(
136+
token='notification-token',
137+
authentication=AuthenticationInfo(
138+
scheme='Bearer', credentials='test-token'
139+
),
140+
)
141+
142+
assert headers == {
143+
'X-A2A-Notification-Token': 'notification-token',
144+
'Authorization': 'Bearer test-token',
145+
}
146+
147+
async def test_authentication_without_credentials_sends_no_header(
148+
self,
149+
) -> None:
150+
"""A half-filled AuthenticationInfo yields no 'Bearer ' with nothing after it."""
151+
headers = await self._post_headers_for(
152+
authentication=AuthenticationInfo(scheme='Bearer')
153+
)
154+
155+
assert headers == {}
156+
157+
async def test_authentication_without_credentials_warns(self) -> None:
158+
"""A scheme with no credentials is valid to send, so say why it was dropped."""
159+
with self.assertLogs(
160+
'a2a.server.tasks.base_push_notification_sender', level='WARNING'
161+
) as logs:
162+
await self._post_headers_for(
163+
config_id='cfg-half-auth',
164+
authentication=AuthenticationInfo(scheme='Bearer'),
165+
)
166+
167+
assert any(
168+
'cfg-half-auth' in line and 'no ' in line for line in logs.output
169+
)
170+
171+
async def test_complete_authentication_does_not_warn(self) -> None:
172+
with self.assertNoLogs(
173+
'a2a.server.tasks.base_push_notification_sender', level='WARNING'
174+
):
175+
await self._post_headers_for(
176+
authentication=AuthenticationInfo(
177+
scheme='Bearer', credentials='test-token'
178+
)
179+
)
180+
181+
async def test_no_authentication_sends_no_authorization_header(
182+
self,
183+
) -> None:
184+
headers = await self._post_headers_for()
185+
186+
assert headers == {}
187+
106188
async def test_send_notification_no_config(self) -> None:
107189
task_id = 'task_send_no_config'
108190
task_data = _create_sample_task(task_id=task_id)
@@ -140,7 +222,7 @@ async def test_send_notification_http_status_error(
140222
self.mock_httpx_client.post.assert_awaited_once_with(
141223
config.url,
142224
json=MessageToDict(StreamResponse(task=task_data)),
143-
headers=None,
225+
headers={},
144226
)
145227
mock_logger.exception.assert_called_once()
146228

@@ -173,13 +255,13 @@ async def test_send_notification_multiple_configs(self) -> None:
173255
self.mock_httpx_client.post.assert_any_call(
174256
config1.url,
175257
json=MessageToDict(StreamResponse(task=task_data)),
176-
headers=None,
258+
headers={},
177259
)
178260
# Check calls for config2
179261
self.mock_httpx_client.post.assert_any_call(
180262
config2.url,
181263
json=MessageToDict(StreamResponse(task=task_data)),
182-
headers=None,
264+
headers={},
183265
)
184266
mock_response.raise_for_status.call_count = 2
185267

@@ -204,7 +286,7 @@ async def test_send_notification_status_update_event(self) -> None:
204286
self.mock_httpx_client.post.assert_awaited_once_with(
205287
config.url,
206288
json=MessageToDict(StreamResponse(status_update=event)),
207-
headers=None,
289+
headers={},
208290
)
209291

210292
async def test_send_notification_artifact_update_event(self) -> None:
@@ -228,7 +310,7 @@ async def test_send_notification_artifact_update_event(self) -> None:
228310
self.mock_httpx_client.post.assert_awaited_once_with(
229311
config.url,
230312
json=MessageToDict(StreamResponse(artifact_update=event)),
231-
headers=None,
313+
headers={},
232314
)
233315

234316

0 commit comments

Comments
 (0)