Skip to content

Commit

Permalink
MDL-61716 auth_oauth2: field names in mappings allow all characters
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Mastny committed Apr 18, 2018
1 parent 3e3a083 commit 8b58e05
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions admin/tool/oauth2/lang/en/tool_oauth2.php
Expand Up @@ -96,6 +96,7 @@
$string['usebasicauth'] = 'Authenticate token requests via HTTP headers';
$string['usebasicauth_help'] = 'Utilise the HTTP Basic authentication scheme when sending client ID and password with a refresh token request. Recommended by the OAuth 2 standard, but may not be available with some issuers.';
$string['userfieldexternalfield'] = 'External field name';
$string['userfieldexternalfield_error'] = 'This field cannot contain HTML.';
$string['userfieldexternalfield_help'] = 'Name of the field provided by the external OAuth system.';
$string['userfieldinternalfield_help'] = 'Name of the Moodle user field that should be mapped from the external field.';
$string['userfieldinternalfield'] = 'Internal field name';
Expand Down
17 changes: 15 additions & 2 deletions lib/classes/oauth2/user_field_mapping.php
Expand Up @@ -26,7 +26,7 @@
defined('MOODLE_INTERNAL') || die();

use core\persistent;

use lang_string;
/**
* Class for loading/storing oauth2 user field mappings from the DB
*
Expand Down Expand Up @@ -57,7 +57,7 @@ protected static function define_properties() {
'type' => PARAM_INT
),
'externalfield' => array(
'type' => PARAM_ALPHANUMEXT,
'type' => PARAM_RAW_TRIMMED,
),
'internalfield' => array(
'type' => PARAM_ALPHANUMEXT,
Expand All @@ -74,4 +74,17 @@ protected static function define_properties() {
public function get_internalfield_list() {
return array_combine(self::get_user_fields(), self::get_user_fields());
}

/**
* Ensures that no HTML is saved to externalfield field
* but preserves all special characters that can be a part of the claim
* @return boolean true if validation is successful, string error if externalfield is not validated
*/
protected function validate_externalfield($value){
// This parameter type is set to PARAM_RAW_TRIMMED and HTML check is done here.
if (clean_param($value, PARAM_NOTAGS) !== $value){
return new lang_string('userfieldexternalfield_error', 'tool_oauth2');
}
return true;
}
}

0 comments on commit 8b58e05

Please sign in to comment.