loolwsd/Storage.cpp | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-)
New commits: commit a76e9a2b21a2d5b34feba35524aa75fb843461cf Author: Ashod Nakashian <ashod.nakash...@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 <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@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."); } //////////////////// _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits