aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2025-01-25 09:14:08 +0100
committerGravatar GitHub <noreply@github.com> 2025-01-25 09:14:08 +0100
commit22b74b0a5790360d81088a83addab1f98b7f7947 (patch)
tree2b08182a24cef248ac7ec9bb45c375cb33eb2f55
parent68497030f988cac483a67b27b96d2ac90a54856e (diff)
Improve cURL proxy options (#7231)
3 is now used for CURLPROXY_HTTPS2 https://github.com/curl/curl/blob/f07612cd9ae1ec50b9bedd749171ad75203c9e7e/include/curl/curl.h#L789 Related to https://github.com/FreshRSS/FreshRSS/issues/7209
-rwxr-xr-xapp/Controllers/feedController.php8
-rw-r--r--app/Controllers/subscriptionController.php8
-rw-r--r--app/Services/ImportService.php3
-rw-r--r--app/views/helpers/export/opml.phtml3
-rw-r--r--app/views/helpers/feed/update.phtml11
-rw-r--r--app/views/subscription/add.phtml8
-rw-r--r--lib/Minz/Request.php4
-rw-r--r--lib/lib_rss.php7
8 files changed, 40 insertions, 12 deletions
diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php
index 4d64b40b5..00f321ddf 100755
--- a/app/Controllers/feedController.php
+++ b/app/Controllers/feedController.php
@@ -175,15 +175,17 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
$max_redirs = Minz_Request::paramInt('curl_params_redirects');
$useragent = Minz_Request::paramString('curl_params_useragent', plaintext: true);
$proxy_address = Minz_Request::paramString('curl_params', plaintext: true);
- $proxy_type = Minz_Request::paramString('proxy_type', plaintext: true);
+ $proxy_type = Minz_Request::paramIntNull('proxy_type');
$request_method = Minz_Request::paramString('curl_method', plaintext: true);
$request_fields = Minz_Request::paramString('curl_fields', plaintext: true);
$headers = Minz_Request::paramTextToArray('http_headers', plaintext: true);
$opts = [];
- if ($proxy_type !== '') {
+ if ($proxy_type !== null) {
+ $opts[CURLOPT_PROXYTYPE] = $proxy_type;
+ }
+ if ($proxy_address !== '') {
$opts[CURLOPT_PROXY] = $proxy_address;
- $opts[CURLOPT_PROXYTYPE] = (int)$proxy_type;
}
if ($cookie !== '') {
$opts[CURLOPT_COOKIE] = $cookie;
diff --git a/app/Controllers/subscriptionController.php b/app/Controllers/subscriptionController.php
index 33e4af340..800f6b7c9 100644
--- a/app/Controllers/subscriptionController.php
+++ b/app/Controllers/subscriptionController.php
@@ -157,14 +157,16 @@ class FreshRSS_subscription_Controller extends FreshRSS_ActionController {
$max_redirs = Minz_Request::paramInt('curl_params_redirects');
$useragent = Minz_Request::paramString('curl_params_useragent', plaintext: true);
$proxy_address = Minz_Request::paramString('curl_params', plaintext: true);
- $proxy_type = Minz_Request::paramString('proxy_type', plaintext: true);
+ $proxy_type = Minz_Request::paramIntNull('proxy_type');
$request_method = Minz_Request::paramString('curl_method', plaintext: true);
$request_fields = Minz_Request::paramString('curl_fields', plaintext: true);
$headers = Minz_Request::paramTextToArray('http_headers', plaintext: true);
$opts = [];
- if ($proxy_type !== '') {
+ if ($proxy_type !== null) {
+ $opts[CURLOPT_PROXYTYPE] = $proxy_type;
+ }
+ if ($proxy_address !== '') {
$opts[CURLOPT_PROXY] = $proxy_address;
- $opts[CURLOPT_PROXYTYPE] = (int)$proxy_type;
}
if ($cookie !== '') {
$opts[CURLOPT_COOKIE] = $cookie;
diff --git a/app/Services/ImportService.php b/app/Services/ImportService.php
index 00bb89229..96591053b 100644
--- a/app/Services/ImportService.php
+++ b/app/Services/ImportService.php
@@ -296,6 +296,9 @@ class FreshRSS_Import_Service {
}
if (isset($feed_elt['frss:CURLOPT_PROXYTYPE'])) {
$curl_params[CURLOPT_PROXYTYPE] = (int)$feed_elt['frss:CURLOPT_PROXYTYPE'];
+ if ($curl_params[CURLOPT_PROXYTYPE] === 3) { // Legacy for NONE
+ $curl_params[CURLOPT_PROXYTYPE] = -1;
+ }
}
if (isset($feed_elt['frss:CURLOPT_USERAGENT'])) {
$curl_params[CURLOPT_USERAGENT] = $feed_elt['frss:CURLOPT_USERAGENT'];
diff --git a/app/views/helpers/export/opml.phtml b/app/views/helpers/export/opml.phtml
index 37e728470..fba6d2498 100644
--- a/app/views/helpers/export/opml.phtml
+++ b/app/views/helpers/export/opml.phtml
@@ -107,6 +107,9 @@ function feedsToOutlines(array $feeds, bool $excludeMutedFeeds = false): array {
$outline['frss:CURLOPT_POSTFIELDS'] = $curl_params[CURLOPT_POSTFIELDS] ?? null;
$outline['frss:CURLOPT_PROXY'] = $curl_params[CURLOPT_PROXY] ?? null;
$outline['frss:CURLOPT_PROXYTYPE'] = $curl_params[CURLOPT_PROXYTYPE] ?? null;
+ if ($outline['frss:CURLOPT_PROXYTYPE'] === 3) { // Legacy for NONE
+ $outline['frss:CURLOPT_PROXYTYPE'] = -1;
+ }
$outline['frss:CURLOPT_USERAGENT'] = $curl_params[CURLOPT_USERAGENT] ?? null;
if (!empty($curl_params[CURLOPT_HTTPHEADER]) && is_array($curl_params[CURLOPT_HTTPHEADER])) {
diff --git a/app/views/helpers/feed/update.phtml b/app/views/helpers/feed/update.phtml
index 7dd71a0da..92fedd992 100644
--- a/app/views/helpers/feed/update.phtml
+++ b/app/views/helpers/feed/update.phtml
@@ -740,7 +740,7 @@
<div class="group-controls">
<input type="text" name="curl_params_useragent" id="curl_params_useragent" class="w100" value="<?=
htmlspecialchars((string)($curlParams[CURLOPT_USERAGENT] ?? ''), ENT_COMPAT, 'UTF-8')
- ?>" placeholder="<?= _t('gen.short.blank_to_disable') ?>" />
+ ?>" placeholder="<?= _t('gen.short.by_default') ?>" />
<p class="help"><?= _i('help') ?> <?= _t('sub.feed.useragent_help') ?></p>
</div>
</div>
@@ -750,14 +750,19 @@
<div class="group-controls">
<select name="proxy_type" id="proxy_type"><?php
$type = $curlParams[CURLOPT_PROXYTYPE] ?? '';
- foreach (['' => '', 3 => 'NONE', 0 => 'HTTP', 2 => 'HTTPS', 4 => 'SOCKS4', 6 => 'SOCKS4A', 5 => 'SOCKS5', 7 => 'SOCKS5H'] as $k => $v) {
+ if ($type === 3) { // Legacy for NONE
+ $type = -1;
+ }
+ foreach (['' => '', -1 => 'NONE', CURLPROXY_HTTP => 'HTTP', CURLPROXY_HTTPS => 'HTTPS',
+ CURLPROXY_SOCKS4 => 'SOCKS4', CURLPROXY_SOCKS4A => 'SOCKS4A', CURLPROXY_SOCKS5 => 'SOCKS5',
+ CURLPROXY_SOCKS5_HOSTNAME => 'SOCKS5H'] as $k => $v) {
echo '<option value="' . $k . ($type === $k ? '" selected="selected' : '' ) . '">' . $v . '</option>';
}
?>
</select>
<input type="text" name="curl_params" id="curl_params" value="<?=
htmlspecialchars((string)($curlParams[CURLOPT_PROXY] ?? ''), ENT_COMPAT, 'UTF-8')
- ?>" placeholder="<?= _t('gen.short.blank_to_disable') ?>" />
+ ?>" placeholder="<?= _t('gen.short.by_default') ?>" />
<p class="help"><?= _i('help') ?> <?= _t('sub.feed.proxy_help') ?></p>
</div>
</div>
diff --git a/app/views/subscription/add.phtml b/app/views/subscription/add.phtml
index c3b240975..50d3380a8 100644
--- a/app/views/subscription/add.phtml
+++ b/app/views/subscription/add.phtml
@@ -306,7 +306,7 @@
<div class="form-group">
<label class="group-name" for="curl_params_useragent"><?= _t('sub.feed.useragent') ?></label>
<div class="group-controls">
- <input type="text" name="curl_params_useragent" id="curl_params_useragent" value="" placeholder="<?= _t('gen.short.blank_to_disable') ?>" />
+ <input type="text" name="curl_params_useragent" id="curl_params_useragent" value="" placeholder="<?= _t('gen.short.by_default') ?>" />
<p class="help"><?= _i('help') ?> <?= _t('sub.feed.useragent_help') ?></p>
</div>
</div>
@@ -315,12 +315,14 @@
<label class="group-name" for="proxy_type"><?= _t('sub.feed.proxy') ?></label>
<div class="group-controls">
<select class="number" name="proxy_type" id="proxy_type"><?php
- foreach (['' => '', 3 => 'NONE', 0 => 'HTTP', 2 => 'HTTPS', 4 => 'SOCKS4', 6 => 'SOCKS4A', 5 => 'SOCKS5', 7 => 'SOCKS5H'] as $k => $v) {
+ foreach (['' => '', -1 => 'NONE', CURLPROXY_HTTP => 'HTTP', CURLPROXY_HTTPS => 'HTTPS',
+ CURLPROXY_SOCKS4 => 'SOCKS4', CURLPROXY_SOCKS4A => 'SOCKS4A', CURLPROXY_SOCKS5 => 'SOCKS5',
+ CURLPROXY_SOCKS5_HOSTNAME => 'SOCKS5H'] as $k => $v) {
echo '<option value="' . $k . '">' . $v . '</option>';
}
?>
</select>
- <input type="text" name="curl_params" id="curl_params" value="" placeholder="<?= _t('gen.short.blank_to_disable') ?>" />
+ <input type="text" name="curl_params" id="curl_params" value="" placeholder="<?= _t('gen.short.by_default') ?>" />
<p class="help"><?= _i('help') ?> <?= _t('sub.feed.proxy_help') ?></p>
</div>
</div>
diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php
index 3304ad480..a5d599a45 100644
--- a/lib/Minz/Request.php
+++ b/lib/Minz/Request.php
@@ -120,6 +120,10 @@ class Minz_Request {
return $value;
}
+ public static function paramIntNull(string $key): ?int {
+ return is_numeric(self::$params[$key] ?? null) ? (int)self::$params[$key] : null;
+ }
+
public static function paramInt(string $key): int {
if (!empty(self::$params[$key]) && is_numeric(self::$params[$key])) {
return (int)self::$params[$key];
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index 2a5bdd02f..f0a070820 100644
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@ -329,6 +329,13 @@ function customSimplePie(array $attributes = [], array $curl_options = []): \Sim
}
}
}
+ if (!empty($curl_options[CURLOPT_PROXYTYPE]) && ($curl_options[CURLOPT_PROXYTYPE] < 0 || $curl_options[CURLOPT_PROXYTYPE] === 3)) {
+ // 3 is legacy for NONE
+ unset($curl_options[CURLOPT_PROXYTYPE]);
+ if (isset($curl_options[CURLOPT_PROXY])) {
+ unset($curl_options[CURLOPT_PROXY]);
+ }
+ }
$simplePie->set_curl_options($curl_options);
$simplePie->strip_comments(true);