fix: properly Set Real IP
This commit is contained in:
parent
897e0497d8
commit
14e819e09b
10
main.go
10
main.go
@ -88,7 +88,10 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
UploadHeaders := map[string]string{
|
||||
"X-Api-Key": API_Key,
|
||||
"Content-Type": "application/json",
|
||||
"X-Real-IP": r.RemoteAddr,
|
||||
}
|
||||
|
||||
if handler.IsInternalIP(r.RemoteAddr) {
|
||||
UploadHeaders["X-Real-IP"] = r.RemoteAddr
|
||||
}
|
||||
|
||||
chibisafe_post, err := handler.UploadPost(Chibisafe_basepath, UploadHeaders, PostData)
|
||||
@ -129,7 +132,10 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
ProcessHeaders := map[string]string{
|
||||
"X-Api-Key": API_Key,
|
||||
"Content-Type": "application/json",
|
||||
"X-Real-IP": r.RemoteAddr,
|
||||
}
|
||||
|
||||
if handler.IsInternalIP(r.RemoteAddr) {
|
||||
ProcessHeaders["X-Real-IP"] = r.RemoteAddr
|
||||
}
|
||||
|
||||
PostProcess, err := handler.UploadProcessPost(Chibisafe_basepath, ProcessHeaders, PostProcessData)
|
||||
|
30
src/handler/net.go
Normal file
30
src/handler/net.go
Normal file
@ -0,0 +1,30 @@
|
||||
package handler
|
||||
|
||||
import "net"
|
||||
|
||||
func IsInternalIP(ip string) bool {
|
||||
// Parse the IP address
|
||||
ipAddress := net.ParseIP(ip)
|
||||
if ipAddress == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
internalRanges := []string{
|
||||
"10.0.0.0/8",
|
||||
"172.16.0.0/12",
|
||||
"192.168.0.0/16",
|
||||
}
|
||||
|
||||
for _, internalRange := range internalRanges {
|
||||
_, ipNet, err := net.ParseCIDR(internalRange)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if ipNet.Contains(ipAddress) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
Loading…
Reference in New Issue
Block a user