Skip to content

Commit 9045b60

Browse files
committed
fix: sync $_REQUEST after modifying $_GET in SiteURIFactory
Fixes #9872 When SiteURIFactory modifies $_GET via setGetArray(), it does not update $_REQUEST. Since IncomingRequest::getVar() reads from $_REQUEST (via fetchGlobal('request')), validation with $validator->withRequest() receives stale data. Changes: - Add Superglobals::syncRequest() method that rebuilds $_REQUEST from $_GET, $_POST, and $_COOKIE respecting PHP's request_order - Call syncRequest() in SiteURIFactory after each setGetArray() call Ref: #9872
1 parent 2a1c348 commit 9045b60

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

system/HTTP/SiteURIFactory.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ private function parseRequestURI(): string
173173
parse_str($this->superglobals->server('QUERY_STRING'), $get);
174174
$this->superglobals->setGetArray($get);
175175

176+
// Sync $_REQUEST so that getVar() works correctly
177+
$this->superglobals->syncRequest();
178+
176179
return URI::removeDotSegments($path);
177180
}
178181

@@ -205,6 +208,9 @@ private function parseQueryString(): string
205208
parse_str($this->superglobals->server('QUERY_STRING'), $get);
206209
$this->superglobals->setGetArray($get);
207210

211+
// Sync $_REQUEST so that getVar() works correctly
212+
$this->superglobals->syncRequest();
213+
208214
return URI::removeDotSegments($path);
209215
}
210216

system/Superglobals.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,4 +456,34 @@ public function setGlobalArray(string $name, array $array): void
456456
),
457457
};
458458
}
459+
460+
/**
461+
* Rebuilds $_REQUEST from $_GET, $_POST, and $_COOKIE according to PHP's
462+
* request_order / variables_order ini setting.
463+
*
464+
* This is necessary when superglobals like $_GET are modified after the
465+
* initial request population, since PHP does not automatically keep
466+
* $_REQUEST in sync.
467+
*
468+
* @see https://www.php.net/manual/en/ini.core.php#ini.request-order
469+
*/
470+
public function syncRequest(): self
471+
{
472+
$requestOrder = ini_get('request_order') ?: ini_get('variables_order');
473+
474+
$this->request = [];
475+
476+
foreach (str_split($requestOrder) as $type) {
477+
match ($type) {
478+
'G' => $this->request = array_replace($this->request, $this->get),
479+
'P' => $this->request = array_replace($this->request, $this->post),
480+
'C' => $this->request = array_replace($this->request, $this->cookie),
481+
default => null,
482+
};
483+
}
484+
485+
$_REQUEST = $this->request;
486+
487+
return $this;
488+
}
459489
}

0 commit comments

Comments
 (0)