kbrown / rpms / libreoffice

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