File tree Expand file tree Collapse file tree 3 files changed +27
-0
lines changed
Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -70,6 +70,12 @@ const (
7070type Config struct {
7171 Listen string `yaml:"listen"`
7272
73+ // TrustedProxies is a list of trusted proxy IPs or CIDRs.
74+ // When set, Gin will only trust X-Forwarded-For from these sources.
75+ // When empty (default), proxy headers are not trusted and ClientIP()
76+ // returns the direct remote address.
77+ TrustedProxies []string `yaml:"trusted-proxies"`
78+
7379 Db DbConfig `yaml:"db"`
7480
7581 APIPath string `yaml:"api-path"`
Original file line number Diff line number Diff line change 11# The application will listen at this address
22listen : :8089
33
4+ # Trusted proxy IPs or CIDRs.
5+ # When set, Gin will only trust X-Forwarded-For headers from these sources
6+ # to determine the client IP. This is important for IP-based rate limiting
7+ # and logging to work correctly.
8+ # When empty or not set (default), proxy headers are NOT trusted and
9+ # ClientIP() returns the direct remote address (most secure default).
10+ # If go-drive is running behind a reverse proxy (e.g. Nginx), you MUST
11+ # configure this to include the proxy's IP/CIDR, otherwise the real
12+ # client IP will not be recognized.
13+ # trusted-proxies:
14+ # - 127.0.0.1
15+ # - 10.0.0.0/8
16+ # - 172.16.0.0/12
17+ # - 192.168.0.0/16
18+
419db :
520 # database type: currently supports sqlite, mysql
621 type : sqlite
Original file line number Diff line number Diff line change @@ -55,6 +55,12 @@ func InitServer(config common.Config,
5555
5656 engine := gin .New ()
5757
58+ if len (config .TrustedProxies ) > 0 {
59+ engine .SetTrustedProxies (config .TrustedProxies )
60+ } else {
61+ engine .SetTrustedProxies (nil )
62+ }
63+
5864 engine .Use (gin .CustomRecovery (handlePanic ))
5965
6066 if noLogRequest , _ := os .LookupEnv ("NO_LOG_REQUEST" ); noLogRequest == "" {
You can’t perform that action at this time.
0 commit comments