Decide on a WebSocket Origin check once a week of Origin logs exists (after 2026-09-29) #25

Closed
opened 2026-09-22 12:16:37 +00:00 by grenade · 3 comments
Owner

Why

/v1/ws accepts an upgrade from any origin. Verified 2026-09-22: a handshake carrying Origin: https://evil.example got 101 Switching Protocols. CORS does not apply to WebSockets, and crates/blackbeard-api/src/ws.rs never reads Origin. So any third-party page could embed the live feed from its visitors' browsers, and the REST allowlist (allowed_origins) does nothing about it.

Before #24 we could not tell whether that happens. Browsers send no Referer on the upgrade handshake, so all 7,551 /v1/ws requests between 2026-09-12 and 2026-09-22 had none, and ours looked the same as anyone else's. Since #24 (6d8c3fe, live 2026-09-22 12:04 UTC) the public vhost logs origin as JSON to /var/log/nginx/blackbeard.observer.access.log on oolon.

To do, after 2026-09-29

Break the WebSocket upgrades down by origin:

ssh oolon.kosherinata.internal 'sudo cat /var/log/nginx/blackbeard.observer.access.log*' \
  | jq -r 'select(.uri | startswith("/v1/ws")) | select(.denied==0) | .origin' \
  | sort | uniq -c | sort -rn

The rotated files are gzipped (delaycompress, daily), so use zcat -f over access.log-* for anything older than a day.

Expected:

  • https://blackbeard.observer: our UI.
  • empty: non-browser clients (scripts, bots, wallet backends). An Origin check would not affect them, because a non-browser client can send any Origin it likes.
  • http://localhost:*: dev servers.

Anything else is a third-party page opening our socket from its visitors' browsers.

The decision

  • Only our origin, plus empty or localhost: nothing is embedding us. An Origin check is cheap hardening but not urgent. Decide whether to add it anyway and record why.
  • Other origins present: identify them before blocking. A wallet or explorer we would want to support is a case for adding it to allowed_origins, not for refusing it. Then enforce Origin in the WS handler: reject a present Origin not in allowed_origins, and allow an absent one (non-browser clients). Do it in axum rather than nginx, so the allowlist stays in one place.

Record the numbers here either way. The outcome is a documented decision, not necessarily a code change.

Also note any "denied":1 lines with browser User-Agents. That is #24's deny list catching VPN users, and a reason to revisit it.

Related: #24.

## Why `/v1/ws` accepts an upgrade from any origin. Verified 2026-09-22: a handshake carrying `Origin: https://evil.example` got `101 Switching Protocols`. CORS does not apply to WebSockets, and `crates/blackbeard-api/src/ws.rs` never reads `Origin`. So any third-party page could embed the live feed from its visitors' browsers, and the REST allowlist (`allowed_origins`) does nothing about it. Before #24 we could not tell whether that happens. Browsers send no Referer on the upgrade handshake, so all 7,551 `/v1/ws` requests between 2026-09-12 and 2026-09-22 had none, and ours looked the same as anyone else's. Since #24 (`6d8c3fe`, live 2026-09-22 12:04 UTC) the public vhost logs `origin` as JSON to `/var/log/nginx/blackbeard.observer.access.log` on oolon. ## To do, after 2026-09-29 Break the WebSocket upgrades down by origin: ```sh ssh oolon.kosherinata.internal 'sudo cat /var/log/nginx/blackbeard.observer.access.log*' \ | jq -r 'select(.uri | startswith("/v1/ws")) | select(.denied==0) | .origin' \ | sort | uniq -c | sort -rn ``` The rotated files are gzipped (`delaycompress`, daily), so use `zcat -f` over `access.log-*` for anything older than a day. Expected: - `https://blackbeard.observer`: our UI. - empty: non-browser clients (scripts, bots, wallet backends). An Origin check would not affect them, because a non-browser client can send any Origin it likes. - `http://localhost:*`: dev servers. Anything else is a third-party page opening our socket from its visitors' browsers. ## The decision - **Only our origin, plus empty or localhost:** nothing is embedding us. An Origin check is cheap hardening but not urgent. Decide whether to add it anyway and record why. - **Other origins present:** identify them before blocking. A wallet or explorer we would want to support is a case for adding it to `allowed_origins`, not for refusing it. Then enforce Origin in the WS handler: reject a *present* Origin not in `allowed_origins`, and allow an absent one (non-browser clients). Do it in axum rather than nginx, so the allowlist stays in one place. Record the numbers here either way. The outcome is a documented decision, not necessarily a code change. Also note any `"denied":1` lines with browser User-Agents. That is #24's deny list catching VPN users, and a reason to revisit it. Related: #24.
Author
Owner

