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