fix: allow localhost alarm reports without token

This commit is contained in:
tian 2026-05-07 12:10:21 +08:00
parent 84aab0fa8e
commit 5d1b32c071
2 changed files with 7 additions and 1 deletions

View File

@ -41,7 +41,8 @@ func (s *Server) handleAlarmReport(w http.ResponseWriter, r *http.Request) {
errorJSON(w, http.StatusMethodNotAllowed, "method not allowed")
return
}
if !s.authorize(r, true) {
// Allow localhost requests without token (media-server alarm callback)
if !isLocalhost(r) && !s.authorize(r, true) {
errorJSON(w, http.StatusUnauthorized, "unauthorized")
return
}
@ -181,3 +182,8 @@ func randomHex(n int) string {
rand.Read(b)
return hex.EncodeToString(b)[:n]
}
func isLocalhost(r *http.Request) bool {
ip := remoteIP(r)
return ip == "127.0.0.1" || ip == "::1" || ip == "localhost"
}

Binary file not shown.