Skip to content

fix: mitigate WebSocket CSRF and restrict sensitive file permissions#4

Open
giwaov wants to merge 1 commit into
jleppert:mainfrom
giwaov:fix/websocket-csrf-and-file-permissions
Open

fix: mitigate WebSocket CSRF and restrict sensitive file permissions#4
giwaov wants to merge 1 commit into
jleppert:mainfrom
giwaov:fix/websocket-csrf-and-file-permissions

Conversation

@giwaov
Copy link
Copy Markdown

@giwaov giwaov commented Feb 26, 2026

Summary

  • WebSocket CSRF fix: Replace permissive CheckOrigin: return true with origin validation that allows localhost, local network (192.168.x, 10.x, 172.x), and rejects untrusted external origins. Logs rejected attempts.
  • File permission hardening: Change credentials/config file permissions from world-readable 0644 to owner-only 0600 for files containing passwords (RTK config, wpa_supplicant, hostapd, LTE config, LTE env).

Why

WebSocket CSRF (Cross-Site WebSocket Hijacking)

The current CheckOrigin function unconditionally returns true, allowing any website to open a WebSocket connection to the rover. A malicious webpage could send motor commands, read GPS/telemetry data, or modify network credentials — all without user interaction beyond visiting the page.

File Permissions

Sensitive configuration files containing plaintext NTRIP passwords, WiFi PSK, AP passphrase, and LTE APN credentials were written with 0644 (world-readable). Any user or process on the system could read these credentials. Changed to 0600 (owner-only read/write).

Files changed

  • webserver.go — WebSocket origin validation with allow-list
  • rtk_config.go — RTK config file permissions (0644 → 0600)
  • wifimanager.go — wpa_supplicant config permissions (0644 → 0600)
  • apconfig.go — hostapd config permissions (0644 → 0600)
  • ltemodem.go — LTE config and env file permissions (0644 → 0600)

Test plan

  • Verify WebSocket connections from localhost/dashboard still work
  • Verify WebSocket connections from external origins are rejected
  • Verify config files are created with 0600 permissions
  • Verify rover control via dashboard is unaffected

Security fixes:

1. WebSocket CSRF (Cross-Site WebSocket Hijacking):
   - Replace permissive `CheckOrigin: return true` with origin validation
   - Allow localhost and local network origins (192.168.x, 10.x, 172.x)
   - Reject connections from untrusted external origins
   - Log rejected connection attempts for monitoring
   - Without this fix, any malicious website could open a WebSocket to
     the rover and send motor commands without user interaction

2. Sensitive file permissions (0644 -> 0600):
   - rtk_config.json: contains NTRIP username/password in plaintext
   - wpa_supplicant.conf: contains WiFi PSK passwords
   - hostapd.conf: contains AP passphrase
   - lte_config.json: contains LTE APN credentials
   - lte.env: contains LTE connection arguments with credentials
   - Previously world-readable (0644), now owner-only (0600)
@giwaov giwaov force-pushed the fix/websocket-csrf-and-file-permissions branch from fdadfbb to f9af045 Compare February 26, 2026 12:24
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