From 26f1e6f6de2365202366b0025cce2a19cd05baab Mon Sep 17 00:00:00 2001
From: Brian Wolff <bawolff+wn@gmail.com>
Date: Tue, 27 Oct 2015 02:31:00 -0600
Subject: [PATCH] SECURITY: Add data attribute to patrol links so it can't be
 spoofed by user

Javascript used to look just for the patrollinks class, which
could be set by the user in order to patrol an arbitrary page.

Bug: T103239
Change-Id: I13fcc3ce479c0a4a90a6217c2e5244f051eaf862
---
 includes/diff/DifferenceEngine.php          | 2 +-
 includes/page/Article.php                   | 2 +-
 resources/src/mediawiki/page/patrol.ajax.js | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php
index d588d51..ca64f89 100644
--- a/includes/diff/DifferenceEngine.php
+++ b/includes/diff/DifferenceEngine.php
@@ -474,7 +474,7 @@ class DifferenceEngine extends ContextSource {
 			if ( !$linkInfo ) {
 				$this->mMarkPatrolledLink = '';
 			} else {
-				$this->mMarkPatrolledLink = ' <span class="patrollink">[' . Linker::linkKnown(
+				$this->mMarkPatrolledLink = ' <span class="patrollink" data-mw="interface">[' . Linker::linkKnown(
 					$this->mNewPage,
 					$this->msg( 'markaspatrolleddiff' )->escaped(),
 					array(),
diff --git a/includes/page/Article.php b/includes/page/Article.php
index f16158b..6e12cb7 100644
--- a/includes/page/Article.php
+++ b/includes/page/Article.php
@@ -1214,7 +1214,7 @@ class Article implements Page {
 		);
 
 		$outputPage->addHTML(
-			"<div class='patrollink'>" .
+			"<div class='patrollink' data-mw='interface'>" .
 				wfMessage( 'markaspatrolledlink' )->rawParams( $link )->escaped() .
 			'</div>'
 		);
diff --git a/resources/src/mediawiki/page/patrol.ajax.js b/resources/src/mediawiki/page/patrol.ajax.js
index f9b0d35..2ad1ea4 100644
--- a/resources/src/mediawiki/page/patrol.ajax.js
+++ b/resources/src/mediawiki/page/patrol.ajax.js
@@ -12,7 +12,7 @@
 		return;
 	}
 	$( function () {
-		var $patrolLinks = $( '.patrollink a' );
+		var $patrolLinks = $( '.patrollink[data-mw="interface"] a' );
 		$patrolLinks.on( 'click', function ( e ) {
 			var $spinner, href, rcid, apiRequest;
 
-- 
2.0.1

