From 23e7cdc0a32b3739e13d19ae504be0fe215142b6 Mon Sep 17 00:00:00 2001
From: Peter Knut <peter@pematon.com>
Date: Thu, 25 Jan 2024 13:43:18 +0100
Subject: [PATCH] Disable redirections in HTTP based drivers
Applied-Upstream: commit:bc44e5f676b3ff249acd97ed9835305469d55bfa

---
 adminer/drivers/elastic.inc.php | 8 +++++---
 plugins/drivers/clickhouse.php  | 4 +++-
 plugins/drivers/simpledb.php    | 4 +++-
 3 files changed, 11 insertions(+), 5 deletions(-)

--- adminer.git.orig/adminer/drivers/elastic.inc.php	2024-07-03 12:10:04.857272478 +0200
+++ adminer.git/adminer/drivers/elastic.inc.php	2024-07-03 12:10:04.821271765 +0200
@@ -18,9 +18,11 @@
 				@ini_set('track_errors', 1); // @ - may be disabled
 				$file = @file_get_contents("$this->_url/" . ltrim($path, '/'), false, stream_context_create(array('http' => array(
 					'method' => $method,
-					'content' => $content === null ? $content : json_encode($content),
-					'header' => 'Content-Type: application/json',
-					'ignore_errors' => 1, // available since PHP 5.2.10
+					'content' => $content !== null ? json_encode($content) : null,
+					'header' => $content !== null ? 'Content-Type: application/json' : [],
+					'ignore_errors' => 1,
+					'follow_location' => 0,
+					'max_redirects' => 0,
 				))));
 				if (!$file) {
 					$this->error = $php_errormsg;
--- adminer.git.orig/plugins/drivers/clickhouse.php	2024-07-03 12:10:04.857272478 +0200
+++ adminer.git/plugins/drivers/clickhouse.php	2024-07-03 12:10:04.821271765 +0200
@@ -14,7 +14,9 @@
 				'method' => 'POST',
 				'content' => $this->isQuerySelectLike($query) ? "$query FORMAT JSONCompact" : $query,
 				'header' => 'Content-type: application/x-www-form-urlencoded',
-				'ignore_errors' => 1, // available since PHP 5.2.10
+				'ignore_errors' => 1,
+				'follow_location' => 0,
+				'max_redirects' => 0,
 			))));
 
 			if ($file === false) {
--- adminer.git.orig/plugins/drivers/simpledb.php	2024-07-03 12:10:04.857272478 +0200
+++ adminer.git/plugins/drivers/simpledb.php	2024-07-03 12:10:04.845272241 +0200
@@ -425,7 +425,9 @@
 		$file = @file_get_contents((preg_match('~^https?://~', $host) ? $host : "http://$host"), false, stream_context_create(array('http' => array(
 			'method' => 'POST', // may not fit in URL with GET
 			'content' => $query,
-			'ignore_errors' => 1, // available since PHP 5.2.10
+			'ignore_errors' => 1,
+			'follow_location' => 0,
+			'max_redirects' => 0,
 		))));
 		if (!$file) {
 			$connection->error = $php_errormsg;
