r106625 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106624‎ | r106625 | r106626 >
Date:04:19, 19 December 2011
Author:aaron
Status:resolved
Tags:
Comment:
* Added proper bypassValidationKey() function to review submission class and removed API hack.
* Improved RevisionReviewForm::validationKey by using a per-user temp secret key
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.setup.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/api/actions/ApiReview.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/backend/FlaggedRevs.hooks.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/business/RevisionReviewForm.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/frontend/RevisionReviewFormUI.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/frontend/specialpages/actions/RevisionReview_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/frontend/specialpages/actions/RevisionReview_body.php
@@ -62,6 +62,8 @@
6363 $form->setValidatedParams( $request->getVal( 'validatedParams' ) );
6464 # Conflict handling
6565 $form->setLastChangeTime( $request->getVal( 'changetime' ) );
 66+ # Session key
 67+ $form->setSessionKey( $request->getSessionData( 'wsFlaggedRevsKey' ) );
6668 # Tag values
6769 foreach ( FlaggedRevs::getTags() as $tag ) {
6870 # This can be NULL if we uncheck a checkbox
@@ -188,7 +190,7 @@
189191 }
190192
191193 public static function AjaxReview( /*$args...*/ ) {
192 - global $wgUser, $wgOut;
 194+ global $wgUser, $wgOut, $wgRequest;
193195
194196 $args = func_get_args();
195197 if ( wfReadOnly() ) {
@@ -263,6 +265,7 @@
264266 return '<err#>' . wfMsgExt( 'notargettext', 'parseinline' );
265267 }
266268 $form->setPage( $title );
 269+ $form->setSessionKey( $wgRequest->getSessionData( 'wsFlaggedRevsKey' ) );
267270
268271 $status = $form->ready(); // all params loaded
269272 # Check session via user token
Index: trunk/extensions/FlaggedRevs/frontend/RevisionReviewFormUI.php
@@ -231,8 +231,9 @@
232232 $form .= Html::hidden( 'imageParams', $imageParams ) . "\n";
233233 $form .= Html::hidden( 'fileVersion', $fileVersion ) . "\n";
234234 # Special token to discourage fiddling...
 235+ $key = $this->request->getSessionData( 'wsFlaggedRevsKey' );
235236 $checkCode = RevisionReviewForm::validationKey(
236 - $templateParams, $imageParams, $fileVersion, $revId
 237+ $templateParams, $imageParams, $fileVersion, $revId, $key
237238 );
238239 $form .= Html::hidden( 'validatedParams', $checkCode ) . "\n";
239240
Index: trunk/extensions/FlaggedRevs/backend/FlaggedRevs.hooks.php
@@ -922,6 +922,19 @@
923923 return true;
924924 }
925925
 926+ public static function setSessionKey( User $user ) {
 927+ global $wgRequest;
 928+ if ( $user->isAllowed( 'review' ) ) {
 929+ $key = $wgRequest->getSessionData( 'wsFlaggedRevsKey' );
 930+ if ( $key === null ) { // should catch login
 931+ $key = User::generateToken( $user->getId() );
 932+ // Temporary secret key attached to this session
 933+ $this->request->setSessionData( 'wsFlaggedRevsKey', $key );
 934+ }
 935+ }
 936+ return true;
 937+ }
 938+
