[Libreoffice-commits] online.git: loolwsd/Storage.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Sat Apr 16 17:58:36 UTC 2016


 loolwsd/Storage.cpp |   32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

New commits:
commit a76e9a2b21a2d5b34feba35524aa75fb843461cf
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sat Apr 16 12:55:56 2016 -0400

    loolwsd: check WOPI host against configured whitelist and cleanup factory
    
    Change-Id: I1dd45a9b1332754a33b2f190b7f6244e8e3b1dff
    Reviewed-on: https://gerrit.libreoffice.org/24136
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/Storage.cpp b/loolwsd/Storage.cpp
index 1fb3bba..a3b68e2 100644
--- a/loolwsd/Storage.cpp
+++ b/loolwsd/Storage.cpp
@@ -22,8 +22,9 @@
 #include <Poco/JSON/Object.h>
 #include <Poco/JSON/Parser.h>
 
-#include "Common.hpp"
 #include "Auth.hpp"
+#include "Common.hpp"
+#include "Exceptions.hpp"
 #include "Storage.hpp"
 #include "Util.hpp"
 #include "Unit.hpp"
@@ -96,27 +97,30 @@ std::unique_ptr<StorageBase> StorageBase::create(const std::string& jailRoot, co
     }
     else if (uri.isRelative() || uri.getScheme() == "file")
     {
-        if (!_filesystemEnabled)
+        Log::info("Public URI [" + uri.toString() + "] is a file.");
+        if (_filesystemEnabled)
         {
-            Log::error("Local Storage is disabled by default. Specify allowlocalstorage on the command-line to enable.");
-            return nullptr;
+            return std::unique_ptr<StorageBase>(new LocalStorage(jailRoot, jailPath, uri.getPath()));
         }
 
-        Log::info("Public URI [" + uri.toString() + "] is a file.");
-        storage = std::unique_ptr<StorageBase>(new LocalStorage(jailRoot, jailPath, uri.getPath()));
+        Log::error("Local Storage is disabled by default. Specify allowlocalstorage on the command-line to enable.");
     }
     else if (_wopiEnabled)
     {
-        Log::info("Public URI [" + uri.toString() +
-                  "] assuming cloud storage.");
-        storage = std::unique_ptr<StorageBase>(new WopiStorage(jailRoot, jailPath, uri.toString()));
-    }
-    else
-    {
-        throw std::runtime_error("No Storage configured or invalid URI.");
+        Log::info("Public URI [" + uri.toString() + "] considered WOPI.");
+        const auto targetHost = uri.getHost();
+        for (const auto& acceptedHost : _wopiHosts)
+        {
+            if (targetHost == acceptedHost)
+            {
+                return std::unique_ptr<StorageBase>(new WopiStorage(jailRoot, jailPath, uri.toString()));
+            }
+        }
+
+        Log::error("No acceptable WOPI hosts found matching the target host [" + targetHost + "] in config.");
     }
 
-    return storage;
+    throw BadRequestException("No Storage configured or invalid URI.");
 }
 
 ////////////////////


More information about the Libreoffice-commits mailing list