Skip to content

Commit

Permalink
add hack to properly process X-Forwarded-For header
Browse files Browse the repository at this point in the history
  • Loading branch information
TymKh committed Oct 11, 2024
1 parent 6fb38a0 commit 4281f97
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ports/http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io"
"net"
"net/http"
"strings"

"github.com/flashbots/builder-hub/domain"
"github.com/go-chi/chi/v5"
Expand Down Expand Up @@ -52,8 +53,12 @@ func (bhs *BuilderHubHandler) getAuthData(r *http.Request) (*AuthData, error) {
if len(ipHeaders) == 0 {
return nil, fmt.Errorf("ip header is empty %w", ErrInvalidAuthData)
}
bhs.log.Info("ip headers", "headers", ipHeaders)
//NOTE: we need this quite awkward logic since header comes not in the canonical format, with space.
ipHeader := ipHeaders[len(ipHeaders)-1]
ipHeaders = strings.Split(ipHeader, ",")
ipHeader = ipHeaders[len(ipHeaders)-1]
ipHeader = strings.TrimSpace(ipHeader)

ip := net.ParseIP(ipHeader)
if ip == nil {
return nil, fmt.Errorf("failed to parse ip %s %w", ipHeader, ErrInvalidAuthData)
Expand Down

0 comments on commit 4281f97

Please sign in to comment.