| 1 | // Copyright 2015 Matthew Holt and The Caddy Authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ |
| 16 | |
| 17 | import ( |
| 18 | "errorsscip-go gomod github.com/golang/go/src go1.25.1 errors/" |
| 19 | "fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/" |
| 20 | "netscip-go gomod github.com/golang/go/src go1.25.1 net/" |
| 21 | "net/httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/" |
| 22 | "net/netipscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/" |
| 23 | "stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/" |
| 24 | |
| 25 | "github.com/google/cel-go/celscip-go gomod github.com/google/cel-go v0.28.1 `github.com/google/cel-go/cel`/" |
| 26 | "github.com/google/cel-go/common/types/refscip-go gomod github.com/google/cel-go v0.28.1 `github.com/google/cel-go/common/types/ref`/" |
| 27 | "go.uber.org/zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/" |
| 28 | "go.uber.org/zap/zapcorescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/" |
| 29 | |
| 30 | "github.com/caddyserver/caddy/v2scip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/" |
| 31 | "github.com/caddyserver/caddy/v2/caddyconfig/caddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/" |
| 32 | "github.com/caddyserver/caddy/v2/internalscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/internal`/" |
| 33 | ) |
| 34 | |
| 35 | // MatchRemoteIP matches requests by the remote IP address, |
| 36 | // i.e. the IP address of the direct connection to Caddy. |
| 37 | type MatchRemoteIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP# struct { |
| 38 | // The IPs or CIDR ranges to match. |
| 39 | Rangesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#Ranges. []string `json:"ranges,omitempty"` |
| 40 | |
| 41 | // cidrs and zones vars should aligned always in the same |
| 42 | // length and indexes for matching later |
| 43 | cidrsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#cidrs. []*netipscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/.Prefixscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/Prefix# |
| 44 | zonesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#zones. []string |
| 45 | loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#logger. *zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Loggerscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger# |
| 46 | } |
| 47 | |
| 48 | // MatchClientIP matches requests by the client IP address, |
| 49 | // i.e. the resolved address, considering trusted proxies. |
| 50 | type MatchClientIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP# struct { |
| 51 | // The IPs or CIDR ranges to match. |
| 52 | Rangesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#Ranges. []string `json:"ranges,omitempty"` |
| 53 | |
| 54 | // cidrs and zones vars should aligned always in the same |
| 55 | // length and indexes for matching later |
| 56 | cidrsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#cidrs. []*netipscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/.Prefixscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/Prefix# |
| 57 | zonesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#zones. []string |
| 58 | loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#logger. *zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Loggerscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger# |
| 59 | } |
| 60 | |
| 61 | func initscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/init().() { |
| 62 | caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.RegisterModulescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/RegisterModule().(MatchRemoteIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#{}) |
| 63 | caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.RegisterModulescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/RegisterModule().(MatchClientIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#{}) |
| 64 | } |
| 65 | |
| 66 | // CaddyModule returns the Caddy module information. |
| 67 | func (MatchRemoteIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#) CaddyModulescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#CaddyModule().() caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ModuleInfoscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleInfo# { |
| 68 | return caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ModuleInfoscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleInfo#{ |
| 69 | IDscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleInfo#ID.: "http.matchers.remote_ip", |
| 70 | Newscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleInfo#New.: func() caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Modulescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Module# { return new(MatchRemoteIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#) }, |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | // UnmarshalCaddyfile implements caddyfile.Unmarshaler. |
| 75 | func (m *MatchRemoteIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#) UnmarshalCaddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#UnmarshalCaddyfile().(d *caddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/.Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) error { |
| 76 | // iterate to merge multiple matchers into one |
| 77 | for d.Nextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Next().() { |
| 78 | for d.NextArgscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#NextArg().() { |
| 79 | if d.Valscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Val().() == "forwarded" { |
| 80 | return d.Errscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Err().("the 'forwarded' option is no longer supported; use the 'client_ip' matcher instead") |
| 81 | } |
| 82 | if d.Valscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Val().() == "private_ranges" { |
| 83 | m.Rangesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#Ranges. = append(m.Rangesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#Ranges., internalscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/internal`/.PrivateRangesCIDRscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/internal`/PrivateRangesCIDR().()...) |
| 84 | continue |
| 85 | } |
| 86 | m.Rangesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#Ranges. = append(m.Rangesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#Ranges., d.Valscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Val().()) |
| 87 | } |
| 88 | if d.NextBlockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#NextBlock().(0) { |
| 89 | return d.Errscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Err().("malformed remote_ip matcher: blocks are not supported") |
| 90 | } |
| 91 | } |
| 92 | return nil |
| 93 | } |
| 94 | |
| 95 | // CELLibrary produces options that expose this matcher for use in CEL |
| 96 | // expression matchers. |
| 97 | // |
| 98 | // Example: |
| 99 | // |
| 100 | // expression remote_ip('192.168.0.0/16', '172.16.0.0/12', '10.0.0.0/8') |
| 101 | func (MatchRemoteIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#) CELLibraryscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#CELLibrary().(ctx caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#) (celscip-go gomod github.com/google/cel-go v0.28.1 `github.com/google/cel-go/cel`/.Libraryscip-go gomod github.com/google/cel-go v0.28.1 `github.com/google/cel-go/cel`/Library#, error) { |
| 102 | return CELMatcherImplscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/CELMatcherImpl().( |
| 103 | // name of the macro, this is the function name that users see when writing expressions. |
| 104 | "remote_ip", |
| 105 | // name of the function that the macro will be rewritten to call. |
| 106 | "remote_ip_match_request_list", |
| 107 | // internal data type of the MatchPath value. |
| 108 | []*celscip-go gomod github.com/google/cel-go v0.28.1 `github.com/google/cel-go/cel`/.Typescip-go gomod github.com/google/cel-go v0.28.1 `github.com/google/cel-go/cel`/Type#{celscip-go gomod github.com/google/cel-go v0.28.1 `github.com/google/cel-go/cel`/.ListTypescip-go gomod github.com/google/cel-go v0.28.1 `github.com/google/cel-go/cel`/ListType.(celscip-go gomod github.com/google/cel-go v0.28.1 `github.com/google/cel-go/cel`/.StringTypescip-go gomod github.com/google/cel-go v0.28.1 `github.com/google/cel-go/cel`/StringType.)}, |
| 109 | // function to convert a constant list of strings to a MatchPath instance. |
| 110 | func(data refscip-go gomod github.com/google/cel-go v0.28.1 `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go v0.28.1 `github.com/google/cel-go/common/types/ref`/Val#) (RequestMatcherWithErrorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/RequestMatcherWithError#, error) { |
| 111 | refStringList := stringSliceTypescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/stringSliceType. |
| 112 | strList, err := data.ConvertToNativescip-go gomod github.com/google/cel-go v0.28.1 `github.com/google/cel-go/common/types/ref`/Val#ConvertToNative().(refStringList) |
| 113 | if err != nil { |
| 114 | return nil, err |
| 115 | } |
| 116 | |
| 117 | m := MatchRemoteIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#{} |
| 118 | |
| 119 | for _, input := range strList.([]string) { |
| 120 | if input == "forwarded" { |
| 121 | return nil, errorsscip-go gomod github.com/golang/go/src go1.25.1 errors/.Newscip-go gomod github.com/golang/go/src go1.25.1 errors/New().("the 'forwarded' option is no longer supported; use the 'client_ip' matcher instead") |
| 122 | } |
| 123 | m.Rangesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#Ranges. = append(m.Rangesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#Ranges., input) |
| 124 | } |
| 125 | |
| 126 | err = m.Provisionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#Provision().(ctx) |
| 127 | return m, err |
| 128 | }, |
| 129 | ) |
| 130 | } |
| 131 | |
| 132 | // Provision parses m's IP ranges, either from IP or CIDR expressions. |
| 133 | func (m *MatchRemoteIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#) Provisionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#Provision().(ctx caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#) error { |
| 134 | m.loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#logger. = ctx.Loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#Logger().() |
| 135 | cidrs, zones, err := provisionCidrsZonesFromRangesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/provisionCidrsZonesFromRanges().(m.Rangesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#Ranges.) |
| 136 | if err != nil { |
| 137 | return err |
| 138 | } |
| 139 | m.cidrsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#cidrs. = cidrs |
| 140 | m.zonesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#zones. = zones |
| 141 | |
| 142 | return nil |
| 143 | } |
| 144 | |
| 145 | // Match returns true if r matches m. |
| 146 | func (m MatchRemoteIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#) Matchscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#Match().(r *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#) bool { |
| 147 | match, err := m.MatchWithErrorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#MatchWithError().(r) |
| 148 | if err != nil { |
| 149 | SetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/SetVar().(r.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().(), MatcherErrorVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatcherErrorVarKey., err) |
| 150 | } |
| 151 | return match |
| 152 | } |
| 153 | |
| 154 | // MatchWithError returns true if r matches m. |
| 155 | func (m MatchRemoteIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#) MatchWithErrorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#MatchWithError().(r *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#) (bool, error) { |
| 156 | // if handshake is not finished, we infer 0-RTT that has |
| 157 | // not verified remote IP; could be spoofed, so we throw |
| 158 | // HTTP 425 status to tell the client to try again after |
| 159 | // the handshake is complete |
| 160 | if r.TLSscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#TLS. != nil && !r.TLSscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#TLS..HandshakeCompletescip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/ConnectionState#HandshakeComplete. { |
| 161 | return false, Errorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Error().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.StatusTooEarlyscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/StatusTooEarly., fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("TLS handshake not complete, remote IP cannot be verified")) |
| 162 | } |
| 163 | |
| 164 | address := r.RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr. |
| 165 | clientIP, zoneID, err := parseIPZoneFromStringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/parseIPZoneFromString().(address) |
| 166 | if err != nil { |
| 167 | if c := m.loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#logger..Checkscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Check().(zapcorescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/.ErrorLevelscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/ErrorLevel., "getting remote "); c != nil { |
| 168 | c.Writescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/CheckedEntry#Write().(zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Errorscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Error().(err)) |
| 169 | } |
| 170 | |
| 171 | return false, nil |
| 172 | } |
| 173 | matches, zoneFilter := matchIPByCidrZonesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/matchIPByCidrZones().(clientIP, zoneID, m.cidrsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#cidrs., m.zonesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#zones.) |
| 174 | if !matches && !zoneFilter { |
| 175 | if c := m.loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#logger..Checkscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Check().(zapcorescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/.DebugLevelscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/DebugLevel., "zone ID from remote IP did not match"); c != nil { |
| 176 | c.Writescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/CheckedEntry#Write().(zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Stringscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/String().("zone", zoneID)) |
| 177 | } |
| 178 | } |
| 179 | return matches, nil |
| 180 | } |
| 181 | |
| 182 | // CaddyModule returns the Caddy module information. |
| 183 | func (MatchClientIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#) CaddyModulescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#CaddyModule().() caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ModuleInfoscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleInfo# { |
| 184 | return caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ModuleInfoscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleInfo#{ |
| 185 | IDscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleInfo#ID.: "http.matchers.client_ip", |
| 186 | Newscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleInfo#New.: func() caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Modulescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Module# { return new(MatchClientIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#) }, |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | // UnmarshalCaddyfile implements caddyfile.Unmarshaler. |
| 191 | func (m *MatchClientIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#) UnmarshalCaddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#UnmarshalCaddyfile().(d *caddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/.Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) error { |
| 192 | // iterate to merge multiple matchers into one |
| 193 | for d.Nextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Next().() { |
| 194 | for d.NextArgscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#NextArg().() { |
| 195 | if d.Valscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Val().() == "private_ranges" { |
| 196 | m.Rangesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#Ranges. = append(m.Rangesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#Ranges., internalscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/internal`/.PrivateRangesCIDRscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/internal`/PrivateRangesCIDR().()...) |
| 197 | continue |
| 198 | } |
| 199 | m.Rangesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#Ranges. = append(m.Rangesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#Ranges., d.Valscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Val().()) |
| 200 | } |
| 201 | if d.NextBlockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#NextBlock().(0) { |
| 202 | return d.Errscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Err().("malformed client_ip matcher: blocks are not supported") |
| 203 | } |
| 204 | } |
| 205 | return nil |
| 206 | } |
| 207 | |
| 208 | // CELLibrary produces options that expose this matcher for use in CEL |
| 209 | // expression matchers. |
| 210 | // |
| 211 | // Example: |
| 212 | // |
| 213 | // expression client_ip('192.168.0.0/16', '172.16.0.0/12', '10.0.0.0/8') |
| 214 | func (MatchClientIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#) CELLibraryscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#CELLibrary().(ctx caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#) (celscip-go gomod github.com/google/cel-go v0.28.1 `github.com/google/cel-go/cel`/.Libraryscip-go gomod github.com/google/cel-go v0.28.1 `github.com/google/cel-go/cel`/Library#, error) { |
| 215 | return CELMatcherImplscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/CELMatcherImpl().( |
| 216 | // name of the macro, this is the function name that users see when writing expressions. |
| 217 | "client_ip", |
| 218 | // name of the function that the macro will be rewritten to call. |
| 219 | "client_ip_match_request_list", |
| 220 | // internal data type of the MatchPath value. |
| 221 | []*celscip-go gomod github.com/google/cel-go v0.28.1 `github.com/google/cel-go/cel`/.Typescip-go gomod github.com/google/cel-go v0.28.1 `github.com/google/cel-go/cel`/Type#{celscip-go gomod github.com/google/cel-go v0.28.1 `github.com/google/cel-go/cel`/.ListTypescip-go gomod github.com/google/cel-go v0.28.1 `github.com/google/cel-go/cel`/ListType.(celscip-go gomod github.com/google/cel-go v0.28.1 `github.com/google/cel-go/cel`/.StringTypescip-go gomod github.com/google/cel-go v0.28.1 `github.com/google/cel-go/cel`/StringType.)}, |
| 222 | // function to convert a constant list of strings to a MatchPath instance. |
| 223 | func(data refscip-go gomod github.com/google/cel-go v0.28.1 `github.com/google/cel-go/common/types/ref`/.Valscip-go gomod github.com/google/cel-go v0.28.1 `github.com/google/cel-go/common/types/ref`/Val#) (RequestMatcherWithErrorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/RequestMatcherWithError#, error) { |
| 224 | refStringList := stringSliceTypescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/stringSliceType. |
| 225 | strList, err := data.ConvertToNativescip-go gomod github.com/google/cel-go v0.28.1 `github.com/google/cel-go/common/types/ref`/Val#ConvertToNative().(refStringList) |
| 226 | if err != nil { |
| 227 | return nil, err |
| 228 | } |
| 229 | |
| 230 | m := MatchClientIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#{ |
| 231 | Rangesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#Ranges.: strList.([]string), |
| 232 | } |
| 233 | |
| 234 | err = m.Provisionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#Provision().(ctx) |
| 235 | return m, err |
| 236 | }, |
| 237 | ) |
| 238 | } |
| 239 | |
| 240 | // Provision parses m's IP ranges, either from IP or CIDR expressions. |
| 241 | func (m *MatchClientIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#) Provisionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#Provision().(ctx caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#) error { |
| 242 | m.loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#logger. = ctx.Loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#Logger().() |
| 243 | cidrs, zones, err := provisionCidrsZonesFromRangesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/provisionCidrsZonesFromRanges().(m.Rangesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#Ranges.) |
| 244 | if err != nil { |
| 245 | return err |
| 246 | } |
| 247 | m.cidrsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#cidrs. = cidrs |
| 248 | m.zonesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#zones. = zones |
| 249 | return nil |
| 250 | } |
| 251 | |
| 252 | // Match returns true if r matches m. |
| 253 | func (m MatchClientIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#) Matchscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#Match().(r *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#) bool { |
| 254 | match, err := m.MatchWithErrorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#MatchWithError().(r) |
| 255 | if err != nil { |
| 256 | SetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/SetVar().(r.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().(), MatcherErrorVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatcherErrorVarKey., err) |
| 257 | } |
| 258 | return match |
| 259 | } |
| 260 | |
| 261 | // MatchWithError returns true if r matches m. |
| 262 | func (m MatchClientIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#) MatchWithErrorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#MatchWithError().(r *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#) (bool, error) { |
| 263 | // if handshake is not finished, we infer 0-RTT that has |
| 264 | // not verified remote IP; could be spoofed, so we throw |
| 265 | // HTTP 425 status to tell the client to try again after |
| 266 | // the handshake is complete |
| 267 | if r.TLSscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#TLS. != nil && !r.TLSscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#TLS..HandshakeCompletescip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/ConnectionState#HandshakeComplete. { |
| 268 | return false, Errorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Error().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.StatusTooEarlyscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/StatusTooEarly., fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("TLS handshake not complete, remote IP cannot be verified")) |
| 269 | } |
| 270 | |
| 271 | address := GetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/GetVar().(r.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().(), ClientIPVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ClientIPVarKey.).(string) |
| 272 | clientIP, zoneID, err := parseIPZoneFromStringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/parseIPZoneFromString().(address) |
| 273 | if err != nil { |
| 274 | m.loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#logger..Errorscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Error().("getting client IP", zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Errorscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Error().(err)) |
| 275 | return false, nil |
| 276 | } |
| 277 | matches, zoneFilter := matchIPByCidrZonesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/matchIPByCidrZones().(clientIP, zoneID, m.cidrsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#cidrs., m.zonesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#zones.) |
| 278 | if !matches && !zoneFilter { |
| 279 | m.loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#logger..Debugscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Debug().("zone ID from client IP did not match", zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Stringscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/String().("zone", zoneID)) |
| 280 | } |
| 281 | return matches, nil |
| 282 | } |
| 283 | |
| 284 | func provisionCidrsZonesFromRangesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/provisionCidrsZonesFromRanges().(ranges []string) ([]*netipscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/.Prefixscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/Prefix#, []string, error) { |
| 285 | cidrs := []*netipscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/.Prefixscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/Prefix#{} |
| 286 | zones := []string{} |
| 287 | repl := caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.NewReplacerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NewReplacer().() |
| 288 | for _, str := range ranges { |
| 289 | str = repl.ReplaceAllscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#ReplaceAll().(str, "") |
| 290 | // Exclude the zone_id from the IP |
| 291 | if stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.1 strings/Contains().(str, "%") { |
| 292 | split := stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Splitscip-go gomod github.com/golang/go/src go1.25.1 strings/Split().(str, "%") |
| 293 | str = split[0] |
| 294 | // write zone identifiers in m.zones for matching later |
| 295 | zones = append(zones, split[1]) |
| 296 | } else { |
| 297 | zones = append(zones, "") |
| 298 | } |
| 299 | if stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.1 strings/Contains().(str, "/") { |
| 300 | ipNet, err := netipscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/.ParsePrefixscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/ParsePrefix().(str) |
| 301 | if err != nil { |
| 302 | return nil, nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("parsing CIDR expression '%s': %v", str, err) |
| 303 | } |
| 304 | cidrs = append(cidrs, &ipNet) |
| 305 | } else { |
| 306 | ipAddr, err := netipscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/.ParseAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/ParseAddr().(str) |
| 307 | if err != nil { |
| 308 | return nil, nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("invalid IP address: '%s': %v", str, err) |
| 309 | } |
| 310 | ipNew := netipscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/.PrefixFromscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/PrefixFrom().(ipAddr, ipAddr.BitLenscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/Addr#BitLen().()) |
| 311 | cidrs = append(cidrs, &ipNew) |
| 312 | } |
| 313 | } |
| 314 | return cidrs, zones, nil |
| 315 | } |
| 316 | |
| 317 | func parseIPZoneFromStringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/parseIPZoneFromString().(address string) (netipscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/.Addrscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/Addr#, string, error) { |
| 318 | ipStr, _, err := netscip-go gomod github.com/golang/go/src go1.25.1 net/.SplitHostPortscip-go gomod github.com/golang/go/src go1.25.1 net/SplitHostPort().(address) |
| 319 | if err != nil { |
| 320 | ipStr = address // OK; probably didn't have a port |
| 321 | } |
| 322 | |
| 323 | // Some IPv6-Addresses can contain zone identifiers at the end, |
| 324 | // which are separated with "%" |
| 325 | zoneID := "" |
| 326 | if stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.1 strings/Contains().(ipStr, "%") { |
| 327 | split := stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Splitscip-go gomod github.com/golang/go/src go1.25.1 strings/Split().(ipStr, "%") |
| 328 | ipStr = split[0] |
| 329 | zoneID = split[1] |
| 330 | } |
| 331 | |
| 332 | ipAddr, err := netipscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/.ParseAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/ParseAddr().(ipStr) |
| 333 | if err != nil { |
| 334 | return netipscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/.IPv4Unspecifiedscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/IPv4Unspecified().(), "", err |
| 335 | } |
| 336 | |
| 337 | return ipAddr, zoneID, nil |
| 338 | } |
| 339 | |
| 340 | func matchIPByCidrZonesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/matchIPByCidrZones().(clientIP netipscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/.Addrscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/Addr#, zoneID string, cidrs []*netipscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/.Prefixscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/Prefix#, zones []string) (bool, bool) { |
| 341 | zoneFilter := true |
| 342 | for i, ipRange := range cidrs { |
| 343 | if ipRange.Containsscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/Prefix#Contains().(clientIP) { |
| 344 | // Check if there are zone filters assigned and if they match. |
| 345 | if zones[i] == "" || zoneID == zones[i] { |
| 346 | return true, false |
| 347 | } |
| 348 | zoneFilter = false |
| 349 | } |
| 350 | } |
| 351 | return false, zoneFilter |
| 352 | } |
| 353 | |
| 354 | // Interface guards |
| 355 | var ( |
| 356 | _ RequestMatcherWithErrorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/RequestMatcherWithError# = (*MatchRemoteIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#)(nil) |
| 357 | _ caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Provisionerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Provisioner# = (*MatchRemoteIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#)(nil) |
| 358 | _ caddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/.Unmarshalerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Unmarshaler# = (*MatchRemoteIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#)(nil) |
| 359 | _ CELLibraryProducerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/CELLibraryProducer# = (*MatchRemoteIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchRemoteIP#)(nil) |
| 360 | |
| 361 | _ RequestMatcherWithErrorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/RequestMatcherWithError# = (*MatchClientIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#)(nil) |
| 362 | _ caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Provisionerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Provisioner# = (*MatchClientIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#)(nil) |
| 363 | _ caddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/.Unmarshalerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Unmarshaler# = (*MatchClientIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#)(nil) |
| 364 | _ CELLibraryProducerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/CELLibraryProducer# = (*MatchClientIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/MatchClientIP#)(nil) |
| 365 | ) |