Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

fix(plugins): always strip the core session cookie from plugin responses

Gabe Kangase86c3df1a347
diff --git a/services/plugins/server.go b/services/plugins/server.go
index 47615664f5..14fff2e183 100644
--- a/services/plugins/server.go
+++ b/services/plugins/server.go
@@ -630,14 +630,15 @@ func writePluginHTTPResponse(w http.ResponseWriter, out []byte, injectStyles boo
}
w.Header().Set(k, v)
}
- // Core owns the gate session cookie: drop any plugin-supplied value for it,
- // then set the host-minted cookies (grant/clear) the plugin asked for via
- // owncast.auth.grantSession / endSession.
- if len(sessionCookies) > 0 {
- stripSetCookie(w.Header(), SessionCookieName)
- for _, c := range sessionCookies {
- http.SetCookie(w, c)
- }
+ // Core owns the gate session cookie. ALWAYS drop any plugin-supplied value
+ // for it — set-cookie is an allowed response header, so a plugin without
+ // auth.gate could otherwise overwrite a viewer's valid owncast_session with
+ // garbage and log them out. Then set the host-minted cookies (grant/clear)
+ // the plugin asked for via owncast.auth.grantSession / endSession (an empty
+ // slice for any plugin that didn't, which is the common case).
+ stripSetCookie(w.Header(), SessionCookieName)
+ for _, c := range sessionCookies {
+ http.SetCookie(w, c)
}
w.WriteHeader(resp.Status)
_, _ = io.WriteString(w, body)
diff --git a/services/plugins/server_test.go b/services/plugins/server_test.go
index 6437f42b46..59b0d4607d 100644
--- a/services/plugins/server_test.go
+++ b/services/plugins/server_test.go
@@ -301,6 +301,23 @@ func TestServer_AdminGate_NotBypassableByTraversal(t *testing.T) {
}
}
+// TestWritePluginHTTPResponse_StripsCoreSessionCookie is the A4 regression: a
+// plugin (even one without auth.gate, so sessionCookies is empty) must not be
+// able to set or clobber the core-owned owncast_session cookie via a Set-Cookie
+// response header.
+func TestWritePluginHTTPResponse_StripsCoreSessionCookie(t *testing.T) {
+ out := []byte(`{"status":200,"headers":{"Set-Cookie":"` + SessionCookieName + `=forged; Path=/"},"body":"ok"}`)
+ rec := httptest.NewRecorder()
+
+ writePluginHTTPResponse(rec, out, false, nil /* no host-minted session cookies */)
+
+ for _, c := range rec.Result().Cookies() {
+ if c.Name == SessionCookieName {
+ t.Fatalf("plugin-set %s cookie was not stripped: %q", SessionCookieName, c.Value)
+ }
+ }
+}
+
func TestServer_NonGetFallsThroughStatic(t *testing.T) {
// POST to a static asset path shouldn't serve the file. (Static is
// read-only; non-GET/HEAD requests fall through to the dynamic handler.)