HTTP hardening (from Incus)#17950
Merged
tomponline merged 7 commits intocanonical:mainfrom Mar 25, 2026
Merged
Conversation
We've apparently always turned off this particular safety check but can't find a good reason for that as all complex Websocket operations are done outside of the browser. For browser-based interactions, the default behavior of enforcing an Origin match seems quite appropriate. Reported-by: https://7asecurity.com Signed-off-by: Stéphane Graber <[email protected]> (cherry picked from commit a86e741255916fdfb16ca1c770db6d77364495fb) Signed-off-by: Simon Deziel <[email protected]> License: Apache-2.0
This configures some timeouts on the HTTP server to prevent clients from keeping connections open longer than they should. We can generally have reasonable timeouts on receiving headers and receiving the client's request. We however can't easily put timeouts in place in the other direction as we have to support long-poll style endpoints in this API. Reported-by: https://7asecurity.com Signed-off-by: Stéphane Graber <[email protected]> (cherry picked from commit 318fa0eb966c83e3b8ccc97afca4c43c1176174f) Signed-off-by: Simon Deziel <[email protected]> License: Apache-2.0
This configures some timeouts on the HTTP server to prevent clients from keeping connections open longer than they should. Depending on the endpoints, we can either just timeout on the receiving side (headers, request body) or also on the sending direction (client reading the response). Endpoints that need to support long-poll style APIs or need to handle potentially very large requests (file uploads, connection upgrades, ...) only get to benefit from the header timeout logic. Reported-by: https://7asecurity.com Signed-off-by: Stéphane Graber <[email protected]> (cherry picked from commit bb885a06187f2e63a34fdd48b90d693610eafc2b) Signed-off-by: Simon Deziel <[email protected]> License: Apache-2.0
There was a problem hiding this comment.
Pull request overview
This PR ports HTTP hardening changes from Incus into LXD, focusing on tightening defaults for WebSocket origin handling and adding safer HTTP client/server timeouts and headers.
Changes:
- Switch WebSocket upgrading to use the default Origin checks (instead of allowing all origins).
- Add/standardize HTTP server timeouts across several internal endpoints (REST, metrics, devlxd, vsock, agent, pprof).
- Add
Referrer-Policy: no-referrerto UI and documentation handlers, and add a TLS handshake timeout for the Loki client.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| shared/ws/upgrader.go | Removes permissive WebSocket Origin bypass to rely on default Origin enforcement. |
| lxd/loki/loki.go | Adds TLSHandshakeTimeout to the Loki HTTP transport for safer outbound TLS behavior. |
| lxd/endpoints/pprof.go | Adds server timeouts to the pprof HTTP server. |
| lxd/api_vsock.go | Adds HTTP server timeouts for the vsock /dev/lxd server. |
| lxd/api_devlxd.go | Adds HTTP server timeouts for the container /dev/lxd server. |
| lxd/api.go | Adds Referrer-Policy to UI/docs handlers and adds timeouts to REST/metrics servers. |
| lxd-agent/server.go | Adds HTTP server timeouts to the agent REST server. |
| lxd-agent/devlxd.go | Adds HTTP server timeouts to the VM /dev/lxd agent server. |
Signed-off-by: Simon Deziel <[email protected]>
Signed-off-by: Simon Deziel <[email protected]>
Signed-off-by: Simon Deziel <[email protected]>
From https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-XSS-Protection: > Deprecated: This feature is no longer recommended. None of the relevant browsers support it: * Chrome dropped it in 2019 with Chrome 78 * Edge dropped it in July 2018 * Safari in 2022 * Firefox never implemented it https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-XSS-Protection#browser_compatibility Ideally, this would be replaced by a `Content-Security-Policy` but I'll leave that to someone else. Signed-off-by: Simon Deziel <[email protected]>
e1e5aa3 to
7f2daf2
Compare
tomponline
reviewed
Mar 24, 2026
simondeziel
commented
Mar 25, 2026
| // vSockServer creates an http.Server capable of handling /dev/lxd requests over vsock. | ||
| func vSockServer(d *Daemon) *http.Server { | ||
| return &http.Server{ | ||
| Handler: devLXDAPI(d, vSockAuthenticator{}), |
Member
Author
There was a problem hiding this comment.
This seem to have caused a regression for pylxd that sends a bogus/weird Origin header
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.
From lxc/incus#3067 with some additional improvements in the same vein.