From c46fa4c474035779cd8b4a961f0f6941ef102a1c Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 28 Nov 2017 18:40:04 -0800 Subject: [PATCH] Make ChronologyProtector actually use cpPosTime cookies Setup.php was only injected the value from $_GET. LBFactory used to check both before 0e5cd18b74d83c50, with the cookie check left in LBFactoryMW. After d175b391ae2a7, LBFactoryMW class switched to the default LBFactory method for making a ChronologyProtector instance, so the cookie check was lost there too. This means that an HTTP GET request due to a redirect from a POST request will still make sure the DB position store is up-to-date. This only matters is that store uses replication (e.g. cross DC). Also refactor LBFactory handling of the cpPosTime URL parameter. Change-Id: Ie5744577609f4c193cacd71334f92b30f02e3846 --- includes/Setup.php | 9 +++++++-- includes/libs/rdbms/lbfactory/ILBFactory.php | 1 + includes/libs/rdbms/lbfactory/LBFactory.php | 5 +++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/includes/Setup.php b/includes/Setup.php index 4c281b13ce..081ea68363 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -734,13 +734,18 @@ if ( !$wgDBerrorLogTZ ) { $wgDBerrorLogTZ = $wgLocaltimezone; } -// initialize the request object in $wgRequest +// Initialize the request object in $wgRequest $wgRequest = RequestContext::getMain()->getRequest(); // BackCompat // Set user IP/agent information for causal consistency purposes MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->setRequestInfo( [ 'IPAddress' => $wgRequest->getIP(), 'UserAgent' => $wgRequest->getHeader( 'User-Agent' ), - 'ChronologyProtection' => $wgRequest->getHeader( 'ChronologyProtection' ) + 'ChronologyProtection' => $wgRequest->getHeader( 'ChronologyProtection' ), + // The cpPosTime cookie has no prefix and is set by MediaWiki::preOutputCommit() + 'ChronologyPositionTime' => $wgRequest->getFloat( + 'cpPosTime', + $wgRequest->getCookie( 'cpPosTime', '' ) + ) ] ); // Useful debug output diff --git a/includes/libs/rdbms/lbfactory/ILBFactory.php b/includes/libs/rdbms/lbfactory/ILBFactory.php index f6d080e4f0..697af0ed76 100644 --- a/includes/libs/rdbms/lbfactory/ILBFactory.php +++ b/includes/libs/rdbms/lbfactory/ILBFactory.php @@ -319,6 +319,7 @@ interface ILBFactory { * - IPAddress : IP address * - UserAgent : User-Agent HTTP header * - ChronologyProtection : cookie/header value specifying ChronologyProtector usage + * - ChronologyPositionTime: timestamp used to get up-to-date DB positions for the agent */ public function setRequestInfo( array $info ); } diff --git a/includes/libs/rdbms/lbfactory/LBFactory.php b/includes/libs/rdbms/lbfactory/LBFactory.php index c891fb6ba7..ef716b68a6 100644 --- a/includes/libs/rdbms/lbfactory/LBFactory.php +++ b/includes/libs/rdbms/lbfactory/LBFactory.php @@ -115,7 +115,8 @@ abstract class LBFactory implements ILBFactory { $this->requestInfo = [ 'IPAddress' => isset( $_SERVER[ 'REMOTE_ADDR' ] ) ? $_SERVER[ 'REMOTE_ADDR' ] : '', 'UserAgent' => isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '', - 'ChronologyProtection' => 'true' + 'ChronologyProtection' => 'true', + 'ChronologyPositionTime' => isset( $_GET['cpPosTime'] ) ? $_GET['cpPosTime'] : null ]; $this->cliMode = isset( $conf['cliMode'] ) ? $conf['cliMode'] : PHP_SAPI === 'cli'; @@ -440,7 +441,7 @@ abstract class LBFactory implements ILBFactory { 'ip' => $this->requestInfo['IPAddress'], 'agent' => $this->requestInfo['UserAgent'], ], - isset( $_GET['cpPosTime'] ) ? $_GET['cpPosTime'] : null + $this->requestInfo['ChronologyPositionTime'] ); $this->chronProt->setLogger( $this->replLogger ); -- 2.20.1