diff --git a/main/auth/openid/login.php b/main/auth/openid/login.php index f3cda60ac6..3fa1359379 100755 --- a/main/auth/openid/login.php +++ b/main/auth/openid/login.php @@ -14,7 +14,7 @@ require_once 'openid.lib.php'; require_once 'xrds.lib.php'; -function openid_form() +function openid_form(): FormValidator { $form = new FormValidator( 'openid_login', @@ -25,8 +25,10 @@ function openid_form() ); $form -> addElement('text', 'openid_url', array(get_lang('OpenIDURL'), Display::url(get_lang('OpenIDWhatIs'), 'main/auth/openid/whatis.php')), array('class' => 'openid_input')); $form -> addElement('button', 'submit', get_lang('Login')); + $form->applyFilter('openid_url', 'trim'); + $form->protect(); - return $form->returnForm(); + return $form; } /** @@ -459,3 +461,30 @@ function openid_http_request($url, $headers = array(), $method = 'GET', $data = $result->code = $code; return $result; } + +function openid_is_allowed_provider($identityUrl): bool +{ + $allowedProviders = api_get_configuration_value('auth_openid_allowed_providers'); + + if (false === $allowedProviders) { + return true; + } + + $host = parse_url($identityUrl, PHP_URL_HOST) ?: $identityUrl; + + foreach ($allowedProviders as $provider) { + if (strpos($provider, '*') !== false) { + $regex = '/^' . str_replace('\*', '.*', preg_quote($provider, '/')) . '$/'; + + if (preg_match($regex, $host)) { + return true; + } + } else { + if ($host === $provider) { + return true; + } + } + } + + return false; +} diff --git a/main/inc/lib/formvalidator/FormValidator.class.php b/main/inc/lib/formvalidator/FormValidator.class.php index 33221be733..3224a7dc7a 100755 --- a/main/inc/lib/formvalidator/FormValidator.class.php +++ b/main/inc/lib/formvalidator/FormValidator.class.php @@ -1106,6 +1106,7 @@ EOT; $this->addElement('html_editor', $name, $label, $attributes, $config); $this->applyFilter($name, 'trim'); + $this->applyFilter($name, 'attr_on_filter'); if ($required) { $this->addRule($name, get_lang('ThisFieldIsRequired'), 'required'); } @@ -2097,3 +2098,15 @@ function plain_url_filter($html, $mode = NO_HTML) return kses_split($html, $allowed_html_fixed, ['http', 'https']); } + +/** + * Prevent execution of event handlers in HTML elements. + * + * @param string $html + * @return string + */ +function attr_on_filter($html) { + $prefix = uniqid('data-cke-').'-'; + + return preg_replace('/(\s)(on)/i', '$1'.$prefix.'$2', $html); +} diff --git a/main/inc/lib/template.lib.php b/main/inc/lib/template.lib.php index 83121e6796..f6c1fc3587 100755 --- a/main/inc/lib/template.lib.php +++ b/main/inc/lib/template.lib.php @@ -1318,7 +1318,7 @@ class Template $html = $form->returnForm(); if (api_get_setting('openid_authentication') == 'true') { include_once api_get_path(SYS_CODE_PATH).'auth/openid/login.php'; - $html .= '