2ceb93
From 8f98c29cea1e46e5a2bcde10039840145776f56b Mon Sep 17 00:00:00 2001
2ceb93
From: Stephan Bergmann <sbergman@redhat.com>
2ceb93
Date: Tue, 6 Aug 2019 13:29:22 +0200
2ceb93
Subject: [PATCH] Properly obtain location
2ceb93
MIME-Version: 1.0
2ceb93
Content-Type: text/plain; charset=UTF-8
2ceb93
Content-Transfer-Encoding: 8bit
2ceb93
2ceb93
Change-Id: I9fb0d883a3623394343cd54ef61e5610544198c8
2ceb93
Reviewed-on: https://gerrit.libreoffice.org/77019
2ceb93
Tested-by: Jenkins
2ceb93
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2ceb93
(cherry picked from commit a9cde2557242a0c343d99533f3ee032599c66f42)
2ceb93
Reviewed-on: https://gerrit.libreoffice.org/77024
2ceb93
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
2ceb93
Reviewed-by: Michael Stahl <Michael.Stahl@cib.de>
2ceb93
Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
2ceb93
Tested-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
2ceb93
---
2ceb93
 .../source/protocolhandler/scripthandler.cxx  |  9 ++++++--
2ceb93
 sfx2/source/doc/objmisc.cxx                   | 21 +++++++++++--------
2ceb93
 2 files changed, 19 insertions(+), 11 deletions(-)
2ceb93
2ceb93
diff --git a/scripting/source/protocolhandler/scripthandler.cxx b/scripting/source/protocolhandler/scripthandler.cxx
2ceb93
index f8ad8c7fd63d..332d4833a6f2 100644
2ceb93
--- a/scripting/source/protocolhandler/scripthandler.cxx
2ceb93
+++ b/scripting/source/protocolhandler/scripthandler.cxx
2ceb93
@@ -49,6 +49,7 @@
2ceb93
 
2ceb93
 #include <com/sun/star/uno/XComponentContext.hpp>
2ceb93
 #include <com/sun/star/uri/XUriReference.hpp>
2ceb93
+#include <com/sun/star/uri/XVndSunStarScriptUrlReference.hpp>
2ceb93
 #include <com/sun/star/uri/UriReferenceFactory.hpp>
2ceb93
 
2ceb93
 #include <memory>
2ceb93
@@ -135,8 +136,12 @@ void SAL_CALL ScriptProtocolHandler::dispatchWithNotification(
2ceb93
     {
2ceb93
         try
2ceb93
         {
2ceb93
-            bool bIsDocumentScript = ( aURL.Complete.indexOf( "document" ) !=-1 );
2ceb93
-                // TODO: isn't this somewhat strange? This should be a test for a location=document parameter, shouldn't it?
2ceb93
+            css::uno::Reference<css::uri::XUriReferenceFactory> urifac(
2ceb93
+                css::uri::UriReferenceFactory::create(m_xContext));
2ceb93
+            css::uno::Reference<css::uri::XVndSunStarScriptUrlReference> uri(
2ceb93
+                urifac->parse(aURL.Complete), css::uno::UNO_QUERY_THROW);
2ceb93
+            auto const loc = uri->getParameter("location");
2ceb93
+            bool bIsDocumentScript = loc == "document";
2ceb93
 
2ceb93
             if ( bIsDocumentScript )
2ceb93
             {
2ceb93
diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx
2ceb93
index 9869f76606bf..08f4d8c21297 100644
2ceb93
--- a/sfx2/source/doc/objmisc.cxx
2ceb93
+++ b/sfx2/source/doc/objmisc.cxx
2ceb93
@@ -1380,19 +1380,22 @@ ErrCode SfxObjectShell::CallXScript( const Reference< XInterface >& _rxScriptCon
2ceb93
     SAL_INFO("sfx", "in CallXScript" );
2ceb93
     ErrCode nErr = ERRCODE_NONE;
2ceb93
 
2ceb93
-    bool bIsDocumentScript = ( _rScriptURL.indexOf( "location=document" ) >= 0 );
2ceb93
-        // TODO: we should parse the URL, and check whether there is a parameter with this name.
2ceb93
-        // Otherwise, we might find too much.
2ceb93
-    if ( bIsDocumentScript && !lcl_isScriptAccessAllowed_nothrow( _rxScriptContext ) )
2ceb93
-        return ERRCODE_IO_ACCESSDENIED;
2ceb93
-
2ceb93
-    if ( UnTrustedScript(_rScriptURL) )
2ceb93
-        return ERRCODE_IO_ACCESSDENIED;
2ceb93
-
2ceb93
     bool bCaughtException = false;
2ceb93
     Any aException;
2ceb93
     try
2ceb93
     {
2ceb93
+        css::uno::Reference<css::uri::XUriReferenceFactory> urifac(
2ceb93
+            css::uri::UriReferenceFactory::create(comphelper::getProcessComponentContext()));
2ceb93
+        css::uno::Reference<css::uri::XVndSunStarScriptUrlReference> uri(
2ceb93
+            urifac->parse(_rScriptURL), css::uno::UNO_QUERY_THROW);
2ceb93
+        auto const loc = uri->getParameter("location");
2ceb93
+        bool bIsDocumentScript = loc == "document";
2ceb93
+        if ( bIsDocumentScript && !lcl_isScriptAccessAllowed_nothrow( _rxScriptContext ) )
2ceb93
+            return ERRCODE_IO_ACCESSDENIED;
2ceb93
+
2ceb93
+        if ( UnTrustedScript(_rScriptURL) )
2ceb93
+            return ERRCODE_IO_ACCESSDENIED;
2ceb93
+
2ceb93
         // obtain/create a script provider
2ceb93
         Reference< provider::XScriptProvider > xScriptProvider;
2ceb93
         Reference< provider::XScriptProviderSupplier > xSPS( _rxScriptContext, UNO_QUERY );
2ceb93
-- 
2ceb93
2.21.0
2ceb93