Skip to content

fix: validate push notification URLs and REST listTasks params - #625

Closed
ez-lbz wants to merge 0 commit into
a2aproject:mainfrom
ez-lbz:main
Closed

ez-lbz wants to merge 0 commit into
a2aproject:mainfrom
ez-lbz:main

Conversation

@ez-lbz

@ez-lbz ez-lbz commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

What changed

1. Validate push notification URLs before sending

Problem: Webhook URLs from client-supplied TaskPushNotificationConfig were POSTed as-is to whatever target the config named — loopback, private-network, link-local or cloud-metadata endpoints included — and HTTP redirects were followed with no re-checking, so a config pointing at a public URL could be redirected onto an internal endpoint in a second hop.

Fix (DefaultPushNotificationSender):

  • The URL must be http/https and must not target loopback, private (RFC 1918 / ULA / CGNAT), link-local, unspecified or multicast literal addresses (IPv4 and IPv6, including IPv4-mapped ::ffff: forms), localhost, or well-known cloud metadata hostnames (metadata.google.internal, metadata.azure.com, metadata.goog).
  • Redirects are followed manually (redirect: 'manual') with every hop re-validated against the same checks (max 10 hops); the notification token / Authorization header is dropped when a hop crosses to a different host.
  • New allowPrivateNetworks option (default false, guard enabled) lets trusted internal deployments opt out — e.g. a webhook hosted on the same host or private network.

Behavior change: senders now refuse private targets by default; deployments that intentionally push to same-host or private webhooks must pass allowPrivateNetworks: true. Validation is static (literal address + hostname checks); DNS resolution happens inside fetch at connection time, so hostname-based DNS-rebinding is not covered.

2. Strict parsing of pageSize / historyLength in REST listTasks

Problem: listTasks parsed pageSize and historyLength with bare Number(). Non-numeric query values became NaN, which slips through the 1..100 range check (NaN < 1 is false) and makes slice(-NaN) behave like slice(0) — historyLength=abc returned the full task history and pageSize=abc returned an empty page, instead of a malformed-request error.

Fix (RestTransportHandler.listTasks):

  • pageSize is parsed with parseInt and validated as an integer in 1..100.
  • historyLength now reuses the existing parseHistoryLength (same as getTask), rejecting non-integers and negative values.
  • Invalid input is rejected with RequestMalformedError.

Testing

  • Added unit tests: 6 for the push-URL guard (blocked targets, allowed public URL, blocked redirect hop, cross-host token stripping, allowPrivateNetworks opt-out), 4 for listTasks parsing.
  • Adapted existing push-notification tests to opt into loopback webhooks via allowPrivateNetworks: true.
  • Full suite: 68 test files, 1506 tests passing.
  • tsc (source + test configs), npm run build (tsup), and npm run test-build (workers-safe / grpc / express bundles) all pass.

@ez-lbz
ez-lbz requested a review from a team as a code owner August 6, 2026 13:21
@github-actions

github-actions Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

🧪 Code Coverage

⬇️ Download Full Report

Base PR Delta
src/server/push_notification/default_push_notification_sender.ts 96.59% 86.86% 🔴 -9.73%
src/server/transports/rest/rest_transport_handler.ts 98.69% 98.75% 🟢 +0.06%
Total 91.19% 91% 🔴 -0.19%

Generated by coverage-comment.yml

@ez-lbz ez-lbz closed this Aug 25, 2026
bartek-gralewicz added a commit that referenced this pull request Sep 17, 2026
…ize (#685)

# Description

- [x] Follow the CONTRIBUTING Guide
- [x] Conventional Commits title
- [x] Tests and linter pass
- [x] Docs updated if necessary

Fixes #679

## Summary

`RestTransportHandler.listTasks` used truthy `Number()` on query
strings. `historyLength=0` became undefined, so listTasks returned full
history instead of omitting it. `getTask` already keeps 0 via
`parseHistoryLength`. The JS REST client sends `historyLength=0`, so a
same-SDK call was wrong.

`pageSize=abc` became NaN. The range check `pageSize < 1 || pageSize >
100` is false for NaN, so the store did `slice(0, NaN)` and returned an
empty page with HTTP 200.

Closed unmerged PR #625 called out the REST Number() hole. Open PR #639
caps historyLength at 1000 and does not fix the 0 drop or NaN pageSize.

listTasks now reuses `parseHistoryLength` and adds `parsePageSize`
(integer 1..100). DefaultRequestHandler.listTasks also rejects
non-integer pageSize so JSON-RPC/gRPC cannot slip NaN through.

## Testing

```
npx --no-install vitest run test/server/rest_transport_handler.spec.ts test/server/default_request_handler.spec.ts
```

130 passed.

Signed-off-by: Anas Khan <[email protected]>
Co-authored-by: bartek-gralewicz <[email protected]>
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.

1 participant