Scheduled: a systemd user timer on grenade's workstation (bb-origin-report.timer, 2026-09-29 09:00 Europe/Sofia, Persistent=true) runs ~/.local/bin/bb-origin-report. The script reads the #24 JSON log over ssh and posts the numbers here as a comment: WebSocket upgrades by Origin, REST by Origin, and denials with browser User-Agents. It posts numbers only. The decision stays with a human.

It is not a cloud routine because a cloud agent can reach neither oolon nor this Gitea.

Scheduled: a systemd user timer on grenade's workstation (`bb-origin-report.timer`, 2026-09-29 09:00 Europe/Sofia, `Persistent=true`) runs `~/.local/bin/bb-origin-report`. The script reads the #24 JSON log over ssh and posts the numbers here as a comment: WebSocket upgrades by Origin, REST by Origin, and denials with browser User-Agents. It posts numbers only. The decision stays with a human. It is not a cloud routine because a cloud agent can reach neither oolon nor this Gitea.
Author
Owner

Automated report for this issue, from /var/log/nginx/blackbeard.observer.access.log* on oolon (the #24 JSON log). It gives the numbers only. The decision is still open.

Span: 2026-09-22T12:03:25+00:00 → 2026-09-29T06:00:43+00:00, 23557 requests

/v1/ws upgrades by Origin (not denied)

origin upgrades 101 distinct IPs
https://blackbeard.observer 1843 1594 92
(none) 1 1 1

Read against the issue: https://blackbeard.observer is our UI, (none) is non-browser clients that an Origin check would not affect, and localhost is dev. Anything else is a third-party page.

REST /v1/* by Origin, for comparison

origin requests
(none) 10418
https://blackbeard.observer 5

Deny list (#24)

8452 denied requests, 4 with a browser User-Agent.

ip requests first UA
37.187.143.115 8333 ``
135.181.130.74 115 stardust-devops
167.233.143.69 1 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, l
5.135.137.201 1 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, l
51.178.179.51 1 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, l
95.217.114.145 1 Mozilla/5.0 (compatible; SERankingBacklinksBot/1.0; +https://seranking

Browser User-Agents among the denials would be VPN users caught by the Hetzner/OVH list.

Posted by ~/.local/bin/bb-origin-report via a systemd user timer.

Automated report for this issue, from `/var/log/nginx/blackbeard.observer.access.log*` on oolon (the #24 JSON log). It gives the numbers only. The decision is still open. **Span:** 2026-09-22T12:03:25+00:00 → 2026-09-29T06:00:43+00:00, 23557 requests ### `/v1/ws` upgrades by Origin (not denied) | origin | upgrades | 101 | distinct IPs | |---|---|---|---| | `https://blackbeard.observer` | 1843 | 1594 | 92 | | `(none)` | 1 | 1 | 1 | Read against the issue: `https://blackbeard.observer` is our UI, `(none)` is non-browser clients that an Origin check would not affect, and `localhost` is dev. Anything else is a third-party page. ### REST `/v1/*` by Origin, for comparison | origin | requests | |---|---| | `(none)` | 10418 | | `https://blackbeard.observer` | 5 | ### Deny list (#24) 8452 denied requests, 4 with a browser User-Agent. | ip | requests | first UA | |---|---|---| | `37.187.143.115` | 8333 | `` | | `135.181.130.74` | 115 | `stardust-devops` | | `167.233.143.69` | 1 | `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, l` | | `5.135.137.201` | 1 | `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, l` | | `51.178.179.51` | 1 | `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, l` | | `95.217.114.145` | 1 | `Mozilla/5.0 (compatible; SERankingBacklinksBot/1.0; +https://seranking` | Browser User-Agents among the denials would be VPN users caught by the Hetzner/OVH list. _Posted by `~/.local/bin/bb-origin-report` via a systemd user timer._
Author
Owner

Decision, 2026-10-07: closing without an Origin check.

From the 2026-09-29 report, covering a week of the #24 log: 1,843 WebSocket upgrades from https://blackbeard.observer (92 IPs) and one with no Origin. No third-party page opened the socket.

An Origin check would therefore stop nothing that happens today. A non-browser client can send any Origin it likes, so the check would only ever affect embedding by another site's visitors, and nobody is doing that. Not adding it keeps one less thing to keep in step with the domains the site serves on.

Reopen if a foreign origin shows up on /v1/ws upgrades. The jq query in the issue body still finds them.

**Decision, 2026-10-07: closing without an Origin check.** From the 2026-09-29 report, covering a week of the #24 log: 1,843 WebSocket upgrades from `https://blackbeard.observer` (92 IPs) and one with no Origin. **No third-party page opened the socket.** An Origin check would therefore stop nothing that happens today. A non-browser client can send any Origin it likes, so the check would only ever affect embedding by another site's visitors, and nobody is doing that. Not adding it keeps one less thing to keep in step with the domains the site serves on. Reopen if a foreign origin shows up on `/v1/ws` upgrades. The `jq` query in the issue body still finds them.
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: blackbeard/observer#25