fix: mitigate WebSocket CSRF and restrict sensitive file permissions#4
Open
giwaov wants to merge 1 commit into
Open
fix: mitigate WebSocket CSRF and restrict sensitive file permissions#4giwaov wants to merge 1 commit into
giwaov wants to merge 1 commit into
Conversation
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)
fdadfbb to
f9af045
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CheckOrigin: return truewith origin validation that allows localhost, local network (192.168.x, 10.x, 172.x), and rejects untrusted external origins. Logs rejected attempts.0644to owner-only0600for files containing passwords (RTK config, wpa_supplicant, hostapd, LTE config, LTE env).Why
WebSocket CSRF (Cross-Site WebSocket Hijacking)
The current
CheckOriginfunction unconditionally returnstrue, 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 to0600(owner-only read/write).Files changed
webserver.go— WebSocket origin validation with allow-listrtk_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