From 1d1104e70ee9d7ca14e8164bc4d32e29fc44f77e Mon Sep 17 00:00:00 2001 From: Michael Myers Date: Wed, 13 Nov 2024 10:44:06 -0600 Subject: [PATCH] [v16] Add wasm to content security policy for web ssh terminal --- lib/httplib/httpheaders.go | 6 +++++- lib/httplib/httplib_test.go | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/httplib/httpheaders.go b/lib/httplib/httpheaders.go index 2c1d500980c3c..f3c8eb426abcf 100644 --- a/lib/httplib/httpheaders.go +++ b/lib/httplib/httpheaders.go @@ -198,6 +198,10 @@ var desktopSessionRe = regexp.MustCompile(`^/web/cluster/[^/]+/desktops/[^/]+/[^ // which is a route to a desktop recording that uses WASM. var recordingRe = regexp.MustCompile(`^/web/cluster/[^/]+/session/[^/]+$`) +// regex for the ssh terminal endpoint /web/cluster/:clusterId/console/node/:sid/:login +// which is a route to a ssh session that uses WASM. +var sshSessionRe = regexp.MustCompile(`^/web/cluster/[^/]+/console/node/[^/]+/[^/]+$`) + var indexCSPStringCache *cspCache = newCSPCache() func getIndexContentSecurityPolicyString(cfg proto.Features, urlPath string) string { @@ -209,7 +213,7 @@ func getIndexContentSecurityPolicyString(cfg proto.Features, urlPath string) str } // Nothing found in cache, calculate regex and result - withWasm := desktopSessionRe.MatchString(urlPath) || recordingRe.MatchString(urlPath) + withWasm := desktopSessionRe.MatchString(urlPath) || recordingRe.MatchString(urlPath) || sshSessionRe.MatchString(urlPath) cspString := GetContentSecurityPolicyString( getIndexContentSecurityPolicy(withStripe, withWasm), ) diff --git a/lib/httplib/httplib_test.go b/lib/httplib/httplib_test.go index 8ed0a3690058f..88bcf4604fc75 100644 --- a/lib/httplib/httplib_test.go +++ b/lib/httplib/httplib_test.go @@ -346,7 +346,24 @@ func TestSetIndexContentSecurityPolicy(t *testing.T) { }, }, { - name: "for cloud based usage & desktop session, Stripe managed product (with stripe, with wasm)", + name: "for web ssh session (with wasm)", + features: proto.Features{}, + urlPath: "/web/cluster/:clusterId/console/node/:sessionId/:username", + expectedCspVals: map[string]string{ + "default-src": "'self'", + "base-uri": "'self'", + "form-action": "'self'", + "frame-ancestors": "'none'", + "object-src": "'none'", + "script-src": "'self' 'wasm-unsafe-eval'", + "style-src": "'self' 'unsafe-inline'", + "img-src": "'self' data: blob:", + "font-src": "'self' data:", + "connect-src": "'self' wss:", + }, + }, + { + name: "for cloud based usage & desktop session, with wasm", features: proto.Features{Cloud: true, IsUsageBased: true, IsStripeManaged: true}, urlPath: "/web/cluster/:clusterId/desktops/:desktopName/:username", expectedCspVals: map[string]string{