From 8aedcd05ab191394331e6f478d29637771805c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Tue, 1 Sep 2026 14:35:11 +0000 Subject: [PATCH] move isScriptURLAllowed onto SfxObjectShell MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit it was private to sfx2's eventsupplier.hxx, so nothing outside sfx2 could run the AllowedDocumentEventURLs test Change-Id: I814a965cafc245eb7b7f2d8fb18a81d1f7b7e50f Signed-off-by: Caolán McNamara Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/10920 Reviewed-by: Noel Grandin Tested-by: Jenkins CPCI (cherry picked from commit 4a5b2dd74b4e82b183961ca8f50d80bd485d5359) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/210591 Tested-by: Jenkins Reviewed-by: Xisco Fauli (cherry picked from commit 890f388a788264b186b9aef7d1ade1a51520f7b5) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/211800 --- include/sfx2/objsh.hxx | 3 +++ sfx2/source/doc/objmisc.cxx | 29 +++++++++++++++++++++++++++ sfx2/source/inc/eventsupplier.hxx | 4 ---- sfx2/source/notify/eventsupplier.cxx | 30 +--------------------------- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx index ae5f6a6fe5ef..63cfacb2850d 100644 --- a/include/sfx2/objsh.hxx +++ b/include/sfx2/objsh.hxx @@ -440,6 +440,9 @@ public: static bool UnTrustedScript(const OUString& rScriptURL); + /// Check if script URL whitelist exists, and if so, if current script url is part of it + static bool isScriptURLAllowed(const OUString& rScriptURL); + static bool isScriptAccessAllowed(const css::uno::Reference& rScriptContext); SvKeyValueIterator* GetHeaderAttributes(); diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx index 2ff1fca3bfde..b553738ef966 100644 --- a/sfx2/source/doc/objmisc.cxx +++ b/sfx2/source/doc/objmisc.cxx @@ -84,6 +84,10 @@ #include #include +#include +#include +#include + #include #include #include @@ -1458,6 +1462,31 @@ ErrCode SfxObjectShell::CallBasic( std::u16string_view rMacro, return nRet; } +bool SfxObjectShell::isScriptURLAllowed(const OUString& rScriptURL) +{ + std::optional> allowedEvents( + officecfg::Office::Common::Security::Scripting::AllowedDocumentEventURLs::get()); + // When AllowedDocumentEventURLs is empty, all event URLs are allowed + if (!allowedEvents) + return true; + + icu::ErrorCode status; + const uint32_t rMatcherFlags = UREGEX_CASE_INSENSITIVE; + icu::UnicodeString usInput(rScriptURL.getStr()); + const uno::Sequence& rAllowedEvents = *allowedEvents; + for (auto const& allowedEvent : rAllowedEvents) + { + icu::UnicodeString usRegex(allowedEvent.getStr()); + icu::RegexMatcher rmatch1(usRegex, usInput, rMatcherFlags, status); + if (rScriptURL.startsWith(allowedEvent) || rmatch1.matches(status)) + { + return true; + } + } + + return false; +} + bool SfxObjectShell::isScriptAccessAllowed( const Reference< XInterface >& _rxScriptContext ) { try diff --git a/sfx2/source/inc/eventsupplier.hxx b/sfx2/source/inc/eventsupplier.hxx index 56aa8f95e75f..f552c1fa043e 100644 --- a/sfx2/source/inc/eventsupplier.hxx +++ b/sfx2/source/inc/eventsupplier.hxx @@ -80,10 +80,6 @@ public: ::comphelper::NamedValueCollection& o_normalizedDescriptor, SfxObjectShell* i_document ); static void Execute( css::uno::Sequence < css::beans::PropertyValue > const & aEventData, const css::document::DocumentEvent& aTrigger, SfxObjectShell* pDoc ); - -private: - /// Check if script URL whitelist exists, and if so, if current script url is part of it - static bool isScriptURLAllowed(const OUString& aScriptURL); }; #endif diff --git a/sfx2/source/notify/eventsupplier.cxx b/sfx2/source/notify/eventsupplier.cxx index be47bed36cfb..102621242dc6 100644 --- a/sfx2/source/notify/eventsupplier.cxx +++ b/sfx2/source/notify/eventsupplier.cxx @@ -43,9 +43,6 @@ #include #include -#include -#include -#include using namespace css; using namespace ::com::sun::star; @@ -155,31 +152,6 @@ sal_Bool SAL_CALL SfxEvents_Impl::hasElements() return maEventNames.hasElements(); } -bool SfxEvents_Impl::isScriptURLAllowed(const OUString& aScriptURL) -{ - std::optional> allowedEvents( - officecfg::Office::Common::Security::Scripting::AllowedDocumentEventURLs::get()); - // When AllowedDocumentEventURLs is empty, all event URLs are allowed - if (!allowedEvents) - return true; - - icu::ErrorCode status; - const uint32_t rMatcherFlags = UREGEX_CASE_INSENSITIVE; - icu::UnicodeString usInput(aScriptURL.getStr()); - const css::uno::Sequence& rAllowedEvents = *allowedEvents; - for (auto const& allowedEvent : rAllowedEvents) - { - icu::UnicodeString usRegex(allowedEvent.getStr()); - icu::RegexMatcher rmatch1(usRegex, usInput, rMatcherFlags, status); - if (aScriptURL.startsWith(allowedEvent) || rmatch1.matches(status)) - { - return true; - } - } - - return false; -} - void SfxEvents_Impl::Execute( css::uno::Sequence < css::beans::PropertyValue > const & aProperties, const document::DocumentEvent& aTrigger, SfxObjectShell* pDoc ) { OUString aType; @@ -214,7 +186,7 @@ void SfxEvents_Impl::Execute( css::uno::Sequence < css::beans::PropertyValue > c if (aScript.isEmpty()) return; - if (!isScriptURLAllowed(aScript)) + if (!SfxObjectShell::isScriptURLAllowed(aScript)) return; if (!pDoc)