Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Validate form field names better (see #8403).
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Sep 5, 2016
1 parent a0a01f0 commit dba369a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Resources/contao/dca/tl_form_field.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
'exclude' => true,
'search' => true,
'inputType' => 'text',
'eval' => array('mandatory'=>true, 'rgxp'=>'extnd', 'spaceToUnderscore'=>true, 'maxlength'=>64, 'tl_class'=>'w50'),
'eval' => array('mandatory'=>true, 'rgxp'=>'fieldname', 'spaceToUnderscore'=>true, 'maxlength'=>64, 'tl_class'=>'w50'),
'sql' => "varchar(64) NOT NULL default ''"
),
'label' => array
Expand Down
3 changes: 3 additions & 0 deletions src/Resources/contao/languages/en/default.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@
<trans-unit id="ERR.invalidGoogleId">
<source>Please enter a numeric Google+ ID or vanity name!</source>
</trans-unit>
<trans-unit id="ERR.invalidFieldName">
<source>Please enter only the following characters: A-Z0-9[]_-</source>
</trans-unit>
<trans-unit id="SEC.question1">
<source>Please add %d and %d.</source>
</trans-unit>
Expand Down
13 changes: 13 additions & 0 deletions src/Resources/contao/library/Contao/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,4 +437,17 @@ public static function isValidFileName($strName)

return true;
}


/**
* Valid form field name
*
* @param mixed $strName The form field name
*
* @return boolean True if the form field name is valid
*/
public static function isFieldName($strName)
{
return preg_match('/^[A-Za-z0-9[\]_-]+$/', $strName);
}
}
8 changes: 8 additions & 0 deletions src/Resources/contao/library/Contao/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,14 @@ protected function validator($varInput)
}
break;

// Check whether the current value is a field name
case 'fieldname':
if (!\Validator::isFieldName($varInput))
{
$this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['invalidFieldName'], $this->strLabel));
}
break;

// HOOK: pass unknown tags to callback functions
default:
if (isset($GLOBALS['TL_HOOKS']['addCustomRegexp']) && is_array($GLOBALS['TL_HOOKS']['addCustomRegexp']))
Expand Down

0 comments on commit dba369a

Please sign in to comment.