localhost_bridge 0.1.1
localhost_bridge: ^0.1.1 copied to clipboard
A localhost bridge that lets web pages deliver origin-trusted commands to a local Dart app — CORS-ready, hardened origin policies, first-use consent, token layer, strict limits.
0.1.1 #
429replies that carryRetry-After(origin_rate_limited,token_locked) now echo the CORS headers of admitted origins, so the retrying page can read its rejection code and the honest wait instead of an opaque network error.start()rejects a double start through its returned future (the sameStateErroron every path), so.catchError,then(onError:), andawaitinsidetry/catchall observe the rejection identically.update()validates the origin policy numbers up front: a non-positiveperOriginPerMinuteoraskTimeoutthrowsArgumentErrorbefore anything is applied, so a failed update keeps the previous protection state intact.- Rejection logs sanitize the logged
Originvalue: control characters are stripped and the value is capped, so a hostile header cannot forge log lines or bloat every throttled line. 413now reaches the client on Linux and macOS: after the early rejection the reply is written to the raw socket and the unread remainder of the body is drained within bounded patience (about two seconds or four bodies, whichever comes first) before the connection closes, instead of closing over unread data - which those kernels answer with a reset that discarded the reply. A sender past the bounds keeps the immediate cut. The busy503reply stays an immediate cut on purpose: a saturated server spends no drain windows, so a dropped busy reply reads to the page as the retryable network error it already looks like.- The 413 limit label reads
1 MiB. - Documentation honesty: lib docs describe a host logger, plain
commands, and a local Dart app (no original-product vocabulary), test
headers reference no repository tooling, two protection comments match
the code and
SECURITY.md, and the README dependency claims are exact. - Documentation surface: browser support and host platform tables
(reviewed 2026-11) — Safari and every iOS browser are unsupported
(mixed content blocks
http://127.0.0.1fromhttpspages), Android reaches the bridge behind the Local Network Access prompt with the token layer as the practical requirement against forged local origins; a page-side JavaScript reference showstargetAddressSpace: 'loopback', theorigin_pendingretry honoring the seconds-basedRetry-After, 504 treated as an unknown outcome reconciled onX-Correlation-Id, a boundednavigator.permissions.query({name: 'loopback-network'}), andallow="loopback-network"(plusallow-same-originundersandbox) for iframes; a 504 unknown-outcome callout opens the wire contract; the Arabic guide is now an explicit Arabic summary instead of claiming a full mirror; the allowlist contract states bare hosts match the host name on any port, the fourteen wire cases are one test replaying a corpus across three protection modes, and "trusted" commands mean admitted by the origin decision, never a validated payload; andArrivalGuardis documented as a standalone host-side tool the server never calls, with its keep-or-remove decision deferred to a later release. - Reporting:
SECURITY.mdnow reflects reality — the package is published on pub.dev, the public repository is the single source of truth, and its private vulnerability reporting channel is the way to reach the maintainer. - Packaging: the placeholder
homepageis removed frompubspec.yamlso pub.dev shows the repository link, and the READMEs open with CI and pub.dev badges. - Packaging: CI workflow files are excluded from the published archive
via
.pubignore, so the pub.dev archive lists package files only.
0.1.0 #
- Initial release. A localhost HTTP intake server on
127.0.0.1that lets admitted web pages deliver origin-trusted, payload-untrusted commands to a local Dart app. - CORS echo for admitted origins only (
Vary: Origin, never*), DNS rebinding defense (Host must textually match the bound port's authorities), and duplicate-header rejection. - Unified origin policy: closed by default; an allowlist of exact origins,
bare hosts, and
*.domainpatterns; hardened allow-all (valid HTTPS origin + fetch-mode checks + per-origin rate limit); first-use consent through a host callback (allowAlways,allowOnce,reject,dismissed); an independent token layer for non-browser integrations; and a watch mode (reportOnly) that observes both per-origin quotas without rejecting. - Resource limits: 1 MiB body cap, JSON structural-element cap (default
10,000) and nesting-depth cap (default 32) counted in one pre-decode
pass, concurrency seats with
503(seats plus timed-out handlers are one live-work budget), per-request and idle timeouts, optionalhandlerTimeoutfreeing a seat with504(the command may still have run — deduplicate onX-Correlation-Idbefore retrying). - Content types: POST bodies must carry
application/jsonortext/plain(BridgeConfig.allowedContentTypes); hidden-HTML-form types are refused with415 unsupported_media_type. The browser-facing form defense is the fetch-mode hardening (Sec-Fetch-Mode: cors,Sec-Fetch-Dest: empty) — the content-type gate raises the floor for non-browser clients, andOriginPolicy.requireFetchMetadata(on by default) extends the shape checks to headerless requests from legacy browsers. - Configuration honesty:
update()changes only what you pass — updating the policy keeps the token, updating the token keeps the policy. Remembered consent answers are cleared only when the origin policy actually changes. A rejected token never appears in error messages. Stable error codes throughout;SECURITY.mddocuments the threat model, the residuals, and how to report a vulnerability.