[Libreoffice-commits] online.git: 2 commits - loleaflet/debug loleaflet/html loleaflet/src loolwsd.xml.in wsd/FileServer.cpp wsd/Storage.cpp wsd/Storage.hpp
Ashod Nakashian (via logerrit)
logerrit at kemper.freedesktop.org
Mon Oct 28 09:45:21 UTC 2019
loleaflet/debug/document/loleaflet.html | 4 ++
loleaflet/html/loleaflet.html.m4 | 1
loleaflet/src/main.js | 13 +++++-
loolwsd.xml.in | 5 +-
wsd/FileServer.cpp | 14 +++++++
wsd/Storage.cpp | 60 ++++++++++++++++++++++++++++++--
wsd/Storage.hpp | 13 +++++-
7 files changed, 100 insertions(+), 10 deletions(-)
New commits:
commit 8c4edb5087ac5f225b992d795c5ba33c4a5b5f38
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
AuthorDate: Mon Aug 26 21:16:54 2019 -0400
Commit: Michael Meeks <michael.meeks at collabora.com>
CommitDate: Mon Oct 28 10:45:14 2019 +0100
Reuse cookies from the browser
Reviewed-on: https://gerrit.libreoffice.org/78195
Reviewed-by: Andras Timar <andras.timar at collabora.com>
Tested-by: Andras Timar <andras.timar at collabora.com>
(cherry picked from commit 8deecf4ea6966c059458bdc71e365be426238e09)
Change-Id: I96bbdd3e71bc9d0ecfddea7debc0ebcc303a49ae
Reviewed-on: https://gerrit.libreoffice.org/81558
Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
Tested-by: Michael Meeks <michael.meeks at collabora.com>
diff --git a/loleaflet/debug/document/loleaflet.html b/loleaflet/debug/document/loleaflet.html
index f7d17966c..852b8078b 100644
--- a/loleaflet/debug/document/loleaflet.html
+++ b/loleaflet/debug/document/loleaflet.html
@@ -95,12 +95,16 @@
var wopiSrc = getParameterByName('WOPISrc');
var access_token = '%ACCESS_TOKEN%';
var access_header = '%ACCESS_HEADER%';
+ var reuse_cookies = '%REUSE_COOKIES%';
if (wopiSrc !== '' && access_token !== '') {
wopiSrc += '?access_token=' + access_token;
}
else if (wopiSrc !== '' && access_header !== '') {
wopiSrc += '?access_header=' + access_header;
}
+ else if (wopiSrc !== '' && reuse_cookies !== '') {
+ wopiSrc += '?reuse_cookies=' + reuse_cookies;
+ }
var host = '%HOST%';
var filePath = getParameterByName('file_path');
diff --git a/loleaflet/html/loleaflet.html.m4 b/loleaflet/html/loleaflet.html.m4
index 7401c4724..d61974170 100644
--- a/loleaflet/html/loleaflet.html.m4
+++ b/loleaflet/html/loleaflet.html.m4
@@ -229,6 +229,7 @@ ifelse(MOBILEAPP,[true],
window.loleafletLogging = '%LOLEAFLET_LOGGING%';
window.outOfFocusTimeoutSecs = %OUT_OF_FOCUS_TIMEOUT_SECS%;
window.idleTimeoutSecs = %IDLE_TIMEOUT_SECS%;
+ window.reuseCookies = '%REUSE_COOKIES%';
window.tileSize = 256;])
syscmd([cat ]GLOBAL_JS)dnl
</script>
diff --git a/loleaflet/src/main.js b/loleaflet/src/main.js
index 1110b5365..7c9d7e944 100644
--- a/loleaflet/src/main.js
+++ b/loleaflet/src/main.js
@@ -1,6 +1,6 @@
/* -*- js-indent-level: 8 -*- */
-/* global errorMessages getParameterByName accessToken accessTokenTTL accessHeader vex host */
-/* global serviceRoot idleTimeoutSecs outOfFocusTimeoutSecs setupToolbar*/
+/* global errorMessages getParameterByName accessToken accessTokenTTL accessHeader reuseCookies */
+/* global vex host serviceRoot idleTimeoutSecs outOfFocusTimeoutSecs setupToolbar*/
/*eslint indent: [error, "tab", { "outerIIFEBody": 0 }]*/
(function (global) {
@@ -14,6 +14,15 @@ else if (wopiSrc !== '' && accessHeader !== '') {
wopiParams = { 'access_header': accessHeader };
}
+if (reuseCookies !== '') {
+ if (wopiParams) {
+ wopiParams['reuse_cookies'] = reuseCookies;
+ }
+ else {
+ wopiParams = { 'reuse_cookies': reuseCookies };
+ }
+}
+
var filePath = getParameterByName('file_path');
var permission = getParameterByName('permission') || 'edit';
var timestamp = getParameterByName('timestamp');
diff --git a/loolwsd.xml.in b/loolwsd.xml.in
index 7086fe167..83c35b9ce 100644
--- a/loolwsd.xml.in
+++ b/loolwsd.xml.in
@@ -16,7 +16,7 @@
<per_document desc="Document-specific settings, including LO Core settings.">
<max_concurrency desc="The maximum number of threads to use while processing a document." type="uint" default="4">4</max_concurrency>
<document_signing_url desc="The endpoint URL of signing server, if empty the document signing is disabled" type="string" default="@VEREIGN_URL@">@VEREIGN_URL@</document_signing_url>
- <redlining_as_comments desc="If true show red-lines as comments" type="bool" default="true">true</redlining_as_comments>
+ <redlining_as_comments desc="If true show red-lines as comments" type="bool" default="true">true</redlining_as_comments>
<idle_timeout_secs desc="The maximum number of seconds before unloading an idle document. Defaults to 1 hour." type="uint" default="3600">3600</idle_timeout_secs>
<!-- Idle save and auto save are checked every 30 seconds -->
<!-- They are disabled when the value is zero or negative. -->
@@ -28,7 +28,7 @@
<limit_stack_mem_kb desc="The maximum stack size allowed to each document process. 0 for unlimited." type="uint">8000</limit_stack_mem_kb>
<limit_file_size_mb desc="The maximum file size allowed to each document process to write. 0 for unlimited." type="uint">0</limit_file_size_mb>
<limit_num_open_files desc="The maximum number of files allowed to each document process to open. 0 for unlimited." type="uint">0</limit_num_open_files>
- <limit_load_secs desc="Maximum number of seconds to wait for a document load to succeed. 0 for unlimited." type="uint" default="100">100</limit_load_secs>
+ <limit_load_secs desc="Maximum number of seconds to wait for a document load to succeed. 0 for unlimited." type="uint" default="100">100</limit_load_secs>
</per_document>
<per_view desc="View-specific settings.">
@@ -121,6 +121,7 @@
<host desc="Regex pattern of hostname to allow or deny." allow="true">192\.168\.[0-9]{1,3}\.[0-9]{1,3}</host>
<host desc="Regex pattern of hostname to allow or deny." allow="false">192\.168\.1\.1</host>
<max_file_size desc="Maximum document size in bytes to load. 0 for unlimited." type="uint">0</max_file_size>
+ <reuse_cookies desc="When enabled, cookies from the browser will be captured and set on WOPI requests." type="bool" default="false">false</reuse_cookies>
</wopi>
<webdav desc="Allow/deny webdav storage. Mutually exclusive with wopi." allow="false">
<host desc="Hostname to allow" allow="false">localhost</host>
diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp
index f8b650d29..0085bee28 100644
--- a/wsd/FileServer.cpp
+++ b/wsd/FileServer.cpp
@@ -678,6 +678,20 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, Poco::
const std::string idleTimeoutSecs= config.getString("per_view.idle_timeout_secs", "900");
Poco::replaceInPlace(preprocess, std::string("%IDLE_TIMEOUT_SECS%"), idleTimeoutSecs);
+ // Capture cookies so we can optionally reuse them for the storage requests.
+ {
+ 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() ? ":" : "");
+
+ const std::string cookiesString = cookieTokens.str();
+ if (!cookiesString.empty())
+ LOG_DBG("Captured cookies: " << cookiesString);
+ Poco::replaceInPlace(preprocess, std::string("%REUSE_COOKIES%"), cookiesString);
+ }
+
const std::string mimeType = "text/html";
std::ostringstream oss;
@@ -693,20 +707,6 @@ 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;
diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp
index 5122a62d2..38c682c1c 100644
--- a/wsd/Storage.cpp
+++ b/wsd/Storage.cpp
@@ -404,7 +404,7 @@ Poco::Net::HTTPClientSession* StorageBase::getHTTPClientSession(const Poco::URI&
namespace
{
-void addStorageDebugCookie(Poco::Net::HTTPRequest& request)
+static void addStorageDebugCookie(Poco::Net::HTTPRequest& request)
{
(void) request;
#if ENABLE_DEBUG
@@ -422,19 +422,19 @@ void addStorageDebugCookie(Poco::Net::HTTPRequest& request)
#endif
}
-void addStorageReuseCookie(Poco::Net::HTTPRequest& request)
+static void addStorageReuseCookie(Poco::Net::HTTPRequest& request, const std::string& reuseStorageCookies)
{
- if (std::getenv("LOOL_REUSE_STORAGE_COOKIE"))
+ if (!reuseStorageCookies.empty())
{
Poco::Net::NameValueCollection nvcCookies;
- std::vector<std::string> cookies = LOOLProtocol::tokenize(std::string(std::getenv("LOOL_REUSE_STORAGE_COOKIE")), ':');
+ std::vector<std::string> cookies = LOOLProtocol::tokenize(reuseStorageCookies, ':');
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] << "].");
+ LOG_DBG("Added storage reuse cookie [" << cookieTokens[0] << "=" << cookieTokens[1] << "].");
}
}
request.setCookies(nvcCookies);
@@ -450,6 +450,16 @@ std::unique_ptr<WopiStorage::WOPIFileInfo> WopiStorage::getWOPIFileInfo(const Au
auth.authorizeURI(uriObject);
const std::string uriAnonym = LOOLWSD::anonymizeUrl(uriObject.toString());
+ std::string reuseStorageCookies;
+ for (const auto& param : uriObject.getQueryParameters())
+ {
+ if (param.first == "reuse_cookies")
+ {
+ reuseStorageCookies = param.second;
+ break;
+ }
+ }
+
LOG_DBG("Getting info for wopi uri [" << uriAnonym << "].");
std::string wopiResponse;
@@ -460,7 +470,8 @@ std::unique_ptr<WopiStorage::WOPIFileInfo> WopiStorage::getWOPIFileInfo(const Au
request.set("User-Agent", WOPI_AGENT_STRING);
auth.authorizeRequest(request);
addStorageDebugCookie(request);
- addStorageReuseCookie(request);
+ if (_reuseCookies)
+ addStorageReuseCookie(request, reuseStorageCookies);
const auto startTime = std::chrono::steady_clock::now();
std::unique_ptr<Poco::Net::HTTPClientSession> psession(getHTTPClientSession(uriObject));
@@ -653,6 +664,16 @@ std::string WopiStorage::loadStorageFileToLocal(const Authorization& auth, const
uriObject.setPath(uriObject.getPath() + "/contents");
auth.authorizeURI(uriObject);
+ std::string reuseStorageCookies;
+ for (const auto& param : uriObject.getQueryParameters())
+ {
+ if (param.first == "reuse_cookies")
+ {
+ reuseStorageCookies = param.second;
+ break;
+ }
+ }
+
Poco::URI uriObjectAnonym(getUri());
uriObjectAnonym.setPath(LOOLWSD::anonymizeUrl(uriObjectAnonym.getPath()) + "/contents");
const std::string uriAnonym = uriObjectAnonym.toString();
@@ -679,7 +700,8 @@ std::string WopiStorage::loadStorageFileToLocal(const Authorization& auth, const
request.set("User-Agent", WOPI_AGENT_STRING);
auth.authorizeRequest(request);
addStorageDebugCookie(request);
- addStorageReuseCookie(request);
+ if (_reuseCookies)
+ addStorageReuseCookie(request, reuseStorageCookies);
psession->sendRequest(request);
Poco::Net::HTTPResponse response;
@@ -744,6 +766,17 @@ StorageBase::SaveResult WopiStorage::saveLocalFileToStorage(const Authorization&
Poco::URI uriObject(getUri());
uriObject.setPath(isSaveAs || isRename? uriObject.getPath(): uriObject.getPath() + "/contents");
auth.authorizeURI(uriObject);
+
+ std::string reuseStorageCookies;
+ for (const auto& param : uriObject.getQueryParameters())
+ {
+ if (param.first == "reuse_cookies")
+ {
+ reuseStorageCookies = param.second;
+ break;
+ }
+ }
+
const std::string uriAnonym = LOOLWSD::anonymizeUrl(uriObject.toString());
LOG_INF("Uploading URI via WOPI [" << uriAnonym << "] from [" << filePathAnonym + "].");
@@ -823,7 +856,8 @@ StorageBase::SaveResult WopiStorage::saveLocalFileToStorage(const Authorization&
request.setContentType("application/octet-stream");
request.setContentLength(size);
addStorageDebugCookie(request);
- addStorageReuseCookie(request);
+ if (_reuseCookies)
+ addStorageReuseCookie(request, reuseStorageCookies);
std::ostream& os = psession->sendRequest(request);
std::ifstream ifs(filePath);
diff --git a/wsd/Storage.hpp b/wsd/Storage.hpp
index 85b7e9231..6bb57a72a 100644
--- a/wsd/Storage.hpp
+++ b/wsd/Storage.hpp
@@ -301,10 +301,15 @@ public:
const std::string& localStorePath,
const std::string& jailPath) :
StorageBase(uri, localStorePath, jailPath),
- _wopiLoadDuration(0)
+ _wopiLoadDuration(0),
+ _reuseCookies(false)
{
- LOG_INF("WopiStorage ctor with localStorePath: [" << localStorePath <<
- "], jailPath: [" << jailPath << "], uri: [" << LOOLWSD::anonymizeUrl(uri.toString()) << "].");
+ const auto& app = Poco::Util::Application::instance();
+ _reuseCookies = app.config().getBool("storage.wopi.reuse_cookies", false);
+ LOG_INF("WopiStorage ctor with localStorePath: ["
+ << localStorePath << "], jailPath: [" << jailPath << "], uri: ["
+ << LOOLWSD::anonymizeUrl(uri.toString()) << "], reuseCookies: [" << _reuseCookies
+ << "].");
}
class WOPIFileInfo
@@ -513,6 +518,8 @@ public:
private:
// Time spend in loading the file from storage
std::chrono::duration<double> _wopiLoadDuration;
+ /// Whether or not to re-use cookies from the browser for the WOPI requests.
+ bool _reuseCookies;
};
/// WebDAV protocol backed storage.
commit 1e63a02be44e005d18c257e0b408ed23d9e095a5
Author: merttumer <mert.tumer at collabora.com>
AuthorDate: Wed Aug 21 16:23:40 2019 +0300
Commit: Michael Meeks <michael.meeks at collabora.com>
CommitDate: Mon Oct 28 10:45:04 2019 +0100
Added reuse cookie option for wopi client
Signed-off-by: merttumer <mert.tumer at collabora.com>
(cherry picked from commit 9b8aa96a18ce2eda11b5e51b2df5bb0d8cd822d2)
Reviewed-on: https://gerrit.libreoffice.org/78194
Reviewed-by: Andras Timar <andras.timar at collabora.com>
Tested-by: Andras Timar <andras.timar at collabora.com>
(cherry picked from commit 3ab7e500d83ed814a2d1ba1043df828b1b6c865f)
Change-Id: I61577189f461ef94523af13b3734d84a20a11222
Reviewed-on: https://gerrit.libreoffice.org/81557
Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
Tested-by: Michael Meeks <michael.meeks at collabora.com>
diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp
index 3d1766fba..f8b650d29 100644
--- a/wsd/FileServer.cpp
+++ b/wsd/FileServer.cpp
@@ -693,6 +693,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;
diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp
index 1ffdcdc78..5122a62d2 100644
--- a/wsd/Storage.cpp
+++ b/wsd/Storage.cpp
@@ -422,6 +422,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);
+ }
+}
+
} // anonymous namespace
std::unique_ptr<WopiStorage::WOPIFileInfo> WopiStorage::getWOPIFileInfo(const Authorization& auth)
@@ -441,7 +460,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));
@@ -449,7 +468,6 @@ std::unique_ptr<WopiStorage::WOPIFileInfo> WopiStorage::getWOPIFileInfo(const Au
Poco::Net::HTTPResponse response;
std::istream& rs = psession->receiveResponse(response);
-
callDuration = (std::chrono::steady_clock::now() - startTime);
Log::StreamLogger logger = Log::trace();
@@ -661,6 +679,7 @@ std::string WopiStorage::loadStorageFileToLocal(const Authorization& auth, const
request.set("User-Agent", WOPI_AGENT_STRING);
auth.authorizeRequest(request);
addStorageDebugCookie(request);
+ addStorageReuseCookie(request);
psession->sendRequest(request);
Poco::Net::HTTPResponse response;
@@ -804,6 +823,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);
More information about the Libreoffice-commits
mailing list