From 1f82fb3f7ff6373df163edf7f2e9feff5c4b4a2c Mon Sep 17 00:00:00 2001 From: Dylan Wagstaff Date: Fri, 25 Oct 2024 02:56:16 +1300 Subject: [PATCH] NEW Allow silverstripe/errorpage to static publish When using the error page module to create custom content error pages within the CMS (for e.g. HTTP 404 & 500) the default is to also static publish these files so the web server can reference them directly. This requires an unauthenticated execution of the controller in a mocked request in order to get all the page HTML without revealing any user based customised data that may be present. SAMLMiddleware will currently redirect this request to the IdP for authentication when enabled, essentially preventing error pages from being published, ever (in the default configuration). Hooks to customise the environment before dispatching the mocked request to the error page controller have recently been added to the ErrorPage, allowing us to disable the middleware & re-set it after the mock request completes. We can apply this via config only if the module exists. --- _config/errorpage.yml | 8 ++++++++ src/Extensions/ErrorPageStaticPublish.php | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 _config/errorpage.yml create mode 100644 src/Extensions/ErrorPageStaticPublish.php diff --git a/_config/errorpage.yml b/_config/errorpage.yml new file mode 100644 index 0000000..796ba0a --- /dev/null +++ b/_config/errorpage.yml @@ -0,0 +1,8 @@ +--- +Name: static-error-page +Only: + moduleexists: silverstripe/errorpage +--- +SilverStripe\ErrorPage\ErrorPage: + extensions: + - SilverStripe\SAML\Extensions\ErrorPageStaticPublish diff --git a/src/Extensions/ErrorPageStaticPublish.php b/src/Extensions/ErrorPageStaticPublish.php new file mode 100644 index 0000000..13ec53d --- /dev/null +++ b/src/Extensions/ErrorPageStaticPublish.php @@ -0,0 +1,23 @@ +originallyEnabled = $config->get('enabled'); + $config->set('enabled', false); + } + + public function onAfterStaticWrite() + { + SAMLMiddleware::config()->set('enabled', $this->originallyEnabled); + } +}