|
6 | 6 | */ |
7 | 7 |
|
8 | 8 | use Drupal\block\Entity\Block; |
| 9 | +use Drupal\Component\Utility\Html; |
| 10 | +use Drupal\Component\Utility\UrlHelper; |
9 | 11 | use Drupal\Component\Utility\Xss; |
10 | 12 | use Drupal\Core\Access\AccessResult; |
11 | 13 | use Drupal\Core\Cache\Cache; |
@@ -202,7 +204,12 @@ function oit_form_alter(&$form, FormStateInterface $form_state, $form_id) { |
202 | 204 | $query['field_domain_access_target_id'] = 'oit_colorado_edu'; |
203 | 205 | $query = http_build_query($query); |
204 | 206 | $response = new RedirectResponse('/admin/content?' . $query); |
| 207 | + // @todo (C1): Calling send() inside hook_form_alter() bypasses the Symfony |
| 208 | + // kernel response pipeline. The proper fix is to convert this to a |
| 209 | + // #submit handler or KernelEvents::RESPONSE subscriber. Until then, |
| 210 | + // return immediately after send() so no further form-build code runs. |
205 | 211 | $response->send(); |
| 212 | + return; |
206 | 213 | } |
207 | 214 | } |
208 | 215 | } |
@@ -406,18 +413,18 @@ function oit_form_alter(&$form, FormStateInterface $form_state, $form_id) { |
406 | 413 | if (!$show_login_form) { |
407 | 414 | // Cache is breaking the redirect, so kill it. |
408 | 415 | \Drupal::service('page_cache_kill_switch')->trigger(); |
409 | | - $dest_get = \Drupal::request()->get('dest') != NULL ? Xss::filter(\Drupal::request()->get('dest')) : ''; |
410 | | - $destination_get = \Drupal::request()->get('destination') != NULL ? Xss::filter(\Drupal::request()->get('destination')) : ''; |
411 | | - $destination = ""; |
412 | | - if (!empty($dest_get)) { |
413 | | - $destination = '?destination=' . preg_replace('/https:\/\/[^\/]+/', '', $dest_get); |
| 416 | + $dest_get = \Drupal::request()->get('dest') ?? ''; |
| 417 | + $destination_get = \Drupal::request()->get('destination') ?? ''; |
| 418 | + $destination = ''; |
| 419 | + if (!empty($dest_get) && !UrlHelper::isExternal($dest_get)) { |
| 420 | + $destination = '?destination=' . Xss::filter($dest_get); |
414 | 421 | } |
415 | | - if (!empty($destination_get)) { |
416 | | - $destination = '?destination=' . preg_replace('/https:\/\/[^\/]+/', '', $destination_get); |
| 422 | + if (!empty($destination_get) && !UrlHelper::isExternal($destination_get)) { |
| 423 | + $destination = '?destination=' . Xss::filter($destination_get); |
417 | 424 | } |
418 | 425 | // Drupal 10 add log message with $destination. |
419 | 426 | \Drupal::logger('oit')->notice('User login form redirecting to saml_login with destination: @destination', ['@destination' => $destination]); |
420 | | - $response = new RedirectResponse('/saml_login' . $destination, 301); |
| 427 | + $response = new RedirectResponse('/saml_login' . $destination, 302); |
421 | 428 | $response->send(); |
422 | 429 | unset($form['name']); |
423 | 430 | unset($form['pass']); |
@@ -487,7 +494,12 @@ function _oit_form_set_domain($page, $field_domain) { |
487 | 494 | $query['field_domain_access_target_id'] = $field_domain; |
488 | 495 | $query = http_build_query($query); |
489 | 496 | $response = new RedirectResponse('/admin/' . $page . '?' . $query); |
| 497 | + // @todo (C1): Calling send() inside hook_form_alter() bypasses the Symfony |
| 498 | + // kernel response pipeline. The proper fix is to convert this to a |
| 499 | + // #submit handler or KernelEvents::RESPONSE subscriber. Until then, |
| 500 | + // return immediately after send() so no further form-build code runs. |
490 | 501 | $response->send(); |
| 502 | + return; |
491 | 503 | } |
492 | 504 | } |
493 | 505 |
|
@@ -716,7 +728,7 @@ function oit_tokens($type, $tokens, array $data, array $options, BubbleableMetad |
716 | 728 | } |
717 | 729 | } |
718 | 730 | } |
719 | | - $replacements[$original] = $user_name; |
| 731 | + $replacements[$original] = Html::escape($user_name); |
720 | 732 | break; |
721 | 733 |
|
722 | 734 | case 'tweet_pic': |
@@ -878,7 +890,7 @@ function oit_responsive_menu_off_canvas_tree_alter(array &$rendered_tree) { |
878 | 890 | * Create social link. |
879 | 891 | */ |
880 | 892 | function oit_social_links($title, $url) { |
881 | | - return "<a class='social-icon $title' title='$title' href='$url'><img alt='' src='/themes/custom/dingo/images/icons/$title.svg'></a>"; |
| 893 | + return "<a class='social-icon " . Html::escape($title) . "' title='" . Html::escape($title) . "' href='" . Html::escape($url) . "'><img alt='' src='/themes/custom/dingo/images/icons/" . Html::escape($title) . ".svg'></a>"; |
882 | 894 | } |
883 | 895 |
|
884 | 896 | /** |
|
0 commit comments