Skip to content

Commit

Permalink
Merge pull request #19045 from seamuslee001/remove_xss_function
Browse files Browse the repository at this point in the history
[REF] Remove xssString as it is providing a false sense of security
  • Loading branch information
seamuslee001 authored Nov 26, 2020
2 parents 309de23 + d33b612 commit ab8c4a3
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 37 deletions.
1 change: 0 additions & 1 deletion CRM/Core/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ public function registerRules() {
'postalCode',
'money',
'positiveInteger',
'xssString',
'fileExists',
'settingPath',
'autocomplete',
Expand Down
24 changes: 1 addition & 23 deletions CRM/Utils/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -801,22 +801,6 @@ public static function currencyCode($value) {
return FALSE;
}

/**
* @param $value
*
* @return bool
*/
public static function xssString($value) {
if (is_string($value)) {
return preg_match('!<(vb)?script[^>]*>.*</(vb)?script.*>!ims',
$value
) ? FALSE : TRUE;
}
else {
return TRUE;
}
}

/**
* Validate json string for xss
*
Expand All @@ -826,9 +810,6 @@ public static function xssString($value) {
* False if invalid, true if valid / safe.
*/
public static function json($value) {
if (!self::xssString($value)) {
return FALSE;
}
$array = json_decode($value, TRUE);
if (!$array || !is_array($array)) {
return FALSE;
Expand Down Expand Up @@ -974,13 +955,10 @@ public static function checkExtensionKeyIsValid($key = NULL) {
protected static function arrayValue($array) {
foreach ($array as $key => $item) {
if (is_array($item)) {
if (!self::xssString($key) || !self::arrayValue($item)) {
if (!self::arrayValue($item)) {
return FALSE;
}
}
if (!self::xssString($key) || !self::xssString($item)) {
return FALSE;
}
}
return TRUE;
}
Expand Down
3 changes: 0 additions & 3 deletions api/v3/Generic/Setvalue.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ function civicrm_api3_generic_setValue($apiRequest) {

case CRM_Utils_Type::T_STRING:
case CRM_Utils_Type::T_TEXT:
if (!CRM_Utils_Rule::xssString($value)) {
return civicrm_api3_create_error(ts('Illegal characters in input (potential scripting attack)'), ['error_code' => 'XSS']);
}
if (array_key_exists('maxlength', $def)) {
$value = substr($value, 0, $def['maxlength']);
}
Expand Down
10 changes: 0 additions & 10 deletions api/v3/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -2186,11 +2186,6 @@ function _civicrm_api3_validate_html(&$params, &$fieldName, $fieldInfo) {
if (strpos($op, 'NULL') || strpos($op, 'EMPTY')) {
return;
}
if ($fieldValue) {
if (!CRM_Utils_Rule::xssString($fieldValue)) {
throw new API_Exception('Input contains illegal SCRIPT tag.', ["field" => $fieldName, "error_code" => "xss"]);
}
}
}

/**
Expand Down Expand Up @@ -2219,11 +2214,6 @@ function _civicrm_api3_validate_string(&$params, &$fieldName, &$fieldInfo, $enti

if ($fieldValue) {
foreach ((array) $fieldValue as $key => $value) {
foreach ([$fieldValue, $key, $value] as $input) {
if (!CRM_Utils_Rule::xssString($input)) {
throw new Exception('Input contains illegal SCRIPT tag.');
}
}
if ($fieldName == 'currency') {
//When using IN operator $fieldValue is a array of currency codes
if (!CRM_Utils_Rule::currencyCode($value)) {
Expand Down

0 comments on commit ab8c4a3

Please sign in to comment.