Take control over your live stream video by running it yourself. Streaming + chat out of the box.
HTML activitypubbroadcastingchatdecentralizedfederationfediversegolanghacktoberfesthlslivelivestreamowncastrtmpself-hostedstreaming-videovideo
fix(auth): keep federation endpoints public
Gabe Kangas019eb2aa7c12
diff --git a/pluginhost/authgate.go b/pluginhost/authgate.goindex 7d897b36f5..11c6c2e308 100644--- a/pluginhost/authgate.go+++ b/pluginhost/authgate.go@@ -62,6 +62,7 @@ var gateExemptions = []gateExemption{{"logo", exemptLogoRoutes},{"active-gate-plugin", exemptActiveGatePluginRoutes},{"external-api", exemptExternalAPIRoutes},+ {"federation", exemptFederationRoutes},{"directory-api", exemptDirectoryAPI},{"third-party-player", exemptThirdPartyPlayerRoutes},{"stream-status", exemptStreamStatus},@@ -154,6 +155,27 @@ func exemptDirectoryAPI(r *http.Request, _ string, _ AuthGateSettings) bool {return r.URL.Path == "/api/yp"}+// exemptFederationRoutes keeps the public ActivityPub protocol surface+// reachable. These endpoints authenticate signed activities themselves and+// enforce federation and privacy settings in their handlers.+func exemptFederationRoutes(r *http.Request, _ string, _ AuthGateSettings) bool {+ if strings.HasPrefix(r.URL.Path, "/federation/") {+ return true+ }++ switch r.URL.Path {+ case "/.well-known/webfinger",+ "/.well-known/host-meta",+ "/.well-known/nodeinfo",+ "/.well-known/x-nodeinfo2",+ "/nodeinfo/2.0",+ "/api/v1/instance":+ return true+ default:+ return false+ }+}+// exemptThirdPartyPlayerRoutes keeps the HLS playlist and segments reachable// for players that cannot complete a browser login (VLC, ffplay, mobile apps).// It applies only to the website-only access mode.diff --git a/pluginhost/authgate_test.go b/pluginhost/authgate_test.goindex b4160ed37f..ed7de06146 100644--- a/pluginhost/authgate_test.go+++ b/pluginhost/authgate_test.go@@ -75,6 +75,12 @@ func TestGateExemptions(t *testing.T) {{"public api/config is still gated", req("/api/config", ""), "g", ""},{"logo is exempt", req("/logo", ""), "g", "logo"},{"external logo is exempt", req("/logo/external", ""), "g", "logo"},+ {"federation inbox is exempt", req("/federation/user/streamer/inbox", ""), "g", "federation"},+ {"federation object is exempt", req("/federation/stream/123", ""), "g", "federation"},+ {"webfinger is exempt", req("/.well-known/webfinger?resource=acct:[email protected]", ""), "g", "federation"},+ {"nodeinfo is exempt", req("/nodeinfo/2.0", ""), "g", "federation"},+ {"instance metadata is exempt", req("/api/v1/instance", ""), "g", "federation"},+ {"similarly named route is not exempt", req("/federationish/actor", ""), "g", ""},{"active gate plugin root", req("/plugins/g", ""), "g", "active-gate-plugin"},{"active gate plugin subpath", req("/plugins/g/callback", ""), "g", "active-gate-plugin"},{"a different plugin is NOT exempt", req("/plugins/other/x", ""), "g", ""},@@ -104,6 +110,39 @@ func TestGateExemptions(t *testing.T) {}}+func TestFederationEndpointsRemainPublicInEveryAccessMode(t *testing.T) {+ endpoints := []string{+ "/federation/user/streamer",+ "/federation/user/streamer/inbox",+ "/federation/user/streamer/outbox",+ "/federation/user/streamer/followers",+ "/federation/stream/123",+ "/.well-known/webfinger?resource=acct:[email protected]",+ "/.well-known/host-meta",+ "/.well-known/nodeinfo",+ "/.well-known/x-nodeinfo2",+ "/nodeinfo/2.0",+ "/api/v1/instance",+ }+ modes := []AuthGateSettings{+ defaultAuthGateSettings(),+ {AccessMode: AuthGateAccessWebsiteAndStream},+ {AccessMode: AuthGateAccessWebsiteStreamAndStatus},+ }++ for _, settings := range modes {+ for _, endpoint := range endpoints {+ t.Run(string(settings.AccessMode)+" "+endpoint, func(t *testing.T) {+ r := httptest.NewRequest(http.MethodPost, endpoint, nil)+ got, _ := decideGate(r, "gate", true, true, false, settings)+ if got != gateAllow {+ t.Fatalf("%s: got %d want gateAllow", endpoint, got)+ }+ })+ }+ }+}+// TestAuthGateAccessPolicyMatrix walks every access mode against the paths// whose treatment the mode is supposed to change, plus the paths it must never// change. Table-complete on purpose: this is the whole operator-facing