github dunglas/mercure v1.1.7

2 hours ago

Community

Mercure 1.1.7 is a security release: it fixes 13 vulnerabilities, 5 of them rated high, found by Anthropic's OSS Scanner. All users should upgrade. Most of them let a client with a valid subscriber token, or no token at all, exhaust the hub's CPU, memory, disk or connections; others let a client publish or receive updates its token no longer allows. The release also coalesces writes to subscribers, making Bolt history replays 2.2x faster with a third of the CPU time, replaces gorilla/mux with Go's standard router, and updates dependencies, including Caddy 2.11.9.

🔒 Security Fixes

High:

  • URL Patterns: crafted URL Patterns could stall publishing for seconds or pin hundreds of MB of hub memory. Regexp groups whose cost can grow faster than their length are now refused, and the URL Patterns of a subscribe request, or granted by a token, may total 8 KiB. caddy mercure-token refuses patterns the hub would refuse. See the upgrade guide. (GHSA-67jq-5q8f-jmgr)
  • Subscription events: any subscriber could burn hub CPU and fill the disk with subscription events. When subscription events are on, the matchers of a subscribe request may total 16 KiB, and private updates are checked against the token's grants before the client-chosen matchers. The Bolt transport now keeps the last 10,000 updates when size is unset, instead of growing the file forever. (GHSA-p2f7-8293-4xm5)
  • Subscription API: unread responses each held a client-sized copy of the collection and could make the hub run out of memory. Responses are now streamed, and clients that stop reading are dropped after dispatch_timeout. (GHSA-65rj-8f2v-m5g4)
  • Subscribe: HEAD requests and subscribe requests carrying a body held connections and permits, stalling proxied requests. The hub now reads and discards the content of GET and HEAD requests before authorizing them, counting it against max_request_body_size, and answers HEAD without opening a subscription. (GHSA-qcrf-69wp-qjjr)
  • Topic matcher cache: cached matchers kept whole subscribe requests alive after the subscriber disconnected. Matcher strings are now copied before caching. (GHSA-hghw-8gfj-4rp7)

Medium:

  • History replay: replay tested every stored update against every URL Pattern of a subscription, costing seconds of CPU per request. A replay now runs at most 100,000 URL Pattern and URI Template tests: a subscription with 100 URL Patterns replays at most 1,000 updates. (GHSA-2xqh-6298-gj5c)
  • URL Patterns: topics with long URL authorities cost about 9 ms per URL Pattern evaluation, stalling publishing. Fixed by updating go-urlpattern to 1.2.0 and whatwg-url to 0.9.1. (GHSA-5j9m-v57p-f6vh)
  • Token expiration: a client delaying its request body could publish or receive updates after its token expired. The hub now checks exp after reading the body. (GHSA-cw7q-6w8c-mjg4)
  • Logs: unauthenticated requests made the hub write log lines 230 times larger than ordinary refusals. Authorization and matcher errors are now bounded in logs. (GHSA-cqv7-w268-p9c3)
  • Event IDs: a scoped publisher could choose event IDs that made other subscribers miss updates on reconnect. The hub now rejects with a 400 publisher-supplied IDs containing characters other than printable ASCII, or starting or ending with a space. (GHSA-3x23-68w2-896q)
  • Compatibility mode: dot segments in topics bypassed publish grants and selectors. URI Template matches on dot segments are now refused. (GHSA-2ppf-g46w-9jj9)
  • Audience: a malformed request host moved the expected token audience to another host. The hub now derives its identity only from a well-formed host. (GHSA-r82r-f2cw-mv9r)

Low:

  • HTTP/3: failed writes to subscribers were ignored unless debug logging was on, allowing event forgery over HTTP/3. The subscription now ends on every failed write. (GHSA-p333-8q9m-78p5)

Some of these fixes change defaults or reject inputs that were accepted before. Read the 1.1.7 upgrade notes before upgrading.

✨ New Features

  • The hub now logs a warning at startup when publish_origins lists null: browsers send Origin: null for sandboxed iframes, data: URLs and local files, so this lets any site publish with a user's cookie. It stays allowed for file:// apps such as Cordova and Electron. by @dunglas in #1498

⚡ Performance Improvements

  • Subscribers: the hub now writes every update already queued for a subscriber, then flushes once, instead of paying one write syscall per update and subscriber. Each update keeps its own dispatch_timeout, and a batch never writes past the token's exp. by @dunglas in #1500

1.1.6 and 1.1.7 compared on Linux (Docker, arm64), release build tags, hub pinned to 5 CPUs and the load generator to 5 others, medians of 3 runs, no lost delivery:

Scenario 1.1.6 1.1.7
Bolt history replay, 900 updates to 1,000 subscribers: duration 0.71 s 0.32 s (2.2x faster)
Bolt history replay: hub CPU time 3 s 1 s
Bolt history replay: delivery p99 712 ms 334 ms
URL Pattern broadcast, 200,000 deliveries/s: delivery p50 2.6 ms 1.9 ms
URL Pattern broadcast: delivery p99.9 17.5 ms 15.8 ms
URL Pattern broadcast: memory per subscriber 72 KB 63 KB
Exact-topic fan-out, 1,000 subscribers, maximum rate 383,000 deliveries/s 397,000 deliveries/s
10,000 idle subscribers: memory per subscriber 47 KB 46 KB

The security fixes add no measurable cost: exact-topic, private and Bolt fan-out at 2,000 updates/s use the same CPU time with the same or lower latency. Replays use more memory while batching: 153 MB peak instead of 145 MB.

🐛 Bug Fixes

  • Caddy: with playground on, the module no longer redirects / to the debugger, which replaced the home page of applications sharing the site block, such as FrankenPHP's php_server. The debugger stays at /.well-known/mercure/debug/. by @dunglas in #1487
  • Caddy: a dev hub (playground) now exits in about a second, as drain_timeout defaults to 1s. Without a drain, the hub logs that open connections close at their write deadline and how to stop sooner. by @dunglas in #1473
  • Errors for malformed origins such as NULL now quote the origin instead of ending in %!w(<nil>). by @dunglas in #1499

🔧 Internal Improvements

  • Replace the unmaintained gorilla/mux router with Go's http.ServeMux, and unrolled/secure with a small wrapper. The CSP gains frame-ancestors 'none', base-uri 'none' and form-action 'self', and responses carry Cross-Origin-Opener-Policy: same-origin. Unclean paths now get a 307 redirect, HEAD on the subscription API returns 200, and X-XSS-Protection is no longer sent. Code mounting SubscriptionsHandler or SubscriptionHandler on another router must set the path values. by @dunglas in #1489

📦 Dependencies

Enterprise

Mercure Enterprise 1.1.7 ships every security fix and performance improvement above. On Mercure Cloud and with the provided rate-limit.Caddyfile, subscriptions sent with the QUERY method are now counted by the subscribe rate limit and the plan's concurrency limit, as GET subscriptions already were. Release archives are published to the S3 mirror again. Dependencies are updated, including Caddy 2.11.9.

Mercure Cloud hubs are upgraded automatically: use Mercure Cloud to get security fixes like these without managing upgrades yourself.

Enterprise releases ship under the Enterprise SLA, with prioritized security patches and direct support. Contact contact@mercure.rocks for the managed Cloud offering, on-premise licenses, custom development, consulting, and training.

Full Changelog: v1.1.6...v1.1.7

Don't miss a new mercure release

NewReleases is sending notifications on new releases.