bloom_security 0.2.3
bloom_security: ^0.2.3 copied to clipboard
Production-ready CORS, security headers, rate limiting, and WebSocket upgrade utilities for Bloom servers.
0.2.3 - 2026-09-04 #
Security #
- WS Host-header fallback gated behind opt-in (#27): the same-origin check's reverse-proxy fallback (comparing
Originto the client-suppliedHostheader) is now off by default (allowProxyHostFallback: false); enable only when a trusted proxy restores the original Host. - Shared anonymous bucket warning (#24): the default key extractor prints a loud one-time warning when all anonymous clients share the
anonymous_peerbucket; middleware/library/README docs now showpeerAddressExtractorwiring from the server adapter.
Fixed #
- WS subprotocol negotiation (#27):
BloomWebSocketServernow accepts aprotocolslist. When a client offers subprotocols and none match, the handshake is rejected with 400 instead of upgrading — dart:io cannot omit theSec-WebSocket-Protocolheader once the client offers protocols, so echoing nothing requires declining the upgrade. - WS route patterns escape literal segments (#27): static characters in registered path patterns (e.g.
.) are regex-escaped so/ws/v1.2/endpointno longer matches/ws/v1x2/endpoint. - WS idle keepalive (#27): new configurable
pingIntervalsetsWebSocket.pingIntervalon upgraded sockets so half-open connections are detected and closed instead of pinningmaxConnectionscapacity. Validated to be positive when provided. - Dual-case header writes (#27): the CORS, rate-limit, and security-headers middlewares now write each header in a single canonical case instead of both
X-...andx-...variants.
Documentation #
- Security docs lead with
.strict()(#27): the package-level example now starts from the strict CORS policy instead of.permissive().
Fixed #
- Window-aware stale-bucket prune (#25):
BloomInMemoryRateLimitStoreretains entries for the longest enforced window (min 60s) instead of a hardcoded 10-minute cutoff, so hour-long windows stay enforced. Added adebugPrunetesting hook; failed middleware construction now disposes its owned store instead of leaking a timer. - Suite migrated to
package:test(#26): removed the hand-rolled runner (test_helpers/all_tests);dart testnow discovers the full suite (30 tests) and exits 0.
0.2.2 - 2026-08-31 #
Security Hardening #
- CORS (
BloomAdvancedCorsMiddleware):- Implemented deny-by-default policy (
allowedOriginsdefaults toconst []). - Prohibited wildcard origin (
'*') withallowCredentials = trueat construction time. - Rejection of disallowed cross-origin requests and invalid preflight requests with HTTP 403 Forbidden without emitting allow-origin headers.
- Strict preflight validation for requested methods and case-insensitive headers.
- Permissive factory explicitly sets
allowCredentials = falsewithout arbitrary origin reflection.
- Implemented deny-by-default policy (
- Rate Limiting (
BloomRateLimitMiddleware&BloomRateLimitStore):- Added
BloomTrustedProxyPredicate(isTrustedProxy) ensuring proxy headers (CF-Connecting-IP,X-Forwarded-For,X-Real-IP,True-Client-IP) are never trusted unless the immediate peer is approved. - Added safe non-spoofable fallback key (
anonymous_peer) when peer address is unavailable. - Added argument validation for
maxRequests > 0,window > Duration.zero, andcleanupInterval > Duration.zero. - Introduced public
BloomRateLimitStorecontract andBloomInMemoryRateLimitStorefor pluggable shared/distributed storage backends.
- Added
- WebSocket Security (
BloomWebSocketServer&BloomWebSocketUpgrade):- Added configurable origin validation with deny-by-default rejection of cross-origin browser handshakes.
- Added pre-upgrade
BloomWebSocketAdmissionHookfor authorization and connection filtering. - Added active connection cap (
maxConnections) rejecting over-capacity requests with HTTP 503 Service Unavailable. - Added inbound message payload size limit (
maxMessageBytes) closing over-limit peers with status 1009 (WebSocketStatus.messageTooBig).
- Automated Tests:
- Added 27 automated security tests covering CORS denial, preflight headers, spoofed proxy header defense, trusted proxy predicates, WebSocket origin checks, admission hooks, connection caps, and frame size limits.
0.2.1 - 2026-08-25 #
Fixed #
- Bumped
bloom_serverdependency constraint from^0.1.0to^0.2.0— the stale constraint was incompatible with any sibling package (bloom_cache,bloom_i18n) requiringbloom_server ^0.2.0, breakingpub getin any app combining them.
0.2.0 - 2026-08-23 #
Breaking #
- Now depends on
bloom_serverinstead ofbloom_framework. Imports change frompackage:bloom_framework/bloom_server.darttopackage:bloom_server/bloom_server.dart. - No longer requires Flutter. The package now resolves against the Flutter-free
bloom_servercore, so it can be used from a plaindart run/dart compilebackend.
0.1.0 #
- Initial release of
bloom_security. - Added
BloomCorsMiddleware: configurable CORS handling with wildcard/origin lists, credential support, headers, and OPTIONS preflight short-circuiting. - Added
BloomSecurityHeadersMiddleware: standard HTTP security headers (HSTS on HTTPS, CSP, X-Frame-Options, X-Content-Type-Options, Referrer-Policy, and Permissions-Policy). - Added
BloomRateLimitMiddleware: sliding-window rate limiter with per-IP or custom key extraction, 429 Retry-After handling, rate limit headers, and atomic concurrency safety in Dart isolate. - Added
BloomWebSocketUpgradeandBloomWebSocketServer: native WebSocket upgrade routing and server binding integrated withBloomApiRouter.