r45425 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r45424‎ | r45425 | r45426 >
Date:20:37, 5 January 2009
Author:brion
Status:resolved
Tags:
Comment:
* Fix XSS in Special:Search with extended engine features ("did you mean")

Switched a couple of manually created '<a href>'s to use Linker functions,
and put an htmlspecialchars() on the 'did you mean' snippet result which was
spewing raw input-derived text into output (bad!)
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/specials/SpecialSearch.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialSearch.php
@@ -113,9 +113,11 @@
114114 * @param string $term
115115 */
116116 public function showResults( $term ) {
117 - global $wgOut, $wgDisableTextSearch, $wgContLang;
 117+ global $wgOut, $wgUser, $wgDisableTextSearch, $wgContLang;
118118 wfProfileIn( __METHOD__ );
119119
 120+ $sk = $wgUser->getSkin();
 121+
120122 $this->searchEngine = SearchEngine::create();
121123 $search =& $this->searchEngine;
122124 $search->setLimitOffset( $this->limit, $this->offset );
@@ -166,8 +168,9 @@
167169 array( 'search' => $textMatches->getSuggestionQuery(), 'fulltext' => wfMsg('search') ),
168170 $this->powerSearchOptions()
169171 );
170 - $suggestLink = '<a href="'.$st->escapeLocalURL($stParams).'">'.
171 - $textMatches->getSuggestionSnippet().'</a>';
 172+ $suggestLink = $sk->makeKnownLinkObj( $st,
 173+ htmlspecialchars( $textMatches->getSuggestionSnippet() ),
 174+ $stParams );
172175
173176 $this->didYouMeanHtml = '<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>';
174177 }
@@ -384,7 +387,7 @@
385388 * @param array $terms terms to highlight
386389 */
387390 protected function showHit( $result, $terms ) {
388 - global $wgContLang, $wgLang;
 391+ global $wgContLang, $wgLang, $wgUser;
389392 wfProfileIn( __METHOD__ );
390393
391394 if( $result->isBrokenTitle() ) {
@@ -392,6 +395,7 @@
393396 return "<!-- Broken link in search result -->\n";
394397 }
395398
 399+ $sk = $wgUser->getSkin();
396400 $t = $result->getTitle();
397401
398402 $link = $this->sk->makeKnownLinkObj( $t, $result->getTitleSnippet($terms));
@@ -457,8 +461,8 @@
458462 array('search' => wfMsgForContent('searchrelated').':'.$t->getPrefixedText(),
459463 'fulltext' => wfMsg('search') ));
460464
461 - $related = ' -- <a href="'.$st->escapeLocalURL($stParams).'">'.
462 - wfMsg('search-relatedarticle').'</a>';
 465+ $related = ' -- ' . $sk->makeKnownLinkObj( $st,
 466+ wfMsg('search-relatedarticle'), $stParams );
463467 }
464468
465469 // Include a thumbnail for media files...
@@ -942,8 +946,9 @@
943947 'fulltext' => wfMsg('search')),
944948 $this->powerSearchOptions());
945949
946 - $suggestLink = '<a href="'.$st->escapeLocalURL($stParams).'">'.
947 - $textMatches->getSuggestionSnippet().'</a>';
 950+ $suggestLink = $sk->makeKnownLinkObj( $st,
 951+ htmlspecialchars( $textMatches->getSuggestionSnippet() ),
 952+ $stParams );
948953
949954 $wgOut->addHTML('<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>');
950955 }
@@ -1233,8 +1238,8 @@
12341239 array('search' => wfMsgForContent('searchrelated').':'.$t->getPrefixedText(),
12351240 'fulltext' => wfMsg('search') ));
12361241
1237 - $related = ' -- <a href="'.$st->escapeLocalURL($stParams).'">'.
1238 - wfMsg('search-relatedarticle').'</a>';
 1242+ $related = ' -- ' . $sk->makeKnownLinkObj( $st,
 1243+ wfMsg('search-relatedarticle'), $stParams );
12391244 }
12401245
12411246 // Include a thumbnail for media files...
Index: trunk/phase3/RELEASE-NOTES
@@ -468,8 +468,8 @@
469469 that STDIN can be used for page list
470470 * Sanitizer::decodeCharReferences() now decodes the XHTML "&apos;" character
471471 entity (loosely related to bug 14365)
 472+* Fix XSS in Special:Search with extended engine features ("did you mean")
472473
473 -
474474 === API changes in 1.14 ===
475475
476476 * Registration time of users registered before the DB field was created is now

Follow-up revisions

RevisionCommit summaryAuthorDate
r45427Follow-up to r45425 -- bug was in MWSearch, not core. It's supposed to be HTM...brion20:46, 5 January 2009

Status & tagging log