Skip to content

Harden security: hidden token, web-page origins refused, private-network firewall - #3

Closed
rokogan wants to merge 0 commit into
masterfrom
security-hardening
Closed

rokogan wants to merge 0 commit into
masterfrom
security-hardening

Conversation

@rokogan

@rokogan rokogan commented Nov 26, 2026

Copy link
Copy Markdown

Security hardening from the project review.

Device token

  • GET /api/config no longer returns the token; it reports hasToken instead. Saving the config keeps the saved token unless the request sets one. An empty one turns token auth off. The web UI and the installer never need to see it.
  • New POST /api/token generates a 128-bit token from the system's cryptographic generator and applies it at once.
  • As the service, tv-config.json is readable only by SYSTEM and administrators. The restriction is applied on every save (before the file is renamed into place) and at start, so installs from earlier versions are fixed too.
  • The web UI shows whether a token is set and offers Generate new token, followed by Reinstall TV App. While any device on the LAN can drive the PC, a red No device token chip is shown.
  • install.ps1 generates a token only when the service has none. Previously it replaced the token on every run, which would lock out other TVs.

WebSocket

  • Upgrades whose Origin is http or https are refused, so a web page can no longer drive the PC in open mode, in a browser on the LAN or on this PC. The TV app is a local file:// app and sends null, file:// or no Origin. Only web origins are refused, not unknown ones, so an unexpected value from the TV can't lock it out.
  • Refused connections are logged at most once a minute per address, with a count of those held back, so a LAN host can't flood the event log. The refused origin is logged, trimmed to printable text.

Firewall

  • The TV rule allows TCP to the exe on whatever port it uses, so changing the port no longer leaves the TV blocked.
  • Both rules apply only on private and domain networks. install says so, and install.ps1 warns about any network Windows treats as Public.

Testing

  • cargo fmt --check, cargo clippy --all-targets -- -D warnings and cargo test pass: 54 unit tests and 8 integration tests. New tests cover:
    • the token staying hidden through the API and being kept on save;
    • token generation;
    • file permissions: the restricted file is unreadable to its own non-admin creator;
    • origin parsing, plus refusal end to end (https/http refused; file:// and null accepted);
    • the refusal-log rate limit.
  • The release exe was run standalone on a spare port with a test config:
    • GET /api/config hides the token;
    • the web UI shows "Device token on", then "Device token off" plus the red chip after the token was cleared;
    • POST /api/token wrote a new 32-hex token and kept the rest of the config.
  • install.ps1 parses in Windows PowerShell 5.1.

Not tested here:

  • Firewall: the new netsh rule syntax, and the file permissions applied when running as SYSTEM. Both need an elevated install.
  • TV origin: what the TV sends as its Origin. If the TV were ever refused, Recent Events names the origin it used.

@rokogan rokogan closed this Nov 26, 2026
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