forms/source/component/ImageControl.cxx | 1 + forms/source/component/clickableimage.cxx | 9 +++++++-- include/toolkit/controls/unocontrols.hxx | 2 +- include/toolkit/helper/property.hxx | 1 + sfx2/source/appl/linkmgr2.cxx | 13 ------------- sw/source/filter/html/htmlgrin.cxx | 15 ++++++++++++++- toolkit/source/awt/vclxwindows.cxx | 1 + toolkit/source/controls/dialogcontrol.cxx | 4 ++-- toolkit/source/controls/unocontrols.cxx | 12 +++++++++--- toolkit/source/helper/property.cxx | 3 ++- vcl/source/filter/graphicfilter.cxx | 4 ++-- xmloff/source/forms/elementimport.cxx | 9 +++++++++ xmlsecurity/qa/unit/signing/signing.cxx | 1 - 13 files changed, 49 insertions(+), 26 deletions(-)
New commits: commit 1bf4e6cdc7d5e7a2c6544dd4d68e84a51314fdf4 Author: Thorsten Behrens <thorsten.behr...@allotropia.de> AuthorDate: Wed Jan 15 14:30:38 2025 +0100 Commit: Thorsten Behrens <thorsten.behr...@allotropia.de> CommitDate: Wed Jan 15 14:40:02 2025 +0100 Fixup "consider VndSunStarExpand an exotic protocol" Change-Id: Ib4d1647e69965783354f30d199661f88ac9315a6 diff --git a/forms/source/component/ImageControl.cxx b/forms/source/component/ImageControl.cxx index f0af0d8ae3c5..3b03efd59827 100644 --- a/forms/source/component/ImageControl.cxx +++ b/forms/source/component/ImageControl.cxx @@ -52,6 +52,7 @@ #include <comphelper/guarding.hxx> #include <comphelper/processfactory.hxx> #include <unotools/ucbstreamhelper.hxx> +#include <unotools/securityoptions.hxx> #include <svl/urihelper.hxx> #include <memory> diff --git a/sfx2/source/appl/linkmgr2.cxx b/sfx2/source/appl/linkmgr2.cxx index 701074bb9beb..878bf817089d 100644 --- a/sfx2/source/appl/linkmgr2.cxx +++ b/sfx2/source/appl/linkmgr2.cxx @@ -496,19 +496,6 @@ bool LinkManager::GetGraphicFromAny( const OUString& rMimeType, bool bRet = false; css::uno::Sequence< sal_Int8 > aSeq; if( rValue.hasValue() && ( rValue >>= aSeq ) ) - { - OUString sURL = rValue.get<OUString>(); - if (!SvtSecurityOptions().isUntrustedReferer(rReferer) && - !INetURLObject(sURL).IsExoticProtocol()) - { - rGraphic = vcl::graphic::loadFromURL(sURL, pParentWin); - } - if (rGraphic.IsNone()) - rGraphic.SetDefaultType(); - rGraphic.setOriginURL(sURL); - return true; - } - else if (rValue.has<css::uno::Sequence<sal_Int8>>()) { auto aSeq = rValue.get<css::uno::Sequence<sal_Int8>>(); diff --git a/sw/source/filter/html/htmlgrin.cxx b/sw/source/filter/html/htmlgrin.cxx index 5965e6a856e8..93e61797a1e9 100644 --- a/sw/source/filter/html/htmlgrin.cxx +++ b/sw/source/filter/html/htmlgrin.cxx @@ -42,6 +42,7 @@ #include <svtools/htmltokn.h> #include <svtools/htmlkywd.hxx> #include <unotools/eventcfg.hxx> +#include <unotools/securityoptions.hxx> #include <fmtornt.hxx> #include <fmturl.hxx> @@ -292,7 +293,19 @@ void SwHTMLParser::GetDefaultScriptType( ScriptType& rType, rTypeStr = GetScriptTypeString( pHeaderAttrs ); } -/* */ +namespace +{ + bool allowAccessLink(const SwDoc& rDoc) + { + OUString sReferer; + SfxObjectShell * sh = rDoc.GetPersist(); + if (sh != nullptr && sh->HasName()) + { + sReferer = sh->GetMedium()->GetName(); + } + return !SvtSecurityOptions().isUntrustedReferer(sReferer); + } +} void SwHTMLParser::InsertImage() { diff --git a/toolkit/source/controls/unocontrols.cxx b/toolkit/source/controls/unocontrols.cxx index 54d67adc6f3b..2a7a1fcde964 100644 --- a/toolkit/source/controls/unocontrols.cxx +++ b/toolkit/source/controls/unocontrols.cxx @@ -59,6 +59,7 @@ #include <tools/diagnose_ex.h> #include <tools/date.hxx> #include <tools/time.hxx> +#include <unotools/securityoptions.hxx> #include <algorithm> #include <functional> diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx index de0da60b7573..e46dd1474932 100644 --- a/vcl/source/filter/graphicfilter.cxx +++ b/vcl/source/filter/graphicfilter.cxx @@ -1304,10 +1304,10 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const INetURLObject& if (rPath.IsExoticProtocol()) { SAL_WARN("vcl.filter", "GraphicFilter::ImportGraphic(), ignore exotic protocol: " << aMainUrl); - return ERRCODE_GRFILTER_FORMATERROR; + return GRFILTER_FORMATERROR; } - ErrCode nRetValue = ERRCODE_GRFILTER_FORMATERROR; + ErrCode nRetValue = GRFILTER_FORMATERROR; std::unique_ptr<SvStream> xStream(::utl::UcbStreamHelper::CreateStream( aMainUrl, StreamMode::READ | StreamMode::SHARE_DENYNONE )); if (xStream) { diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx index ff9c6a325ab0..9716d67b58ea 100644 --- a/xmlsecurity/qa/unit/signing/signing.cxx +++ b/xmlsecurity/qa/unit/signing/signing.cxx @@ -58,7 +58,6 @@ #include <ucbhelper/interceptedinteraction.hxx> #include <sfx2/docfile.hxx> #include <sfx2/docfilt.hxx> -#include <officecfg/Office/Common.hxx> #include <comphelper/configuration.hxx> using namespace com::sun::star; commit e70aa314d4765f61e0f17e329690e5eaafdaa101 Author: Stephan Bergmann <stephan.bergm...@allotropia.de> AuthorDate: Tue Jun 11 14:15:47 2024 +0200 Commit: Thorsten Behrens <thorsten.behr...@allotropia.de> CommitDate: Wed Jan 15 14:40:02 2025 +0100 Some missing "block untrusted referer links" for form controls ...where "Referer" is now passed in as an additional property, so that the relevant objects can decide whether to obtain graphics while loading a document Change-Id: Ie3dabc574861713212b906a0d7793f438a7d50a8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168674 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de> (cherry picked from commit dc01a6e7efd3e4c41287dc10c7ea1fdfa1ab5cb5) diff --git a/forms/source/component/clickableimage.cxx b/forms/source/component/clickableimage.cxx index 89c0b199a0b1..5c750ffd0efa 100644 --- a/forms/source/component/clickableimage.cxx +++ b/forms/source/component/clickableimage.cxx @@ -45,6 +45,7 @@ #include <comphelper/listenernotification.hxx> #include <comphelper/processfactory.hxx> #include <svtools/imageresourceaccess.hxx> +#include <unotools/securityoptions.hxx> #define LOCAL_URL_PREFIX '#' @@ -786,8 +787,12 @@ namespace frm m_bDownloading = true; m_bProdStarted = false; - // Kick off download (caution: can be synchronous). - m_pMedium->Download(LINK(this, OClickableImageBaseModel, DownloadDoneLink)); + OUString referer; + getPropertyValue("Referer") >>= referer; + if (!SvtSecurityOptions().isUntrustedReferer(referer)) { + // Kick off download (caution: can be synchronous). + m_pMedium->Download(LINK(this, OClickableImageBaseModel, DownloadDoneLink)); + } } else { diff --git a/include/toolkit/controls/unocontrols.hxx b/include/toolkit/controls/unocontrols.hxx index 54082d8324b6..03dc6bbaadb3 100644 --- a/include/toolkit/controls/unocontrols.hxx +++ b/include/toolkit/controls/unocontrols.hxx @@ -71,7 +71,7 @@ public: // appropriately ( e.g. NULL if non GraphicObject scheme ) or a valid // object if the rURL points to a valid object static css::uno::Reference< css::graphic::XGraphic > getGraphicAndGraphicObjectFromURL_nothrow( css::uno::Reference< css::graphic::XGraphicObject >& xOutGraphicObject, const OUString& _rURL ); - static css::uno::Reference< css::graphic::XGraphic > getGraphicFromURL_nothrow( const OUString& _rURL ); + static css::uno::Reference< css::graphic::XGraphic > getGraphicFromURL_nothrow( const OUString& _rURL, OUString const & referer ); }; diff --git a/include/toolkit/helper/property.hxx b/include/toolkit/helper/property.hxx index 34d8918e9573..7eec86928d17 100644 --- a/include/toolkit/helper/property.hxx +++ b/include/toolkit/helper/property.hxx @@ -208,6 +208,7 @@ namespace uno { #define BASEPROPERTY_ACTIVE_SEL_TEXT_COLOR 167 #define BASEPROPERTY_INACTIVE_SEL_TEXT_COLOR 168 #define BASEPROPERTY_TYPEDITEMLIST 169 // AnySequence +#define BASEPROPERTY_REFERER 172 // These properties are not bound, they are always extracted from the BASEPROPERTY_FONTDESCRIPTOR property diff --git a/toolkit/source/awt/vclxwindows.cxx b/toolkit/source/awt/vclxwindows.cxx index f7e2270aacef..36201413ec49 100644 --- a/toolkit/source/awt/vclxwindows.cxx +++ b/toolkit/source/awt/vclxwindows.cxx @@ -207,6 +207,7 @@ namespace toolkit void VCLXGraphicControl::ImplGetPropertyIds( std::vector< sal_uInt16 > &rIds ) { + PushPropertyIds(rIds, BASEPROPERTY_REFERER, 0); VCLXWindow::ImplGetPropertyIds( rIds ); } diff --git a/toolkit/source/controls/dialogcontrol.cxx b/toolkit/source/controls/dialogcontrol.cxx index 6861e8732ecf..4e3f535cfb16 100644 --- a/toolkit/source/controls/dialogcontrol.cxx +++ b/toolkit/source/controls/dialogcontrol.cxx @@ -424,7 +424,7 @@ void UnoDialogControl::PrepareWindowDescriptor( css::awt::WindowDescriptor& rDes absoluteUrl = getPhysicalLocation( ImplGetPropertyValue( PROPERTY_DIALOGSOURCEURL ), uno::makeAny( aImageURL ) ); - xGraphic = ImageHelper::getGraphicFromURL_nothrow( absoluteUrl ); + xGraphic = ImageHelper::getGraphicFromURL_nothrow( absoluteUrl, "" ); ImplSetPropertyValue( PROPERTY_GRAPHIC, uno::makeAny( xGraphic ), true ); } } @@ -648,7 +648,7 @@ void UnoDialogControl::ImplModelPropertiesChanged( const Sequence< PropertyChang absoluteUrl = getPhysicalLocation( ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_DIALOGSOURCEURL )), uno::makeAny(aImageURL)); - xGraphic = ImageHelper::getGraphicFromURL_nothrow( absoluteUrl ); + xGraphic = ImageHelper::getGraphicFromURL_nothrow( absoluteUrl, "" ); } ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_GRAPHIC), uno::makeAny( xGraphic ), true ); break; diff --git a/toolkit/source/controls/unocontrols.cxx b/toolkit/source/controls/unocontrols.cxx index 03621c16e54a..54d67adc6f3b 100644 --- a/toolkit/source/controls/unocontrols.cxx +++ b/toolkit/source/controls/unocontrols.cxx @@ -40,6 +40,7 @@ #include <toolkit/helper/servicenames.hxx> #include <tools/urlobj.hxx> #include <toolkit/helper/macros.hxx> +#include <unotools/securityoptions.hxx> // for introspection #include <toolkit/awt/vclxwindows.hxx> @@ -85,11 +86,11 @@ ImageHelper::getGraphicAndGraphicObjectFromURL_nothrow( uno::Reference< graphic: else // linked xOutGraphicObj = nullptr; // release the GraphicObject - return ImageHelper::getGraphicFromURL_nothrow( _rURL ); + return ImageHelper::getGraphicFromURL_nothrow( _rURL, "" ); } css::uno::Reference< css::graphic::XGraphic > -ImageHelper::getGraphicFromURL_nothrow( const OUString& _rURL ) +ImageHelper::getGraphicFromURL_nothrow( const OUString& _rURL, OUString const & referer ) { uno::Reference< graphic::XGraphic > xGraphic; if ( _rURL.isEmpty() || SvtSecurityOptions().isUntrustedReferer(referer) || INetURLObject(_rURL).IsExoticProtocol()) @@ -646,7 +647,11 @@ void SAL_CALL GraphicControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 n mbAdjustingGraphic = true; OUString sImageURL; OSL_VERIFY( rValue >>= sImageURL ); - setDependentFastPropertyValue( BASEPROPERTY_GRAPHIC, uno::makeAny( ImageHelper::getGraphicFromURL_nothrow( sImageURL ) ) ); + css::uno::Any any; + getFastPropertyValue(any, BASEPROPERTY_REFERER); + OUString referer; + any >>= referer; + setDependentFastPropertyValue( BASEPROPERTY_GRAPHIC, uno::makeAny( ImageHelper::getGraphicFromURL_nothrow( sImageURL, referer ) ) ); mbAdjustingGraphic = false; } break; diff --git a/toolkit/source/helper/property.cxx b/toolkit/source/helper/property.cxx index 790a2fdfea31..861df4f7794b 100644 --- a/toolkit/source/helper/property.cxx +++ b/toolkit/source/helper/property.cxx @@ -284,7 +284,8 @@ ImplPropertyInfo* ImplGetPropertyInfos( sal_uInt16& rElementCount ) DECL_PROP_3 ( "InactiveSelectionBackgroundColor", INACTIVE_SEL_BACKGROUND_COLOR, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID ), DECL_PROP_3 ( "ActiveSelectionTextColor", ACTIVE_SEL_TEXT_COLOR, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID ), DECL_PROP_3 ( "InactiveSelectionTextColor", INACTIVE_SEL_TEXT_COLOR, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID ), - }; + DECL_PROP_2("Referer", REFERER, OUString, BOUND, MAYBEVOID), + }; pPropertyInfos = aImplPropertyInfos; nElements = sizeof( aImplPropertyInfos ) / sizeof( ImplPropertyInfo ); } diff --git a/xmloff/source/forms/elementimport.cxx b/xmloff/source/forms/elementimport.cxx index 1bf17017d9c7..2b9cd7893ebb 100644 --- a/xmloff/source/forms/elementimport.cxx +++ b/xmloff/source/forms/elementimport.cxx @@ -620,6 +620,15 @@ namespace xmloff OSL_ENSURE(xPure.is(), OStringBuffer("OElementImport::createElement: service factory gave me no object (service name: ").append(OUStringToOString(m_sServiceName, RTL_TEXTENCODING_ASCII_US)).append(")!").getStr()); xReturn.set(xPure, UNO_QUERY); + if (auto const props = Reference<css::beans::XPropertySet>(xPure, css::uno::UNO_QUERY)) + { + try { + props->setPropertyValue( + "Referer", css::uno::Any(m_rFormImport.getGlobalContext().GetBaseURL())); + } catch (css::uno::Exception &) { + SAL_WARN("xmloff.forms", "setPropertyValue Referer failed"); + } + } } else OSL_FAIL("OElementImport::createElement: no service name to create an element!");