Take control over your live stream video by running it yourself. Streaming + chat out of the box.
HTML activitypubbroadcastingchatdecentralizedfederationfediversegolanghacktoberfesthlslivelivestreamowncastrtmpself-hostedstreaming-videovideo
test(plugins): de-flake the session signature tamper test
Gabe Kangas94b9cf5ebba3
diff --git a/services/plugins/authsession.go b/services/plugins/authsession.goindex 18e7094b3b..802febdbbf 100644--- a/services/plugins/authsession.go+++ b/services/plugins/authsession.go@@ -102,7 +102,7 @@ func VerifySession(secret []byte, token string, nowUnix int64) (userID string, o// plain-HTTP requests, since many deployments terminate TLS at a proxy and// serve the app over HTTP internally (the proxy hop is the secure boundary).func NewSessionCookie(token string, ttl time.Duration, secure bool) *http.Cookie {- return &http.Cookie{+ return &http.Cookie{ //nolint:gosec // G124: Secure is intentionally set only on HTTPS requests; see comment above.Name: SessionCookieName,Value: token,Path: "/",@@ -115,7 +115,7 @@ func NewSessionCookie(token string, ttl time.Duration, secure bool) *http.Cookie// clearSessionCookie expires the gate session cookie (logout).func ClearSessionCookie(secure bool) *http.Cookie {- return &http.Cookie{+ return &http.Cookie{ //nolint:gosec // G124: Secure matches the session cookie it clears; intentionally HTTPS-only (see NewSessionCookie).Name: SessionCookieName,Value: "",Path: "/",diff --git a/services/plugins/authsession_test.go b/services/plugins/authsession_test.goindex 0f2ba283ff..0702fd970c 100644--- a/services/plugins/authsession_test.go+++ b/services/plugins/authsession_test.go@@ -3,6 +3,7 @@ package pluginsimport ("net/http""net/http/httptest"+ "strings""testing""time")@@ -43,8 +44,17 @@ func TestVerifySession_Tampered(t *testing.T) {if _, ok := VerifySession([]byte("other-secret"), tok, now); ok {t.Fatal("expected rejection under a different secret")}- // Flipped last byte of the signature.- bad := tok[:len(tok)-1] + map[bool]string{true: "A", false: "B"}[tok[len(tok)-1] != 'A']+ // Tampered signature: flip the FIRST signature character. (Not the last —+ // for a 32-byte HMAC the final base64 character carries only 4 significant+ // bits, so several characters decode to the same signature; flipping it is+ // sometimes a no-op, which made this test flaky. The first character always+ // changes a decoded byte.)+ dot := strings.IndexByte(tok, '.')+ repl := byte('A')+ if tok[dot+1] == 'A' {+ repl = 'B'+ }+ bad := tok[:dot+1] + string(repl) + tok[dot+2:]if _, ok := VerifySession(secret, bad, now); ok {t.Fatal("expected rejection of a tampered signature")}