🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Ignores invalid timestamps in requests (use current time)
Deluan6a87fc88f7e1
diff --git a/utils/request_helpers.go b/utils/request_helpers.goindex 74210c32d..1fe454609 100644--- a/utils/request_helpers.go+++ b/utils/request_helpers.go@@ -5,6 +5,8 @@ import ("strconv""strings""time"++ "github.com/navidrome/navidrome/log")func ParamString(r *http.Request, param string) string {@@ -28,9 +30,12 @@ func ParamTimes(r *http.Request, param string) []time.Time {times := make([]time.Time, len(pStr))for i, t := range pStr {ti, err := strconv.ParseInt(t, 10, 64)- if err == nil {- times[i] = ToTime(ti)+ if err != nil {+ log.Warn(r.Context(), "Ignoring invalid time param", "time", t, err)+ times[i] = time.Now()+ continue}+ times[i] = ToTime(ti)}return times}diff --git a/utils/request_helpers_test.go b/utils/request_helpers_test.goindex e6d46e4a1..ffd964ce7 100644--- a/utils/request_helpers_test.go+++ b/utils/request_helpers_test.go@@ -92,6 +92,13 @@ var _ = Describe("Request Helpers", func() {It("returns all param occurrences as []time.Time", func() {Expect(ParamTimes(r, "t")).To(Equal([]time.Time{d1, d2}))})+ It("returns current time as default if param is invalid", func() {+ now := time.Now()+ r = httptest.NewRequest("GET", "/ping?t=null", nil)+ times := ParamTimes(r, "t")+ Expect(times).To(HaveLen(1))+ Expect(times[0]).To(BeTemporally(">=", now))+ })})Describe("ParamInt", func() {