r100628 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100627‎ | r100628 | r100629 >
Date:17:40, 24 October 2011
Author:pgehres
Status:ok
Tags:fundraising 
Comment:
Fixing potential security issue by passing all querystring elements through a very restrictive regex
Modified paths:
  • /trunk/extensions/FundraiserLandingPage/FundraiserLandingPage.body.php (modified) (history)
  • /trunk/extensions/FundraiserLandingPage/FundraiserLandingPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FundraiserLandingPage/FundraiserLandingPage.php
@@ -38,7 +38,7 @@
3939 * or not they are passed through the querystring.
4040 */
4141 $wgFundraiserLPDefaults = array(
42 - 'template' => 'LandingPage',
43 - 'appeal' => 'appeal-brandon-1',
44 - 'form' => 'lp-form-US7amounts-extrainfo-noppval'
45 -);
 42+ 'template' => 'Lp-wrapper',
 43+ 'appeal' => 'Appeal-default',
 44+ 'form' => 'Form-default'
 45+);
\ No newline at end of file
Index: trunk/extensions/FundraiserLandingPage/FundraiserLandingPage.body.php
@@ -17,31 +17,26 @@
1818 $request = $this->getRequest();
1919 $this->setHeaders();
2020
21 - # load the querystring variables
22 - $values = $request->getValues();
23 -
2421 # clear output variable to be safe
2522 $output = '';
2623
2724 # get the required variables to use for the landing page
28 - # (escaping with both htmlspecialchars and wfEscapeWikiText since the
29 - # parameters are intending to reference templates)
30 - $template = wfEscapeWikiText( htmlspecialchars( $request->getText( 'template', $wgFundraiserLPDefaults[ 'template' ] ) ) );
31 - $appeal = wfEscapeWikiText( htmlspecialchars( $request->getText( 'appeal', $wgFundraiserLPDefaults[ 'appeal' ] ) ) );
32 - $form = wfEscapeWikiText( htmlspecialchars( $request->getText( 'form', $wgFundraiserLPDefaults[ 'form' ] ) ) );
 25+ $template = $this->make_safe( $request->getText( 'template', $wgFundraiserLPDefaults[ 'template' ] ) );
 26+ $appeal = $this->make_safe( $request->getText( 'appeal', $wgFundraiserLPDefaults[ 'appeal' ] ) );
 27+ $form = $this->make_safe( $request->getText( 'form', $wgFundraiserLPDefaults[ 'form' ] ) );
3328
3429 # begin generating the template call
3530 $output .= "{{ $template\n| appeal = $appeal\n| form = $form\n";
3631
3732 # add any parameters passed in the querystring
38 - foreach ( $values as $k=>$v ) {
 33+ foreach ( $request->getValues() as $k_unsafe => $v_unsafe ) {
3934 # skip the required variables
40 - if ( $k == "template" || $k == "appeal" || $k == "form" ) {
 35+ if ( $k_unsafe == "template" || $k_unsafe == "appeal" || $k_unsafe == "form" ) {
4136 continue;
4237 }
4338 # get the variables name and value
44 - $key = wfEscapeWikiText( htmlspecialchars( $k ) );
45 - $val = wfEscapeWikiText( htmlspecialchars( $v ) );
 39+ $key = $this->make_safe( $k_unsafe );
 40+ $val = $this->make_safe( $v_unsafe );
4641 # print to the template in wiki-syntax
4742 $output .= "| $key = $val\n";
4843 }
@@ -51,4 +46,22 @@
5247 # print the output to the page
5348 $this->getOutput()->addWikiText( $output );
5449 }
 50+
 51+ /**
 52+ * This function limits the possible charactes passed as template keys and
 53+ * values to letters, numbers, hypens and underscores. The function also
 54+ * performs standard escaping of the passed values.
 55+ *
 56+ * @param $string The unsafe string to escape and check for invalid characters
 57+ * @return mixed|String A string matching the regex or an empty string
 58+ */
 59+ function make_safe( $string ) {
 60+ $num = preg_match( '([a-zA-Z0-9_-]+)', $string, $matches );
 61+
 62+ if ( $num == 1 ){
 63+ # theoretically this is overkill, but better safe than sorry
 64+ return wfEscapeWikiText( htmlspecialchars( $matches[0] ) );
 65+ }
 66+ return '';
 67+ }
5568 }
\ No newline at end of file

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r99802Intial commit of Extension:FundraiserLandingPagepgehres20:42, 14 October 2011

Status & tagging log