@@ -37,13 +37,6 @@ type MatchRemoteIP struct {
37
37
// The IPs or CIDR ranges to match.
38
38
Ranges []string `json:"ranges,omitempty"`
39
39
40
- // If true, prefer the first IP in the request's X-Forwarded-For
41
- // header, if present, rather than the immediate peer's IP, as
42
- // the reference IP against which to match. Note that it is easy
43
- // to spoof request headers. Default: false
44
- // DEPRECATED: This is insecure, MatchClientIP should be used instead.
45
- Forwarded bool `json:"forwarded,omitempty"`
46
-
47
40
// cidrs and zones vars should aligned always in the same
48
41
// length and indexes for matching later
49
42
cidrs []* netip.Prefix
@@ -82,11 +75,7 @@ func (m *MatchRemoteIP) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
82
75
d .Next () // consume matcher name
83
76
for d .NextArg () {
84
77
if d .Val () == "forwarded" {
85
- if len (m .Ranges ) > 0 {
86
- return d .Err ("if used, 'forwarded' must be first argument" )
87
- }
88
- m .Forwarded = true
89
- continue
78
+ return d .Err ("the 'forwarded' option is no longer supported; use the 'client_ip' matcher instead" )
90
79
}
91
80
if d .Val () == "private_ranges" {
92
81
m .Ranges = append (m .Ranges , PrivateRangesCIDR ()... )
@@ -105,7 +94,7 @@ func (m *MatchRemoteIP) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
105
94
//
106
95
// Example:
107
96
//
108
- // expression remote_ip('forwarded', ' 192.168.0.0/16', '172.16.0.0/12', '10.0.0.0/8')
97
+ // expression remote_ip('192.168.0.0/16', '172.16.0.0/12', '10.0.0.0/8')
109
98
func (MatchRemoteIP ) CELLibrary (ctx caddy.Context ) (cel.Library , error ) {
110
99
return CELMatcherImpl (
111
100
// name of the macro, this is the function name that users see when writing expressions.
@@ -126,11 +115,7 @@ func (MatchRemoteIP) CELLibrary(ctx caddy.Context) (cel.Library, error) {
126
115
127
116
for _ , input := range strList .([]string ) {
128
117
if input == "forwarded" {
129
- if len (m .Ranges ) > 0 {
130
- return nil , errors .New ("if used, 'forwarded' must be first argument" )
131
- }
132
- m .Forwarded = true
133
- continue
118
+ return nil , errors .New ("the 'forwarded' option is no longer supported; use the 'client_ip' matcher instead" )
134
119
}
135
120
m .Ranges = append (m .Ranges , input )
136
121
}
@@ -151,21 +136,12 @@ func (m *MatchRemoteIP) Provision(ctx caddy.Context) error {
151
136
m .cidrs = cidrs
152
137
m .zones = zones
153
138
154
- if m .Forwarded {
155
- m .logger .Warn ("remote_ip's forwarded mode is deprecated; use the 'client_ip' matcher instead" )
156
- }
157
-
158
139
return nil
159
140
}
160
141
161
142
// Match returns true if r matches m.
162
143
func (m MatchRemoteIP ) Match (r * http.Request ) bool {
163
144
address := r .RemoteAddr
164
- if m .Forwarded {
165
- if fwdFor := r .Header .Get ("X-Forwarded-For" ); fwdFor != "" {
166
- address = strings .TrimSpace (strings .Split (fwdFor , "," )[0 ])
167
- }
168
- }
169
145
clientIP , zoneID , err := parseIPZoneFromString (address )
170
146
if err != nil {
171
147
m .logger .Error ("getting remote IP" , zap .Error (err ))
0 commit comments