Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-20906 backport for 4.6 #11179

Merged
merged 1 commit into from Oct 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CRM/Admin/Form/Extensions.php
Expand Up @@ -51,6 +51,10 @@ public function preProcess() {
$this, FALSE, 0
);

if (!CRM_Utils_Type::validate($this->_key, 'ExtensionKey')) {
throw new CRM_Core_Exception('Extension Key does not match expected standard');
}

$session = CRM_Core_Session::singleton();
$url = CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1&action=browse');
$session->pushUserContext($url);
Expand Down
12 changes: 12 additions & 0 deletions CRM/Utils/Rule.php
Expand Up @@ -857,4 +857,16 @@ public static function qfKey($key) {
return ($key) ? CRM_Core_Key::valid($key) : FALSE;
}

/**
* @param string $key Extension Key to check
* @return bool
*/
public static function checkExtensionKeyIsValid($key = NULL) {

if (!empty($key) && !preg_match('/^[0-9a-zA-Z._-]+$/', $key)) {
return FALSE;
}
return TRUE;
}

}
6 changes: 6 additions & 0 deletions CRM/Utils/Type.php
Expand Up @@ -417,6 +417,12 @@ public static function validate($data, $type, $abort = TRUE, $name = 'One of par
}
break;

case 'ExtensionKey':
if (CRM_Utils_Rule::checkExtensionKeyIsValid($data)) {
return $data;
}
break;

default:
CRM_Core_Error::fatal("Cannot recognize $type for $data");
break;
Expand Down
20 changes: 20 additions & 0 deletions tests/phpunit/CRM/Utils/RuleTest.php
Expand Up @@ -80,4 +80,24 @@ public function numericDataProvider() {
);
}

/**
* @return array
*/
public function extensionKeyTests() {
$keys = array();
$keys[] = array('org.civicrm.multisite', TRUE);
$keys[] = array('au.org.contribute2016', TRUE);
$keys[] = array('%3Csvg%20onload=alert(0)%3E', FALSE);
return $keys;
}

/**
* @param $key
* @param $expectedResult
* @dataProvider extensionKeyTests
*/
public function testExtensionKeyValid($key, $expectedResult) {
$this->assertEquals($expectedResult, CRM_Utils_Rule::checkExtensionKeyIsValid($key));
}

}