Files
owncast/webserver/handlers/remoteFollow.go
Copilot 149d80a07d Inline chat moderation request returning 500s (#4412)
* Initial plan

* Initial analysis of inline chat moderation 500 error issue

Co-authored-by: gabek <414923+gabek@users.noreply.github.com>

* Fix inline chat moderation 500 errors by supporting Authorization header tokens

- Modified RequireUserModerationScopeAccesstoken middleware to check both Authorization header (Bearer tokens) and URL query parameters
- This fixes the issue where inline chat moderation from the web UI was failing with 500 errors
- Maintains backward compatibility with existing code that uses query parameter tokens
- The fix aligns the chat endpoint behavior with the integrations endpoint which already supported Bearer tokens

Addresses the wiring issue between OpenAPI spec and API implementation identified in issue comments.

Co-authored-by: gabek <414923+gabek@users.noreply.github.com>

* Fix inline chat moderation 500 errors by adding nil pointer checks

Co-authored-by: gabek <414923+gabek@users.noreply.github.com>

* Fix nil pointer vulnerabilities across all OpenAPI endpoints

Co-authored-by: gabek <414923+gabek@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: gabek <414923+gabek@users.noreply.github.com>
2025-07-04 23:57:03 -07:00

70 lines
1.9 KiB
Go

package handlers
import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"strings"
"github.com/owncast/owncast/activitypub/webfinger"
"github.com/owncast/owncast/persistence/configrepository"
"github.com/owncast/owncast/webserver/handlers/generated"
webutils "github.com/owncast/owncast/webserver/utils"
)
// RemoteFollow handles a request to begin the remote follow redirect flow.
func RemoteFollow(w http.ResponseWriter, r *http.Request) {
type followResponse struct {
RedirectURL string `json:"redirectUrl"`
}
var request generated.RemoteFollowJSONRequestBody
decoder := json.NewDecoder(r.Body)
if err := decoder.Decode(&request); err != nil {
webutils.WriteSimpleResponse(w, false, "unable to parse request")
return
}
if request.Account == nil {
webutils.WriteSimpleResponse(w, false, "account field is required")
return
}
if *request.Account == "" {
webutils.WriteSimpleResponse(w, false, "Remote Fediverse account is required to follow.")
return
}
configRepository := configrepository.Get()
localActorPath, _ := url.Parse(configRepository.GetServerURL())
localActorPath.Path = fmt.Sprintf("/federation/user/%s", configRepository.GetDefaultFederationUsername())
var template string
links, err := webfinger.GetWebfingerLinks(*request.Account)
if err != nil {
webutils.WriteSimpleResponse(w, false, err.Error())
return
}
// Acquire the remote follow redirect template.
for _, link := range links {
for k, v := range link {
if k == "rel" && v == "http://ostatus.org/schema/1.0/subscribe" && link["template"] != nil {
template = link["template"].(string)
}
}
}
if localActorPath.String() == "" || template == "" {
webutils.WriteSimpleResponse(w, false, "unable to determine remote follow information for "+*request.Account)
return
}
redirectURL := strings.Replace(template, "{uri}", localActorPath.String(), 1)
response := followResponse{
RedirectURL: redirectURL,
}
webutils.WriteResponse(w, response)
}