wsd/FileServer.cpp | 18 +++++++++++++++++- wsd/Storage.cpp | 23 ++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-)
New commits: commit 3ab7e500d83ed814a2d1ba1043df828b1b6c865f Author: merttumer <[email protected]> AuthorDate: Wed Aug 21 16:23:40 2019 +0300 Commit: Andras Timar <[email protected]> CommitDate: Wed Aug 28 14:14:59 2019 +0200 Added reuse cookie option for wopi client Signed-off-by: merttumer <[email protected]> (cherry picked from commit 9b8aa96a18ce2eda11b5e51b2df5bb0d8cd822d2) Change-Id: I61577189f461ef94523af13b3734d84a20a11222 Reviewed-on: https://gerrit.libreoffice.org/78194 Reviewed-by: Andras Timar <[email protected]> Tested-by: Andras Timar <[email protected]> diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp index 447a23a90..6ce5c7b67 100644 --- a/wsd/FileServer.cpp +++ b/wsd/FileServer.cpp @@ -569,7 +569,8 @@ constexpr char BRANDING_UNSUPPORTED[] = "branding-unsupported"; void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, Poco::MemoryInputStream& message, const std::shared_ptr<StreamSocket>& socket) { - const auto host = ((LOOLWSD::isSSLEnabled() || LOOLWSD::isSSLTermination()) ? "wss://" : "ws://") + (LOOLWSD::ServerName.empty() ? request.getHost() : LOOLWSD::ServerName); + const auto host = ((LOOLWSD::isSSLEnabled() || LOOLWSD::isSSLTermination()) ? "wss://" : "ws://") + + (LOOLWSD::ServerName.empty() ? request.getHost() : LOOLWSD::ServerName); const Poco::URI::QueryParameters params = Poco::URI(request.getURI()).getQueryParameters(); // Is this a file we read at startup - if not; its not for serving. @@ -670,6 +671,20 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, Poco:: << "X-XSS-Protection: 1; mode=block\r\n" << "Referrer-Policy: no-referrer\r\n"; + const std::string reuseCookie = form.get("reuse_cookies_for_storage", ""); + if (reuseCookie == "true") + { + NameValueCollection cookies; + request.getCookies(cookies); + std::ostringstream cookieTokens; + + for (auto it = cookies.begin(); it != cookies.end(); it++) + { + cookieTokens << (*it).first << "=" << (*it).second << (std::next(it) != cookies.end() ? ":" : ""); + } + setenv("LOOL_REUSE_STORAGE_COOKIE", cookieTokens.str().c_str(), 1); + } + // Document signing: if endpoint URL is configured, whitelist that for // iframe purposes. std::ostringstream cspOss; @@ -720,6 +735,7 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, Poco:: LOG_TRC("Denied all frame ancestors"); cspOss << "img-src 'self' data: none;"; } + cspOss << "\r\n"; // Append CSP to response headers too oss << cspOss.str(); diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp index 387a03b50..83466fde7 100644 --- a/wsd/Storage.cpp +++ b/wsd/Storage.cpp @@ -397,6 +397,25 @@ void addStorageDebugCookie(Poco::Net::HTTPRequest& request) #endif } +void addStorageReuseCookie(Poco::Net::HTTPRequest& request) +{ + if (std::getenv("LOOL_REUSE_STORAGE_COOKIE")) + { + Poco::Net::NameValueCollection nvcCookies; + std::vector<std::string> cookies = LOOLProtocol::tokenize(std::string(std::getenv("LOOL_REUSE_STORAGE_COOKIE")), ':'); + for (auto cookie : cookies) + { + std::vector<std::string> cookieTokens = LOOLProtocol::tokenize(cookie, '='); + if (cookieTokens.size() == 2) + { + nvcCookies.add(cookieTokens[0], cookieTokens[1]); + LOG_TRC("Added storage reuse cookie [" << cookieTokens[0] << "=" << cookieTokens[1] << "]."); + } + } + request.setCookies(nvcCookies); + } +} + Poco::Timestamp iso8601ToTimestamp(const std::string& iso8601Time, const std::string& name) { Poco::Timestamp timestamp = Poco::Timestamp::fromEpochTime(0); @@ -438,7 +457,7 @@ std::unique_ptr<WopiStorage::WOPIFileInfo> WopiStorage::getWOPIFileInfo(const Au request.set("User-Agent", WOPI_AGENT_STRING); auth.authorizeRequest(request); addStorageDebugCookie(request); - + addStorageReuseCookie(request); const auto startTime = std::chrono::steady_clock::now(); std::unique_ptr<Poco::Net::HTTPClientSession> psession(getHTTPClientSession(uriObject)); @@ -645,6 +664,7 @@ std::string WopiStorage::loadStorageFileToLocal(const Authorization& auth) request.set("User-Agent", WOPI_AGENT_STRING); auth.authorizeRequest(request); addStorageDebugCookie(request); + addStorageReuseCookie(request); psession->sendRequest(request); Poco::Net::HTTPResponse response; @@ -785,6 +805,7 @@ StorageBase::SaveResult WopiStorage::saveLocalFileToStorage(const Authorization& request.setContentType("application/octet-stream"); request.setContentLength(size); addStorageDebugCookie(request); + addStorageReuseCookie(request); std::ostream& os = psession->sendRequest(request); std::ifstream ifs(filePath); _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
