44 "net"
55 "slices"
66
7+ "github.com/ProjectLighthouseCAU/heimdall/config"
78 "github.com/gofiber/fiber/v2"
89)
910
@@ -13,6 +14,9 @@ import (
1314func AllowLoopbackAndPrivateIPs () fiber.Handler {
1415 return func (c * fiber.Ctx ) error {
1516 clientIp := net .ParseIP (c .IP ())
17+ if _ , ok := c .GetReqHeaders ()[config .ProxyHeader ]; ! ok {
18+ clientIp = c .Context ().RemoteIP () // use remote IP if the ProxyHeader is not set
19+ }
1620 if clientIp .IsPrivate () || clientIp .IsLoopback () {
1721 return c .Next ()
1822 }
@@ -23,6 +27,9 @@ func AllowLoopbackAndPrivateIPs() fiber.Handler {
2327func AllowIPs (ips []net.IP ) fiber.Handler {
2428 return func (c * fiber.Ctx ) error {
2529 clientIp := net .ParseIP (c .IP ())
30+ if _ , ok := c .GetReqHeaders ()[config .ProxyHeader ]; ! ok {
31+ clientIp = c .Context ().RemoteIP () // use remote IP if the ProxyHeader is not set
32+ }
2633 if slices .ContainsFunc (ips , func (ip net.IP ) bool {
2734 return slices .Equal (ip , clientIp )
2835 }) {
@@ -35,6 +42,9 @@ func AllowIPs(ips []net.IP) fiber.Handler {
3542func AllowLoopbackAndPrivateIPsAnd (ips []net.IP ) fiber.Handler {
3643 return func (c * fiber.Ctx ) error {
3744 clientIp := net .ParseIP (c .IP ())
45+ if _ , ok := c .GetReqHeaders ()[config .ProxyHeader ]; ! ok {
46+ clientIp = c .Context ().RemoteIP () // use remote IP if the ProxyHeader is not set
47+ }
3848 if clientIp .IsPrivate () || clientIp .IsLoopback () {
3949 return c .Next ()
4050 }
0 commit comments