From: Caolán McNamara Date: Fri, 3 Nov 2023 17:26:25 +0000 (+0000) Subject: [4/6] CVE-2023-6186 default to ignoring libreoffice special-purpose protocols in... X-Git-Tag: archive/raspbian/1%6.1.5-3+rpi1+deb10u11^2~8 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=2d3cf6637149e0ba226973edffa48e5890366eca;p=libreoffice.git [4/6] CVE-2023-6186 default to ignoring libreoffice special-purpose protocols in calc hyperlink Change-Id: Ib9f62be3acc05f24ca234dec0fec21e24579e9de Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158911 Tested-by: Jenkins Tested-by: Caolán McNamara Reviewed-by: Caolán McNamara (cherry picked from commit b6062623b4d69c79e90e9365ac7c5e7f11986793) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159045 Reviewed-by: Eike Rathke (cherry picked from commit 672716d09c54cb6fdd59baa7da4b8393cf104cd2) origin: https://github.com/LibreOffice/core/commit/09833101c989ead8dc751a611a27489ed2f1bcf1.patch Gbp-Pq: Name 0090-4-6-CVE-2023-6186-default-to-ignoring-libreoffice-sp.patch --- diff --git a/dbaccess/source/core/dataaccess/ModelImpl.cxx b/dbaccess/source/core/dataaccess/ModelImpl.cxx index 3281d0dd2b7..ff5b4f61258 100644 --- a/dbaccess/source/core/dataaccess/ModelImpl.cxx +++ b/dbaccess/source/core/dataaccess/ModelImpl.cxx @@ -1056,7 +1056,8 @@ bool ODatabaseModelImpl::checkMacrosOnLoading() { Reference< XInteractionHandler > xInteraction; xInteraction = m_aMediaDescriptor.getOrDefault( "InteractionHandler", xInteraction ); - return m_aMacroMode.checkMacrosOnLoading( xInteraction ); + const bool bHasMacros = m_aMacroMode.hasMacros(); + return m_aMacroMode.checkMacrosOnLoading(xInteraction, false /*HasValidContentSignature*/, bHasMacros); } void ODatabaseModelImpl::resetMacroExecutionMode() diff --git a/include/sfx2/docmacromode.hxx b/include/sfx2/docmacromode.hxx index 19199f7a410..4b2a1d0e10e 100644 --- a/include/sfx2/docmacromode.hxx +++ b/include/sfx2/docmacromode.hxx @@ -259,6 +259,8 @@ namespace sfx2 */ static bool storageHasMacros( const css::uno::Reference< css::embed::XStorage >& _rxStorage ); + bool hasMacros() const; + static bool containerHasBasicMacros( const css::uno::Reference< css::script::XLibraryContainer >& xContainter ); /** checks the macro execution mode while loading the document. @@ -286,7 +288,7 @@ namespace sfx2 bool checkMacrosOnLoading( const css::uno::Reference< css::task::XInteractionHandler >& _rxInteraction, - bool bHasValidContentSignature = false + bool bHasValidContentSignature, bool bHasMacros ); private: diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx index 83033e57ed7..b8bc6a734c5 100644 --- a/include/sfx2/objsh.hxx +++ b/include/sfx2/objsh.hxx @@ -429,6 +429,9 @@ public: void SetMacroCallsSeenWhileLoading(); bool GetMacroCallsSeenWhileLoading() const; + // true if the document had macros (or similar) on load to trigger warning user + bool GetHadCheckedMacrosOnLoad() const; + const css::uno::Sequence< css::beans::PropertyValue >& GetModifyPasswordInfo() const; bool SetModifyPasswordInfo( const css::uno::Sequence< css::beans::PropertyValue >& aInfo ); diff --git a/include/sfx2/strings.hrc b/include/sfx2/strings.hrc index 6861775db09..188b4b4b604 100644 --- a/include/sfx2/strings.hrc +++ b/include/sfx2/strings.hrc @@ -103,6 +103,7 @@ #define STR_GB NC_("STR_GB", "GB") #define STR_QUERY_LASTVERSION NC_("STR_QUERY_LASTVERSION", "Cancel all changes?") #define STR_NO_WEBBROWSER_FOUND NC_("STR_NO_WEBBROWSER_FOUND", "Opening \"$(ARG1)\" failed with error code $(ARG2) and message: \"$(ARG3)\"\nMaybe no web browser could be found on your system. In that case, please check your Desktop Preferences or install a web browser (for example, Firefox) in the default location requested during the browser installation.") +#define STR_DANGEROUS_TO_OPEN NC_("STR_DANGEROUS_TO_OPEN", "It might be dangerous to open \"$(ARG1)\".\nDo you really want to open it?") #define STR_NO_ABS_URI_REF NC_("STR_NO_ABS_URI_REF", "\"$(ARG1)\" is not an absolute URL that can be passed to an external application to open it.") #define STR_GID_INTERN NC_("STR_GID_INTERN", "Internal") #define STR_GID_APPLICATION NC_("STR_GID_APPLICATION", "Application") diff --git a/sc/source/core/data/global.cxx b/sc/source/core/data/global.cxx index 2a4f14a8b75..dd66a821276 100644 --- a/sc/source/core/data/global.cxx +++ b/sc/source/core/data/global.cxx @@ -28,6 +28,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -37,6 +40,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -812,7 +818,7 @@ void ScGlobal::OpenURL(const OUString& rURL, const OUString& rTarget) OUString aUrlName( rURL ); SfxViewFrame* pFrame = nullptr; - const SfxObjectShell* pObjShell = nullptr; + SfxObjectShell* pObjShell = nullptr; OUString aReferName; if ( pScActiveViewShell ) { @@ -839,6 +845,35 @@ void ScGlobal::OpenURL(const OUString& rURL, const OUString& rTarget) aUrlName = aNewUrlName; } + if (INetURLObject(aUrlName).IsExoticProtocol()) + { + // Default to ignoring exotic protocols + bool bAllow = false; + if (pObjShell) + { + // If the document had macros when loaded then follow the allowed macro-mode + if (pObjShell->GetHadCheckedMacrosOnLoad()) + bAllow = pObjShell->AdjustMacroMode(); + else // otherwise ask the user, defaulting to cancel + { + assert(pFrame && "if we have pObjShell we have pFrame"); + //Reuse URITools::onOpenURI warning string + std::unique_ptr xQueryBox(Application::CreateMessageDialog(pFrame->GetWindow().GetFrameWeld(), + VclMessageType::Warning, VclButtonsType::YesNo, + SfxResId(STR_DANGEROUS_TO_OPEN))); + xQueryBox->set_primary_text(xQueryBox->get_primary_text().replaceFirst("$(ARG1)", + INetURLObject::decode(aUrlName, INetURLObject::DecodeMechanism::Unambiguous))); + xQueryBox->set_default_response(RET_NO); + bAllow = xQueryBox->run() == RET_YES; + } + } + if (!bAllow) + { + SAL_WARN("sc", "ScGlobal::OpenURL ignoring: " << aUrlName); + return; + } + } + SfxStringItem aUrl( SID_FILE_NAME, aUrlName ); SfxStringItem aTarget( SID_TARGETNAME, rTarget ); if ( nScClickMouseModifier & KEY_SHIFT ) // control-click -> into new window diff --git a/sfx2/source/doc/docmacromode.cxx b/sfx2/source/doc/docmacromode.cxx index 6279aa235b0..a663fbeb43e 100644 --- a/sfx2/source/doc/docmacromode.cxx +++ b/sfx2/source/doc/docmacromode.cxx @@ -399,8 +399,12 @@ namespace sfx2 return bHasMacros; } + bool DocumentMacroMode::hasMacros() const + { + return m_xData->m_rDocumentAccess.documentStorageHasMacros() || hasMacroLibrary() || m_xData->m_rDocumentAccess.macroCallsSeenWhileLoading(); + } - bool DocumentMacroMode::checkMacrosOnLoading( const Reference< XInteractionHandler >& rxInteraction, bool bHasValidContentSignature ) + bool DocumentMacroMode::checkMacrosOnLoading( const Reference< XInteractionHandler >& rxInteraction, bool bHasValidContentSignature, bool bHasMacros ) { bool bAllow = false; if ( SvtSecurityOptions().IsMacroDisabled() ) @@ -410,7 +414,7 @@ namespace sfx2 } else { - if (m_xData->m_rDocumentAccess.documentStorageHasMacros() || hasMacroLibrary() || m_xData->m_rDocumentAccess.macroCallsSeenWhileLoading()) + if (bHasMacros) { if (m_xData->m_rDocumentAccess.macroCallsSeenWhileLoading()) m_bNeedsContentSigned = true; diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx index 273be873b3a..8155964f707 100644 --- a/sfx2/source/doc/objmisc.cxx +++ b/sfx2/source/doc/objmisc.cxx @@ -935,9 +935,15 @@ void SfxObjectShell::CheckSecurityOnLoading_Impl() // check macro security const bool bHasValidContentSignature = HasValidSignatures(); - pImpl->aMacroMode.checkMacrosOnLoading( xInteraction, bHasValidContentSignature ); + const bool bHasMacros = pImpl->aMacroMode.hasMacros(); + pImpl->aMacroMode.checkMacrosOnLoading( xInteraction, bHasValidContentSignature, bHasMacros ); + pImpl->m_bHadCheckedMacrosOnLoad = bHasMacros; } +bool SfxObjectShell::GetHadCheckedMacrosOnLoad() const +{ + return pImpl->m_bHadCheckedMacrosOnLoad; +} void SfxObjectShell::CheckEncryption_Impl( const uno::Reference< task::XInteractionHandler >& xHandler ) { diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx index b3309bae2d8..3b74b57fec9 100644 --- a/sfx2/source/doc/objxtor.cxx +++ b/sfx2/source/doc/objxtor.cxx @@ -231,6 +231,7 @@ SfxObjectShell_Impl::SfxObjectShell_Impl( SfxObjectShell& _rDocShell ) ,m_bAllowShareControlFileClean( true ) ,m_bConfigOptionsChecked( false ) ,m_bMacroCallsSeenWhileLoading( false ) + ,m_bHadCheckedMacrosOnLoad( false ) ,lErr(ERRCODE_NONE) ,nEventId ( SfxEventHintId::NONE ) ,pReloadTimer ( nullptr) diff --git a/sfx2/source/inc/objshimp.hxx b/sfx2/source/inc/objshimp.hxx index 0b403e071d5..791de71b005 100644 --- a/sfx2/source/inc/objshimp.hxx +++ b/sfx2/source/inc/objshimp.hxx @@ -91,7 +91,8 @@ struct SfxObjectShell_Impl : public ::sfx2::IMacroDocumentAccess m_bSharedXMLFlag:1, // whether the document should be edited in shared mode m_bAllowShareControlFileClean:1, // whether the flag should be stored in xml file m_bConfigOptionsChecked:1, // whether or not the user options are checked after the Options dialog is closed. - m_bMacroCallsSeenWhileLoading:1; // whether or not the user options are checked after the Options dialog is closed. + m_bMacroCallsSeenWhileLoading:1, // whether or not macro calls were seen when loading document. + m_bHadCheckedMacrosOnLoad:1; // if document contained macros (or calls) when loaded IndexBitSet aBitSet; ErrCode lErr;