include/sfx2/linkmgr.hxx                                  |    3 +-
 sd/source/core/drawdoc.cxx                                |    2 -
 sfx2/source/appl/linkmgr2.cxx                             |    6 +++--
 sw/qa/extras/uiwriter/uiwriter8.cxx                       |    4 +--
 sw/qa/extras/uiwriter/uiwriter9.cxx                       |    3 +-
 sw/source/core/doc/DocumentLinksAdministrationManager.cxx |    4 ++-
 sw/source/core/docnode/section.cxx                        |    2 -
 sw/source/core/frmedt/feflyole.cxx                        |    2 -
 sw/source/filter/html/swhtml.cxx                          |    5 +++-
 sw/source/uibase/shells/basesh.cxx                        |   15 ++++++++++++--
 sw/source/uibase/uiview/viewprt.cxx                       |    8 ++++++-
 sw/source/uibase/uno/unotxdoc.cxx                         |    2 -
 sw/source/uibase/utlui/glbltree.cxx                       |    2 -
 13 files changed, 42 insertions(+), 16 deletions(-)

New commits:
commit 2b250d2dbfa907a2eb571c5c4cb36b00c908bdc6
Author:     Stephan Bergmann <stephan.bergm...@allotropia.de>
AuthorDate: Thu Jun 13 15:03:51 2024 +0200
Commit:     Stephan Bergmann <stephan.bergm...@allotropia.de>
CommitDate: Thu Jun 13 20:55:11 2024 +0200

    Let LinkManager::UpdateAllLinks honor isUntrustedReferer
    
    Change-Id: I3714061376afaf1186e4f7cfe5b28bfb54aa7a99
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168789
    Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de>
    Tested-by: Jenkins

diff --git a/include/sfx2/linkmgr.hxx b/include/sfx2/linkmgr.hxx
index af6be44f58b1..1af8e7263197 100644
--- a/include/sfx2/linkmgr.hxx
+++ b/include/sfx2/linkmgr.hxx
@@ -130,7 +130,8 @@ public:
 
     void        UpdateAllLinks(bool bAskUpdate,
                                bool bUpdateGrfLinks,
-                               weld::Window* pParentWin);
+                               weld::Window* pParentWin,
+                               OUString const & referer);
 
     // Call for list of links (eg for link-dialog)
     const       SvBaseLinks& GetLinks() const { return aLinkTbl; }
diff --git a/sd/source/core/drawdoc.cxx b/sd/source/core/drawdoc.cxx
index 7029b55edbc6..635696cd3695 100644
--- a/sd/source/core/drawdoc.cxx
+++ b/sd/source/core/drawdoc.cxx
@@ -840,7 +840,7 @@ void SdDrawDocument::UpdateAllLinks()
         rEmbeddedObjectContainer.setUserAllowsLinkUpdate(true);
     }
 
-    m_pLinkManager->UpdateAllLinks(true, false, nullptr);  // query box: 
update all links?
+    m_pLinkManager->UpdateAllLinks(true, false, nullptr, "");  // query box: 
update all links?
 
     if (s_pDocLockedInsertingLinks == this)
         s_pDocLockedInsertingLinks = nullptr;  // unlock inserting links
diff --git a/sfx2/source/appl/linkmgr2.cxx b/sfx2/source/appl/linkmgr2.cxx
index f041b28a12cc..da2a3cf141f7 100644
--- a/sfx2/source/appl/linkmgr2.cxx
+++ b/sfx2/source/appl/linkmgr2.cxx
@@ -281,11 +281,13 @@ bool LinkManager::GetDisplayNames( const SvBaseLink * 
pLink,
 void LinkManager::UpdateAllLinks(
     bool bAskUpdate,
     bool bUpdateGrfLinks,
-    weld::Window* pParentWin )
+    weld::Window* pParentWin,
+    OUString const & referer )
 {
     // when active content is disabled don't bother updating all links
     // also (when bAskUpdate == true) don't show the pop up.
-    
if(officecfg::Office::Common::Security::Scripting::DisableActiveContent::get())
+    
if(officecfg::Office::Common::Security::Scripting::DisableActiveContent::get()
+       || SvtSecurityOptions::isUntrustedReferer(referer))
         return;
 
     // First make a copy of the array in order to update links
diff --git a/sw/qa/extras/uiwriter/uiwriter8.cxx 
b/sw/qa/extras/uiwriter/uiwriter8.cxx
index 215fc719ad66..77f9d72432e3 100644
--- a/sw/qa/extras/uiwriter/uiwriter8.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter8.cxx
@@ -2749,7 +2749,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf128106)
     // no way to set SwDocShell::m_nUpdateDocMode away from NO_UPDATE ?
     // pMasterDoc->getIDocumentLinksAdministration().UpdateLinks();
     
