Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ const (
type Config struct {
Listen string `yaml:"listen"`

// TrustedProxies is a list of trusted proxy IPs or CIDRs.
// When set, Gin will only trust X-Forwarded-For from these sources.
// When empty (default), proxy headers are not trusted and ClientIP()
// returns the direct remote address.
TrustedProxies []string `yaml:"trusted-proxies"`

Db DbConfig `yaml:"db"`

APIPath string `yaml:"api-path"`
Expand Down
15 changes: 15 additions & 0 deletions docs/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# The application will listen at this address
listen: :8089

# Trusted proxy IPs or CIDRs.
# When set, Gin will only trust X-Forwarded-For headers from these sources
# to determine the client IP. This is important for IP-based rate limiting
# and logging to work correctly.
# When empty or not set (default), proxy headers are NOT trusted and
# ClientIP() returns the direct remote address (most secure default).
# If go-drive is running behind a reverse proxy (e.g. Nginx), you MUST
# configure this to include the proxy's IP/CIDR, otherwise the real
# client IP will not be recognized.
#trusted-proxies:
# - 127.0.0.1
# - 10.0.0.0/8
# - 172.16.0.0/12
# - 192.168.0.0/16

db:
# database type: currently supports sqlite, mysql
type: sqlite
Expand Down
8 changes: 8 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ func InitServer(config common.Config,

engine := gin.New()

if len(config.TrustedProxies) > 0 {
if e := engine.SetTrustedProxies(config.TrustedProxies); e != nil {
return nil, e
}
} else {
engine.SetTrustedProxies(nil)
Comment thread
devld marked this conversation as resolved.
}
Comment thread
cursor[bot] marked this conversation as resolved.

engine.Use(gin.CustomRecovery(handlePanic))

if noLogRequest, _ := os.LookupEnv("NO_LOG_REQUEST"); noLogRequest == "" {
Expand Down
Loading