926939 public static function stableDumpQuery( array &$tables, array &$opts, array &$join ) {
927940 $namespaces = FlaggedRevs::getReviewNamespaces();
928941 if ( $namespaces ) {
Index: trunk/extensions/FlaggedRevs/api/actions/ApiReview.php
@@ -84,9 +84,7 @@
8585 $form->setTemplateParams( $templateParams );
8686 $form->setFileParams( $imageParams );
8787 $form->setFileVersion( $fileParam );
88 - $key = RevisionReviewForm::validationKey(
89 - $templateParams, $imageParams, $fileParam, $revid );
90 - $form->setValidatedParams( $key ); # always OK
 88+ $form->bypassValidationKey(); // always OK; uses current templates/files
9189 }
9290 $status = $form->ready(); // all params set
9391
Index: trunk/extensions/FlaggedRevs/business/RevisionReviewForm.php
@@ -23,6 +23,9 @@
2424 protected $oldFrev = null; # Prior FlaggedRevision for Rev with ID $oldid
2525 protected $oldFlags = array(); # Prior flags for Rev with ID $oldid
2626
 27+ protected $sessionKey = ''; # User session key
 28+ protected $skipValidationKey = false; # Skip validatedParams check
 29+
2730 protected function initialize() {
2831 foreach ( FlaggedRevs::getTags() as $tag ) {
2932 $this->dims[$tag] = 0; // default to "inadequate"
@@ -124,6 +127,14 @@
125128 $this->trySet( $this->dims[$tag], (int)$value );
126129 }
127130
 131+ public function setSessionKey( $sessionId ) {
 132+ $this->sessionKey = $sessionId;
 133+ }
 134+
 135+ public function bypassValidationKey() {
 136+ $this->skipValidationKey = true;
 137+ }
 138+
128139 /**
129140 * Check that a target is given (e.g. from GET/POST request)
130141 * @return mixed (true on success, error string on failure)
@@ -190,10 +201,13 @@
191202 return 'review_too_low';
192203 }
193204 # Special token to discourage fiddling with templates/files...
194 - $k = self::validationKey(
195 - $this->templateParams, $this->imageParams, $this->fileVersion, $this->oldid );
196 - if ( $this->validatedParams !== $k ) {
197 - return 'review_bad_key';
 205+ if ( !$this->skipValidationKey ) {
 206+ $k = self::validationKey(
 207+ $this->templateParams, $this->imageParams, $this->fileVersion,
 208+ $this->oldid, $this->sessionKey );
 209+ if ( $this->validatedParams !== $k ) {
 210+ return 'review_bad_key';
 211+ }
198212 }
199213 # Sanity check tags
200214 if ( !FlaggedRevs::flagsAreValid( $this->dims ) ) {
@@ -464,26 +478,27 @@
465479 }
466480
467481 /**
468 - * Get a validation key from versioning metadata
 482+ * Get a validation key from template/file versioning metadata
469483 * @param string $tmpP
470484 * @param string $imgP
471485 * @param string $imgV
472486 * @param integer $rid rev ID
 487+ * @param string $sessKey Session key
473488 * @return string
474489 */
475 - public static function validationKey( $tmpP, $imgP, $imgV, $rid ) {
 490+ public static function validationKey( $tmpP, $imgP, $imgV, $rid, $sessKey ) {
476491 global $wgSecretKey, $wgProxyKey;
477 - $key = $wgSecretKey ? $wgSecretKey : $wgProxyKey; // fall back to $wgProxyKey
478 - $p = md5( $key . $imgP . $tmpP . $rid . $imgV );
479 - return $p;
 492+ $key = md5( $wgSecretKey ? $wgSecretKey : $wgProxyKey ); // fall back to $wgProxyKey
 493+ $keyBits = $key[3] . $key[9] . $key[13] . $key[19] . $key[26];
 494+ return md5( "{$imgP}{$tmpP}{$imgV}{$rid}{$sessKey}{$keyBits}" );
480495 }
481496
482497 /**
483498 * Update rc_patrolled fields in recent changes after (un)accepting a rev.
484499 * This maintains the patrolled <=> reviewed relationship for reviewable namespaces.
485 - *
 500+ *
486501 * RecentChange should only be passed in when an RC item is saved.
487 - *
 502+ *
488503 * @param $rev Revision|RecentChange
489504 * @param $patrol string "patrol" or "unpatrol"
490505 * @param $srev FlaggedRevsion|null The new stable version
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.setup.php
@@ -213,6 +213,7 @@
214214 $wgHooks['getUserPermissionsErrors'][] = 'FlaggedRevsHooks::onUserCan';
215215 # Implicit autoreview rights group
216216 $wgHooks['AutopromoteCondition'][] = 'FlaggedRevsHooks::checkAutoPromoteCond';
 217+ $wgHooks['UserLoadAfterLoadFromSession'][] = 'FlaggedRevsHooks::setSessionKey';
217218
218219 # Stable dump hook
219220 $wgHooks['WikiExporter::dumpStableQuery'][] = 'FlaggedRevsHooks::stableDumpQuery';

Follow-up revisions

RevisionCommit summaryAuthorDate
r106746FU r106625: fixed bogus varaaron01:05, 20 December 2011

Status & tagging log