pMasterDoc->getIDocumentLinksAdministration().GetLinkManager().UpdateAllLinks(false,
 false,
-                                                                               
   nullptr);
+                                                                               
   nullptr, "");
     // note: this has called SwGetRefFieldType::UpdateGetReferences()
     SwFieldType const* const pType(
         
pMasterDoc->getIDocumentFieldsAccess().GetSysFieldType(SwFieldIds::GetRef));
@@ -2804,7 +2804,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf103612)
         size_t(1),
         
pGlobalDoc->getIDocumentLinksAdministration().GetLinkManager().GetLinks().size());
     
pGlobalDoc->getIDocumentLinksAdministration().GetLinkManager().UpdateAllLinks(false,
 false,
-                                                                               
   nullptr);
+                                                                               
   nullptr, "");
 
     xmlDocUniquePtr pLayout = parseLayoutDump();
 
diff --git a/sw/qa/extras/uiwriter/uiwriter9.cxx 
b/sw/qa/extras/uiwriter/uiwriter9.cxx
index 8523bd95c9eb..8d40f53065ff 100644
--- a/sw/qa/extras/uiwriter/uiwriter9.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter9.cxx
@@ -505,7 +505,8 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, 
testTdf158375_dde_disable)
     CPPUNIT_ASSERT_EQUAL(
         size_t(1), 
pDoc->getIDocumentLinksAdministration().GetLinkManager().GetLinks().size());
 
-    
pDoc->getIDocumentLinksAdministration().GetLinkManager().UpdateAllLinks(false, 
false, nullptr);
+    
pDoc->getIDocumentLinksAdministration().GetLinkManager().UpdateAllLinks(false, 
false, nullptr,
+                                                                            
"");
 
     uno::Reference<text::XTextSectionsSupplier> 
xTextSectionsSupplier(mxComponent, uno::UNO_QUERY);
     uno::Reference<container::XIndexAccess> 
