r102836 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102835‎ | r102836 | r102837 >
Date:01:12, 12 November 2011
Author:khorn
Status:ok
Tags:
Comment:
Bugfix for the session tokens and caching: The token was being handed out one pageview too late.
r101878
Modified paths:
  • /trunk/extensions/DonationInterface/gateway_common/DonationData.php (modified) (history)
  • /trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php (modified) (history)
  • /trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
@@ -64,11 +64,8 @@
6565 // Display form for the first time
6666 $this->displayForm( $this->errors );
6767 }
68 - } else {
69 - if ( !$this->adapter->isCaching() ) {
70 - // if we're not caching, there's a token mismatch
71 - $this->errors['general']['token-mismatch'] = wfMsg( 'donate_interface-token-mismatch' );
72 - }
 68+ } else {//token mismatch
 69+ $this->errors['general']['token-mismatch'] = wfMsg( 'donate_interface-token-mismatch' );
7370 $this->displayForm( $this->errors );
7471 }
7572 }
Index: trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.body.php
@@ -188,11 +188,8 @@
189189
190190 $this->displayForm( $this->errors );
191191 }
192 - } else {
193 - if ( !$this->adapter->isCaching() ) {
194 - // if we're not caching, there's a token mismatch
195 - $this->errors['general']['token-mismatch'] = wfMsg( 'donate_interface-token-mismatch' );
196 - }
 192+ } else { //token mismatch
 193+ $this->errors['general']['token-mismatch'] = wfMsg( 'donate_interface-token-mismatch' );
197194 $this->displayForm( $this->errors );
198195 }
199196 }
Index: trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php
@@ -59,9 +59,6 @@
6060 return;
6161 }
6262
63 -
64 -
65 -
6663 $wgOut->addExtensionStyle(
6764 $wgExtensionAssetsPath . '/DonationInterface/gateway_forms/css/gateway.css?284' .
6865 $this->adapter->getGlobal( 'CSSVersion' ) );
@@ -104,12 +101,7 @@
105102 } //TODO: There really should be an else here.
106103 }
107104 }
108 - } else {
109 - if ( !$this->adapter->isCaching() ) {
110 - // if we're not caching, there's a token mismatch
111 - $this->errors['general']['token-mismatch'] = wfMsg( 'donate_interface-token-mismatch' );
112 - }
113 - }
 105+ }
114106 }
115107
116108 /**
Index: trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php
@@ -318,24 +318,20 @@
319319 * @return boolean true if match, else false.
320320 */
321321 public function checkTokens() {
322 - if ( !$this->posted ) {
323 - //we don't care, because we can't possibly have a good one at this
324 - //point.
325 - //Additional: If we try for this before we're posted, the squid log
326 - //caching won't work.
327 - return true;
328 - } else {
329 - $checkResult = $this->dataObj->token_checkTokens();
 322+ $checkResult = $this->dataObj->token_checkTokens();
330323
331 - if ( $checkResult ) {
332 - $this->debugarray[] = 'Token Match';
 324+ if ( $checkResult ) {
 325+ if ($this->dataObj->isCaching()){
 326+ $this->debugarray[] = 'Token Not Checked (Caching Enabled)';
333327 } else {
334 - $this->debugarray[] = 'Token MISMATCH';
 328+ $this->debugarray[] = 'Token Match';
335329 }
336 -
337 - $this->refreshGatewayValueFromSource( 'token' );
338 - return $checkResult;
 330+ } else {
 331+ $this->debugarray[] = 'Token MISMATCH';
339332 }
 333+
 334+ $this->refreshGatewayValueFromSource( 'token' );
 335+ return $checkResult;
340336 }
341337
342338 /**
Index: trunk/extensions/DonationInterface/gateway_common/DonationData.php
@@ -357,11 +357,16 @@
358358 }
359359 }
360360
361 -
 361+ /**
 362+ * Tells us if we think we're in caching mode or not.
 363+ * @staticvar string $cache Keeps track of the mode so we don't have to
 364+ * calculate it from the data fields more than once.
 365+ * @return boolean true if we are going to be caching, false if we aren't.
 366+ */
362367 function isCaching(){
363 - //I think it's safe to static this here. I don't want to calc this every
364 - //time some outside object asks if we're caching.
 368+
365369 static $cache = null;
 370+
366371 if ( is_null( $cache ) ){
367372 if ( $this->getVal( '_cache_' ) === 'true' ){ //::head. hit. keyboard.::
368373 if ( $this->isSomething( 'utm_source_id' ) && !is_null( 'utm_source_id' ) ){
@@ -372,6 +377,13 @@
373378 $cache = false;
374379 }
375380 }
 381+
 382+ //this business could change at any second, and it will prevent us from
 383+ //caching, so we're going to keep asking if it's set.
 384+ if (self::sessionExists()){
 385+ $cache = false;
 386+ }
 387+
376388 return $cache;
377389 }
378390
@@ -654,6 +666,13 @@
655667 static $match = null;
656668
657669 if ( $match === null ) {
 670+ if ( $this->isCaching() ){
 671+ //This makes sense.
 672+ //If all three conditions for caching are currently true, the
 673+ //last thing we want to do is screw it up by setting a session
 674+ //token before the page loads.
 675+ return true;
 676+ }
658677
659678 // establish the edit token to prevent csrf
660679 $token = $this->token_getSaltedSessionToken();

Follow-up revisions

RevisionCommit summaryAuthorDate
r102994MFT r102836awjrichards17:19, 14 November 2011
r103003Revert r102836awjrichards18:48, 14 November 2011
r103847MFT r102338, r102681, r102685, r102810, r102828, r102829, r102832, r102836, r...khorn22:30, 21 November 2011
r103848MFT r102338, r102681, r102685, r102810, r102828, r102829, r102832, r102836, r...khorn22:31, 21 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r101878Fix: The squid log caching and the sessions were fighting eachother. Now, the...khorn20:54, 3 November 2011

Status & tagging log