This is an automated email from the ASF dual-hosted git repository.

ardovm pushed a commit to branch AOO41X
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit 67269e9dfb82bb90e7db81f0d1937bdc876b076c
Author: Arrigo Marchiori <[email protected]>
AuthorDate: Tue Apr 8 23:08:23 2025 +0200

    Query our XLinkAuthorizer before calling 
com::sun::star::embed::XLinkCreator::createInstanceLink()
    
    (cherry picked and adapted from commit 
716c984a481da6f0eb6eb6ae9d80bd3ea6e0c5c4)
---
 .../source/container/embeddedobjectcontainer.cxx          | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/main/comphelper/source/container/embeddedobjectcontainer.cxx 
b/main/comphelper/source/container/embeddedobjectcontainer.cxx
index 70a053a9a9..3ee14dbf8e 100644
--- a/main/comphelper/source/container/embeddedobjectcontainer.cxx
+++ b/main/comphelper/source/container/embeddedobjectcontainer.cxx
@@ -25,6 +25,7 @@
 #include "precompiled_comphelper.hxx"
 #include <com/sun/star/container/XChild.hpp>
 #include <com/sun/star/container/XNameAccess.hpp>
+#include <com/sun/star/document/XLinkAuthorizer.hpp>
 #include <com/sun/star/embed/XEmbedObjectCreator.hpp>
 #include <com/sun/star/embed/XLinkCreator.hpp>
 #include <com/sun/star/embed/XEmbedPersist.hpp>
@@ -671,7 +672,19 @@ uno::Reference < embed::XEmbeddedObject > 
EmbeddedObjectContainer::InsertEmbedde
                 ::rtl::OUString( 
RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.EmbeddedObjectCreator")) ), 
uno::UNO_QUERY );
         uno::Sequence< beans::PropertyValue > aObjDescr( 1 );
         aObjDescr[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 
"Parent" ) );
-        aObjDescr[0].Value <<= pImpl->m_xModel.get();
+        uno::Any model( pImpl->m_xModel.get() );
+        aObjDescr[0].Value <<= model;
+        // The call to XLinkCreator::createInstanceLink() will open the link.
+        // We must request for authorization now. And we need the URL for that.
+        ::rtl::OUString aURL;
+        for ( sal_Int32 i = 0; i < aMedium.getLength(); i++ )
+            if ( aMedium[i].Name.equalsAscii( "URL" ) )
+                aMedium[i].Value >>= aURL;
+        uno::Reference< com::sun::star::document::XLinkAuthorizer > 
xLinkAuthorizer( model, uno::UNO_QUERY );
+        if ( xLinkAuthorizer.is() ) {
+            if ( !xLinkAuthorizer->authorizeLinks( aURL ) )
+                throw uno::RuntimeException();
+        }
         xObj = uno::Reference < embed::XEmbeddedObject >( 
xFactory->createInstanceLink(
                 pImpl->mxStorage, rNewName, aMedium, aObjDescr ), 
uno::UNO_QUERY );
 

Reply via email to