Skip to content

Commit

Permalink
Drop the config url query params from identifier
Browse files Browse the repository at this point in the history
Unescaped and used in subforkit announce they get parsed as additional
arguments. Escaped, they end up doubly unescaped elsewhere. Just drop
them entirely and disambiguate where necessary.

Signed-off-by: Caolán McNamara <[email protected]>
Change-Id: Ia57f14f7cb3aa7c4f77f2dc536996bdcaa38db78
  • Loading branch information
caolanm committed Jan 27, 2025
1 parent d17aebf commit 53999e1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions wsd/CacheUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ std::string Cache::getConfigId(const std::string& uri)
Poco::URI settingsUri(uri);
std::string sourcePrefix = settingsUri.getScheme() +
'_' + settingsUri.getAuthority();
std::string sourcePathEtc = settingsUri.getPathEtc();
return sourcePrefix + sourcePathEtc;
std::string sourcePath = settingsUri.getPath();
return sourcePrefix + sourcePath;
}

void Cache::cacheConfigFile(const std::string& configId, const std::string& uri,
Expand Down
14 changes: 8 additions & 6 deletions wsd/DocumentBroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1480,7 +1480,8 @@ DocumentBroker::updateSessionWithWopiInfo(const std::shared_ptr<ClientSession>&
std::string jailPresetsPath = FileUtil::buildLocalPathToJail(COOLWSD::EnableMountNamespaces,
getJailRoot(),
JAILED_CONFIG_ROOT);
asyncInstallPresets(session, userSettingsUri, jailPresetsPath);
std::string configId = "user-" + userId + "-" + Cache::getConfigId(userSettingsUri);
asyncInstallPresets(session, configId, userSettingsUri, jailPresetsPath);
}

// Pass the ownership to the client session.
Expand Down Expand Up @@ -1638,6 +1639,7 @@ class PresetsInstallTask
};

void DocumentBroker::asyncInstallPresets(const std::shared_ptr<ClientSession>& session,
const std::string& configId,
const std::string& userSettingsUri,
const std::string& presetsPath)
{
Expand Down Expand Up @@ -1676,7 +1678,8 @@ void DocumentBroker::asyncInstallPresets(const std::shared_ptr<ClientSession>& s
stop("configfailed");
}
};
_asyncInstallTask = asyncInstallPresets(*_poll, userSettingsUri, presetsPath, session, installFinishedCB);
_asyncInstallTask = asyncInstallPresets(*_poll, configId, userSettingsUri,
presetsPath, session, installFinishedCB);
_asyncInstallTask->appendCallback([selfWeak = weak_from_this(), this](bool){
std::shared_ptr<DocumentBroker> selfLifecycle = selfWeak.lock();
if (!selfLifecycle)
Expand Down Expand Up @@ -1777,7 +1780,8 @@ struct PresetRequest
};

std::shared_ptr<PresetsInstallTask>
DocumentBroker::asyncInstallPresets(SocketPoll& poll, const std::string& userSettingsUri,
DocumentBroker::asyncInstallPresets(SocketPoll& poll, const std::string& configId,
const std::string& userSettingsUri,
const std::string& presetsPath,
const std::shared_ptr<ClientSession>& session,
const std::function<void(bool)>& installFinishedCB)
Expand All @@ -1790,15 +1794,13 @@ DocumentBroker::asyncInstallPresets(SocketPoll& poll, const std::string& userSet
const std::string uriAnonym = COOLWSD::anonymizeUrl(userSettingsUri);
LOG_DBG("Getting settings from [" << uriAnonym << ']');

std::string configId = Cache::getConfigId(userSettingsUri);

auto presetTasks = std::make_shared<PresetsInstallTask>(poll, configId, presetsPath,
installFinishedCB);

// When result arrives, extract uris of what we want to install to the jail's user presets
// and async download and install those.
http::Session::FinishedCallback finishedCallback =
[configId, uriAnonym, presetsPath, presetTasks,
[uriAnonym, presetsPath, presetTasks,
session](const std::shared_ptr<http::Session>& configSession)
{
if (SigUtil::getShutdownRequestFlag())
Expand Down
5 changes: 4 additions & 1 deletion wsd/DocumentBroker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ class DocumentBroker : public std::enable_shared_from_this<DocumentBroker>

#if !MOBILEAPP
void asyncInstallPresets(const std::shared_ptr<ClientSession>& session,
const std::string& configId,
const std::string& userSettingsUri,
const std::string& presetsPath);

Expand All @@ -569,7 +570,9 @@ class DocumentBroker : public std::enable_shared_from_this<DocumentBroker>

/// Start an asynchronous Installation of the user presets, e.g. autotexts etc, as
/// described at userSettingsUri for installation into presetsPath
static std::shared_ptr<PresetsInstallTask> asyncInstallPresets(SocketPoll& poll, const std::string& userSettingsUri,
static std::shared_ptr<PresetsInstallTask> asyncInstallPresets(SocketPoll& poll,
const std::string& configId,
const std::string& userSettingsUri,
const std::string& presetsPath,
const std::shared_ptr<ClientSession>& session,
const std::function<void(bool)>& finishedCB);
Expand Down
5 changes: 3 additions & 2 deletions wsd/RequestVettingStation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class SharedSettings
if (auto settingsJSON = wopiInfo->getObject("SharedSettings"))
{
JsonUtil::findJSONValue(settingsJSON, "uri", _uri);
_configId = Cache::getConfigId(_uri);
_configId = "shared-" + Cache::getConfigId(_uri);

std::string stamp;
JsonUtil::findJSONValue(settingsJSON, "stamp", stamp);
Expand Down Expand Up @@ -215,7 +215,8 @@ void RequestVettingStation::launchInstallPresets()
// if this wopi server has some shared settings we want to have a subForKit for those settings
std::string presetsPath = Poco::Path(COOLWSD::ChildRoot, JailUtil::CHILDROOT_TMP_SHARED_PRESETS_PATH).toString();
// ensure the server config is downloaded and populate a subforkit when config is available
DocumentBroker::asyncInstallPresets(*_poll, sharedSettings.getUri(), presetsPath, nullptr, finishedCallback);
DocumentBroker::asyncInstallPresets(*_poll, configId, sharedSettings.getUri(), presetsPath,
nullptr, finishedCallback);
}

#endif
Expand Down

0 comments on commit 53999e1

Please sign in to comment.