Skip to content

Commit 3191624

Browse files
committed
5189: Added check for absolute and secure URLs in MeMo actions
1 parent 0943c5c commit 3191624

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

modules/os2forms_digital_post/src/Plugin/WebformHandler/WebformHandlerSF1601.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Drupal\os2forms_digital_post\Plugin\WebformHandler;
44

5+
use Drupal\Component\Utility\UrlHelper;
56
use Drupal\Core\Form\FormStateInterface;
67
use Drupal\os2forms_digital_post\Helper\WebformHelperSF1601;
78
use Drupal\webform\Plugin\WebformHandlerBase;
@@ -270,10 +271,31 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form
270271
self::MEMO_ACTIONS . '][actions][' . $index . '][url',
271272
$this->t('Url for action %action is required.', [
272273
'%action' => $this->getTranslatedActionName($action['action']),
273-
'%url' => $action['url'] ?? '',
274274
])
275275
);
276276
}
277+
else {
278+
$url = $action['url'];
279+
// URL must be absolute and use https (cf. https://digitaliser.dk/digital-post/nyhedsarkiv/2024/nov/oeget-validering-i-digital-post)
280+
if (!UrlHelper::isValid($url, absolute: TRUE)) {
281+
$formState->setErrorByName(
282+
self::MEMO_ACTIONS . '][actions][' . $index . '][url',
283+
$this->t('Url <code>@url</code> for action %action must be absolute, i.e. start with <code>https://</code>.', [
284+
'@url' => $url,
285+
'%action' => $this->getTranslatedActionName($action['action']),
286+
])
287+
);
288+
}
289+
elseif ('https' !== parse_url($url, PHP_URL_SCHEME)) {
290+
$formState->setErrorByName(
291+
self::MEMO_ACTIONS . '][actions][' . $index . '][url',
292+
$this->t('Url <code>@url</code> for action %action must use the <code>https</code> scheme, i.e. start with <code>https://</code>.', [
293+
'@url' => $url,
294+
'%action' => $this->getTranslatedActionName($action['action']),
295+
])
296+
);
297+
}
298+
}
277299
if (isset($definedActions[$action['action']])) {
278300
$formState->setErrorByName(
279301
self::MEMO_ACTIONS . '][actions][' . $index . '][action',

0 commit comments

Comments
 (0)