64af5b
From 143eedd298113bb20c2807baa49a4c83c2cef70b Mon Sep 17 00:00:00 2001
64af5b
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
64af5b
Date: Fri, 26 Jul 2019 13:25:31 +0100
64af5b
Subject: [PATCH 1/3] decode url escape codes and check each path segment
64af5b
64af5b
Change-Id: Ie8f7cef912e8dacbc2a0bca73534a7a242a53ca1
64af5b
Reviewed-on: https://gerrit.libreoffice.org/76378
64af5b
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
64af5b
Tested-by: Jenkins
64af5b
(cherry picked from commit 7942929685fafb0f9c82feb8da7279e5103c87f0)
64af5b
Reviewed-on: https://gerrit.libreoffice.org/76451
64af5b
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
64af5b
Tested-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
64af5b
---
64af5b
 sfx2/source/doc/objmisc.cxx | 30 +++++++++++++++++++++++++++++-
64af5b
 1 file changed, 29 insertions(+), 1 deletion(-)
64af5b
64af5b
diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx
64af5b
index 8594e9522e48..7e9288524b34 100644
64af5b
--- a/sfx2/source/doc/objmisc.cxx
64af5b
+++ b/sfx2/source/doc/objmisc.cxx
64af5b
@@ -41,6 +41,8 @@
64af5b
 #include <com/sun/star/script/provider/XScriptProvider.hpp>
64af5b
 #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
64af5b
 #include <com/sun/star/ucb/SimpleFileAccess.hpp>
64af5b
+#include <com/sun/star/uri/UriReferenceFactory.hpp>
64af5b
+#include <com/sun/star/uri/XVndSunStarScriptUrlReference.hpp>
64af5b
 #include <com/sun/star/util/XModifiable.hpp>
64af5b
 
64af5b
 #include <toolkit/helper/vclunohelper.hxx>
64af5b
@@ -1351,7 +1353,33 @@ namespace {
64af5b
 // don't allow LibreLogo to be used with our mouseover/etc dom-alike events
64af5b
 bool UnTrustedScript(const OUString& rScriptURL)
64af5b
 {
64af5b
-    return rScriptURL.startsWithIgnoreAsciiCase("vnd.sun.star.script:LibreLogo");
64af5b
+    if (!rScriptURL.startsWith("vnd.sun.star.script:"))
64af5b
+        return false;
64af5b
+
64af5b
+    // ensure URL Escape Codes are decoded
64af5b
+    css::uno::Reference<css::uri::XUriReference> uri(
64af5b
+        css::uri::UriReferenceFactory::create(comphelper::getProcessComponentContext())->parse(rScriptURL));
64af5b
+    css::uno::Reference<css::uri::XVndSunStarScriptUrl> sfUri(uri, css::uno::UNO_QUERY);
64af5b
+
64af5b
+    if (!sfUri.is())
64af5b
+        return false;
64af5b
+
64af5b
+    // pyuno encodes path separator as |
64af5b
+    OUString sScript = sfUri->getName().replace('|', '/');
64af5b
+
64af5b
+    // check if any path portion matches LibreLogo and ban it if it does
64af5b
+    sal_Int32 nIndex = 0;
64af5b
+    do
64af5b
+    {
64af5b
+        OUString aToken = sScript.getToken(0, '/', nIndex);
64af5b
+        if (aToken.startsWithIgnoreAsciiCase("LibreLogo"))
64af5b
+        {
64af5b
+            return true;
64af5b
+        }
64af5b
+    }
64af5b
+    while (nIndex >= 0);
64af5b
+
64af5b
+    return false;
64af5b
 }
64af5b
 
64af5b
 }
64af5b
-- 
64af5b
2.21.0
64af5b