Skip to content

Commit 19d5ba2

Browse files
committed
rename trustedproxy option to trustedproxies
We use a new format (array instead of regex) and need a sure way to recognize it. Zebra's approach would not have survived the editing via config manager. As a side effect this also introduces a new languange string, which is good because the old one did no longer apply.
1 parent e449acd commit 19d5ba2

File tree

4 files changed

+19
-24
lines changed

4 files changed

+19
-24
lines changed

conf/dokuwiki.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,21 +162,22 @@
162162
$conf['search_nslimit'] = 0; //limit the search to the current X namespaces
163163
$conf['search_fragment'] = 'exact'; //specify the default fragment search behavior
164164

165-
$conf['trustedproxy'] = ['::1', 'fe80::/10', '127.0.0.0/8', '10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16'];
165+
/* Feature Flags */
166+
$conf['defer_js'] = 1; // Defer javascript to be executed after the page's HTML has been parsed. Setting will be removed in the next release.
167+
$conf['hidewarnings'] = 0; // Hide warnings
168+
169+
/* Network Settings */
170+
$conf['dnslookups'] = 1; //disable to disallow IP to hostname lookups
171+
$conf['jquerycdn'] = 0; //use a CDN for delivering jQuery?
172+
$conf['trustedproxies'] = array('::1', 'fe80::/10', '127.0.0.0/8', '10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16');
166173
// Trusted proxy servers from which to read the X-Forwarded-For header.
167174
// Each item in the array may be either an IPv4 or IPv6 address, or
168175
// an IPv4 or IPv6 CIDR range (e.g. 10.0.0.0/8).
169176

170177
$conf['realip'] = false; // Enable reading the X-Real-IP header. Default: false.
171178
// Only enable this if your server writes this header, otherwise it may be spoofed.
172179

173-
/* Feature Flags */
174-
$conf['defer_js'] = 1; // Defer javascript to be executed after the page's HTML has been parsed. Setting will be removed in the next release.
175-
$conf['hidewarnings'] = 0; // Hide warnings
176180

177-
/* Network Settings */
178-
$conf['dnslookups'] = 1; //disable to disallow IP to hostname lookups
179-
$conf['jquerycdn'] = 0; //use a CDN for delivering jQuery?
180181
// Proxy setup - if your Server needs a proxy to access the web set these
181182
$conf['proxy']['host'] = '';
182183
$conf['proxy']['port'] = '';

inc/Ip.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public static function ipMatches(string $ip, string $ipOrRange): bool
136136
* Given the IP address of a proxy server, determine whether it is
137137
* a known and trusted server.
138138
*
139-
* This test is performed using the config value `trustedproxy`.
139+
* This test is performed using the config value `trustedproxies`.
140140
*
141141
* @param string $ip The IP address of the proxy.
142142
*
@@ -147,25 +147,17 @@ public static function proxyIsTrusted(string $ip): bool
147147
global $conf;
148148

149149
// If the configuration is empty then no proxies are trusted.
150-
if (empty($conf['trustedproxy'])) {
150+
if (empty($conf['trustedproxies'])) {
151151
return false;
152152
}
153153

154-
if (is_string($conf['trustedproxy'])) {
155-
// If the configuration is a string then treat it as a regex.
156-
return preg_match('/' . $conf['trustedproxy'] . '/', $ip);
157-
} elseif (is_array($conf['trustedproxy'])) {
158-
// If the configuration is an array, then at least one must match.
159-
foreach ($conf['trustedproxy'] as $trusted) {
160-
if (Ip::ipMatches($ip, $trusted)) {
161-
return true;
162-
}
154+
foreach ((array) $conf['trustedproxies'] as $trusted) {
155+
if (Ip::ipMatches($ip, $trusted)) {
156+
return true;
163157
}
164-
165-
return false;
166158
}
167159

168-
Logger::error('Invalid value for $conf[trustedproxy]');
160+
Logger::error('Invalid value for $conf[trustedproxies]');
169161
return false;
170162
}
171163

@@ -251,7 +243,7 @@ public static function clientIp(): string
251243
* The IPs are sourced from, in order of preference:
252244
*
253245
* - The X-Real-IP header if $conf[realip] is true.
254-
* - The X-Forwarded-For header if all the proxies are trusted by $conf[trustedproxy].
246+
* - The X-Forwarded-For header if all the proxies are trusted by $conf[trustedproxies].
255247
* - The TCP/IP connection remote address.
256248
* - 0.0.0.0 if all else fails.
257249
*

lib/plugins/config/lang/en/lang.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@
188188
$lang['search_fragment_o_starts_with'] = 'starts with';
189189
$lang['search_fragment_o_ends_with'] = 'ends with';
190190
$lang['search_fragment_o_contains'] = 'contains';
191-
$lang['trustedproxy'] = 'Trust forwarding proxies matching this regular expression about the true client IP they report. The default matches local networks. Leave empty to trust no proxy.';
192191

193192
$lang['_feature_flags'] = 'Feature Flags';
194193
$lang['defer_js'] = 'Defer javascript to be execute after the page\'s HTML has been parsed. Improves perceived page speed but could break a small number of plugins.';
@@ -197,6 +196,8 @@
197196
/* Network Options */
198197
$lang['dnslookups'] = 'DokuWiki will lookup hostnames for remote IP addresses of users editing pages. If you have a slow or non working DNS server or don\'t want this feature, disable this option';
199198
$lang['jquerycdn'] = 'Should the jQuery and jQuery UI script files be loaded from a CDN? This adds additional HTTP requests, but files may load faster and users may have them cached already.';
199+
$lang['trustedproxies'] = 'Comma-separated list of trusted proxy servers from which to read the X-Forwarded-For header. Each item in the array may be either an IPv4 or IPv6 address, or an IPv4 or IPv6 CIDR range (e.g. 10.0.0.0/8). Leave empty to trust no proxy.';
200+
$lang['realip'] = 'Trust the X-Real-IP header. Only enable this if your server writes this header, otherwise it may be spoofed.';
200201

201202
/* jQuery CDN options */
202203
$lang['jquerycdn_o_0'] = 'No CDN, local delivery only';

lib/plugins/config/settings/config.metadata.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@
247247
$meta['readdircache'] = ['numeric'];
248248
$meta['search_nslimit'] = ['numeric', '_min' => 0];
249249
$meta['search_fragment'] = ['multichoice', '_choices' => ['exact', 'starts_with', 'ends_with', 'contains']];
250-
$meta['trustedproxy'] = ['regex'];
251250

252251
$meta['_feature_flags'] = ['fieldset'];
253252
$meta['defer_js'] = ['onoff'];
@@ -256,6 +255,8 @@
256255
$meta['_network'] = ['fieldset'];
257256
$meta['dnslookups'] = ['onoff'];
258257
$meta['jquerycdn'] = ['multichoice', '_choices' => [0, 'jquery', 'cdnjs']];
258+
$meta['trustedproxies'] = ['array', '_caution' => 'security'];
259+
$meta['realip'] = ['onoff', '_caution' => 'security'];
259260
$meta['proxy____host'] = ['string', '_pattern' => '#^(|[a-z0-9\-\.+]+)$#i'];
260261
$meta['proxy____port'] = ['numericopt'];
261262
$meta['proxy____user'] = ['string'];

0 commit comments

Comments
 (0)