Skip to content

HTTP hardening (from Incus)#17950

Merged
tomponline merged 7 commits intocanonical:mainfrom
simondeziel:hardening-from-incus
Mar 25, 2026
Merged

HTTP hardening (from Incus)#17950
tomponline merged 7 commits intocanonical:mainfrom
simondeziel:hardening-from-incus

Conversation

@simondeziel
Copy link
Copy Markdown
Member

From lxc/incus#3067 with some additional improvements in the same vein.

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
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-referrer to 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.

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]>
@simondeziel simondeziel force-pushed the hardening-from-incus branch from e1e5aa3 to 7f2daf2 Compare March 23, 2026 21:39
@simondeziel simondeziel requested a review from tomponline March 24, 2026 00:13
@simondeziel simondeziel marked this pull request as ready for review March 24, 2026 00:13
Copy link
Copy Markdown
Member

@tomponline tomponline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ta

@tomponline tomponline merged commit e27c9ee into canonical:main Mar 25, 2026
66 checks passed
@simondeziel simondeziel deleted the hardening-from-incus branch March 25, 2026 12:38
// 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{}),
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seem to have caused a regression for pylxd that sends a bogus/weird Origin header

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.

5 participants