xSections(xTextSectionsSupplier->getTextSections(),
diff --git a/sw/source/core/doc/DocumentLinksAdministrationManager.cxx 
b/sw/source/core/doc/DocumentLinksAdministrationManager.cxx
index 2d491021c3a3..98f304a800eb 100644
--- a/sw/source/core/doc/DocumentLinksAdministrationManager.cxx
+++ b/sw/source/core/doc/DocumentLinksAdministrationManager.cxx
@@ -228,7 +228,9 @@ void DocumentLinksAdministrationManager::UpdateLinks()
         rEmbeddedObjectContainer.setUserAllowsLinkUpdate(true);
 
         weld::Window* pDlgParent = GetFrameWeld(m_rDoc.GetDocShell());
-        GetLinkManager().UpdateAllLinks(bAskUpdate, false, pDlgParent);
+        SfxMedium * medium = m_rDoc.GetDocShell()->GetMedium();
+        GetLinkManager().UpdateAllLinks(
+            bAskUpdate, false, pDlgParent, medium == nullptr ? OUString() : 
medium->GetName());
     }
     else
     {
diff --git a/sw/source/core/docnode/section.cxx 
b/sw/source/core/docnode/section.cxx
index 9dcb637d2cea..34d3c566f016 100644
--- a/sw/source/core/docnode/section.cxx
+++ b/sw/source/core/docnode/section.cxx
@@ -1247,7 +1247,7 @@ static void lcl_UpdateLinksInSect( const SwBaseLink& 
rUpdLnk, SwSectionNode& rSe
                 if ( pSrcDoc != pDoc &&
                      rSection.IsProtectFlag() )
                 {
-                    
pSrcDoc->getIDocumentLinksAdministration().GetLinkManager().UpdateAllLinks( 
false, false, nullptr );
+                    
pSrcDoc->getIDocumentLinksAdministration().GetLinkManager().UpdateAllLinks( 
false, false, nullptr, "" );
                 }
 
                 if( oCpyRg )
diff --git a/sw/source/core/frmedt/feflyole.cxx 
b/sw/source/core/frmedt/feflyole.cxx
index efcbaaa1721e..4f8a6e74764e 100644
--- a/sw/source/core/frmedt/feflyole.cxx
+++ b/sw/source/core/frmedt/feflyole.cxx
@@ -112,7 +112,7 @@ bool SwFEShell::FinishOLEObj()                      // 
Server is terminated
         // if we have more than one link let's update them too
         sfx2::LinkManager& rLinkManager = 
GetDoc()->getIDocumentLinksAdministration().GetLinkManager();
         if (rLinkManager.GetLinks().size() > 1)
-            rLinkManager.UpdateAllLinks(false, false, nullptr);
+            rLinkManager.UpdateAllLinks(false, false, nullptr, "");
 
         // return back original value of the "update of the link preview" flag
         
rEmbeddedObjectContainer.setUserAllowsLinkUpdate(aUserAllowsLinkUpdate);
diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx
index fe6091534a29..345d934ada25 100644
--- a/sw/source/filter/html/swhtml.cxx
+++ b/sw/source/filter/html/swhtml.cxx
@@ -493,7 +493,10 @@ SwHTMLParser::~SwHTMLParser()
         sal_uInt16 nLinkMode = 
m_xDoc->getIDocumentSettingAccess().getLinkUpdateMode( true );
         if( nLinkMode != NEVER && bAsync &&
             
SfxObjectCreateMode::INTERNAL!=m_xDoc->GetDocShell()->GetCreateMode() )
-            
m_xDoc->getIDocumentLinksAdministration().GetLinkManager().UpdateAllLinks( 
nLinkMode == MANUAL, false, nullptr );
+        {
+            SfxMedium * medium = m_xDoc->GetDocShell()->GetMedium();
+            
m_xDoc->getIDocumentLinksAdministration().GetLinkManager().UpdateAllLinks( 
nLinkMode == MANUAL, false, nullptr, medium == nullptr ? OUString() : 
medium->GetName() );
+        }
 
         if ( m_xDoc->GetDocShell()->IsLoading() )
         {
diff --git a/sw/source/uibase/shells/basesh.cxx 
b/sw/source/uibase/shells/basesh.cxx
index 3b7e66f6c465..c37d46a9d993 100644
--- a/sw/source/uibase/shells/basesh.cxx
+++ b/sw/source/uibase/shells/basesh.cxx
@@ -25,6 +25,7 @@
 #include <hintids.hxx>
 #include <comphelper/servicehelper.hxx>
 #include <svl/languageoptions.hxx>
+#include <sfx2/docfile.hxx>
 #include <sfx2/linkmgr.hxx>
 #include <sfx2/htmlmode.hxx>
 #include <svx/imapdlg.hxx>
@@ -972,7 +973,12 @@ void SwBaseShell::Execute(SfxRequest &rReq)
                 if( !rSh.GetLinkManager().GetLinks().empty() )
                 {
                     rSh.StartAllAction();
-                    rSh.GetLinkManager().UpdateAllLinks( false, true, nullptr 
);
+                    SfxMedium * medium = nullptr;
+                    if (auto const sh = rSh.GetDoc()->GetDocShell()) {
+                        medium = sh->GetMedium();
+                    }
+                    rSh.GetLinkManager().UpdateAllLinks(
+                        false, true, nullptr, medium == nullptr ? OUString() : 
medium->GetName() );
                     rSh.EndAllAction();
                 }
                 SfxDispatcher &rDis = 
*rTempView.GetViewFrame().GetDispatcher();
@@ -1489,7 +1495,12 @@ void SwBaseShell::Execute(SfxRequest &rReq)
                 {
                     rSh.EnterStdMode();
                     rSh.StartAllAction();
-                    rSh.GetLinkManager().UpdateAllLinks( false, false, nullptr 
);
+                    SfxMedium * medium = nullptr;
+                    if (auto const sh = rSh.GetDoc()->GetDocShell()) {
+                        medium = sh->GetMedium();
+                    }
+                    rSh.GetLinkManager().UpdateAllLinks(
+                        false, false, nullptr, medium == nullptr ? OUString() 
: medium->GetName() );
                     rSh.EndAllAction();
                 }
             }
diff --git a/sw/source/uibase/uiview/viewprt.cxx 
b/sw/source/uibase/uiview/viewprt.cxx
index aec5c9b224e3..1d19a897c034 100644
--- a/sw/source/uibase/uiview/viewprt.cxx
+++ b/sw/source/uibase/uiview/viewprt.cxx
@@ -20,6 +20,7 @@
 #include <libxml/xmlwriter.h>
 #include <cmdid.h>
 #include <officecfg/Office/Common.hxx>
+#include <sfx2/docfile.hxx>
 #include <sfx2/request.hxx>
 #include <sfx2/viewfrm.hxx>
 #include <vcl/svapp.hxx>
@@ -248,7 +249,12 @@ void SwView::ExecutePrint(SfxRequest& rReq)
             //#i61455# if master documents are printed silently without loaded 
links then update the links now
             if( bSilent && pSh->IsGlobalDoc() && !pSh->IsGlblDocSaveLinks() )
             {
-                pSh->GetLinkManager().UpdateAllLinks( false, false, nullptr );
+                SfxMedium * medium = nullptr;
+                if (auto const sh = pSh->GetDoc()->GetDocShell()) {
+                    medium = sh->GetMedium();
+                }
+                pSh->GetLinkManager().UpdateAllLinks(
+                    false, false, nullptr, medium == nullptr ? OUString() : 
medium->GetName() );
             }
             SfxRequest aReq( rReq );
             SfxBoolItem aBool(SID_SELECTION, bPrintSelection);
diff --git a/sw/source/uibase/uno/unotxdoc.cxx 
b/sw/source/uibase/uno/unotxdoc.cxx
index 79e5185799a8..a7d17cf71778 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -2337,7 +2337,7 @@ void SwXTextDocument::updateLinks(  )
     if( !rLnkMan.GetLinks().empty() )
     {
         UnoActionContext aAction(&rDoc);
-        rLnkMan.UpdateAllLinks( false, true, nullptr );
+        rLnkMan.UpdateAllLinks( false, true, nullptr, "" );
     }
 }
 
diff --git a/sw/source/uibase/utlui/glbltree.cxx 
b/sw/source/uibase/utlui/glbltree.cxx
index 6ae53ad36c6c..8dab9b527c6e 100644
--- a/sw/source/uibase/utlui/glbltree.cxx
+++ b/sw/source/uibase/utlui/glbltree.cxx
@@ -611,7 +611,7 @@ void 
SwGlobalTree::ExecuteContextMenuAction(std::u16string_view rSelectedPopupEn
     }
     else if (rSelectedPopupEntry == u"updatelinks" || rSelectedPopupEntry == 
u"updateall")
     {
-        m_pActiveShell->GetLinkManager().UpdateAllLinks(true, false, nullptr);
+        m_pActiveShell->GetLinkManager().UpdateAllLinks(true, false, nullptr, 
"");
         if (rSelectedPopupEntry == u"updateall")
             nSlot = FN_UPDATE_TOX;
         pCont = nullptr;

Reply via email to