Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Implementation/Common/common_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,35 @@ namespace AMCCommon {
return true;
}

bool CUtils::stringIsValidFileName(const std::string& sFileName)
{
if (sFileName.empty())
return false;

if (sFileName.find(":") != std::string::npos)
return false;
if (sFileName.find(">") != std::string::npos)
return false;
if (sFileName.find("<") != std::string::npos)
return false;
if (sFileName.find("\"") != std::string::npos)
return false;
if (sFileName.find("/") != std::string::npos)
return false;
if (sFileName.find("\\") != std::string::npos)
return false;
if (sFileName.find("|") != std::string::npos)
return false;
if (sFileName.find("?") != std::string::npos)
return false;
if (sFileName.find("*") != std::string::npos)
return false;
if (sFileName.find("..") != std::string::npos)
return false;

return true;
}

bool CUtils::stringIsUUIDString(const std::string& sRawString)
{
std::string sTrimmedString = trimString(sRawString);
Expand Down
1 change: 1 addition & 0 deletions Implementation/Common/common_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ namespace AMCCommon {

static bool stringIsValidAlphanumericNameString(const std::string& sString); // Only alphanumeric characters and underscore, underscore not as first character!
static bool stringIsValidAlphanumericPathString(const std::string& sString); // Only alphanumeric name strings separated by dots
static bool stringIsValidFileName(const std::string& sFileName); // No path delimiters or reserved characters

static std::string getCurrentUserHomeDirectory();
static std::string getTempFolder();
Expand Down
4 changes: 2 additions & 2 deletions Implementation/LibMCData/libmcdata_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ void CStorage::CreateDownloadTicket(const std::string& sTicketUUID, const std::s
if (sClientFileName.empty())
throw ELibMCDataInterfaceException(LIBMCDATA_ERROR_EMPTYCLIENTFILENAME);

// TODO: Check invalid file name?
if (!AMCCommon::CUtils::stringIsValidFileName(sClientFileName))
throw ELibMCDataInterfaceException(LIBMCDATA_ERROR_INVALIDCLIENTFILENAME, "invalid client file name: " + sClientFileName);

auto pTransaction = m_pSQLHandler->beginTransaction();

Expand Down Expand Up @@ -527,4 +528,3 @@ void CStorage::AttachStreamToJournal(const std::string& sStreamUUID, const std::

pTransaction->commit();
}

15 changes: 13 additions & 2 deletions Implementation/LibMCEnv/libmcenv_uienvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Abstract: This is a stub class definition of CUIEnvironment
#include "libmcenv_zipstreamwriter.hpp"
#include "libmcenv_imageloader.hpp"
#include "libmcenv_machineconfigurationhandler.hpp"
#include "libmcdata_interfaceexception.hpp"

#include "amc_systemstate.hpp"
#include "amc_accesscontrol.hpp"
Expand Down Expand Up @@ -174,6 +175,9 @@ void CUIEnvironment::StartStreamDownload(const std::string& sUUID, const std::st
if (sFilename.size () > DOWNLOADFILENAME_MAXLENGTH)
throw ELibMCEnvInterfaceException(LIBMCENV_ERROR_INVALIDDOWNLOADSTREAMFILENAME);

if (!AMCCommon::CUtils::stringIsValidFileName(sFilename))
throw ELibMCEnvInterfaceException(LIBMCENV_ERROR_INVALIDDOWNLOADSTREAMFILENAME, "invalid download stream filename: " + sFilename);

if (!m_pAPIAuth->userIsAuthorized ())
throw ELibMCEnvInterfaceException(LIBMCENV_ERROR_USERISNOTAUTHORIZED);

Expand All @@ -182,7 +186,14 @@ void CUIEnvironment::StartStreamDownload(const std::string& sUUID, const std::st
auto pGlobalChrono = m_pUISystemState->getGlobalChronoInstance();

std::string sTicketUUID = m_pAPIAuth->createStreamDownloadTicket (sNormalizedUUID, sFilename);
pStorage->CreateDownloadTicket (sTicketUUID, sNormalizedUUID, sFilename, m_pAPIAuth->getSessionUUID (), sUserUUID, pGlobalChrono->getUTCTimeStampInMicrosecondsSince1970 ());
try {
pStorage->CreateDownloadTicket (sTicketUUID, sNormalizedUUID, sFilename, m_pAPIAuth->getSessionUUID (), sUserUUID, pGlobalChrono->getUTCTimeStampInMicrosecondsSince1970 ());
}
catch (ELibMCDataInterfaceException & E) {
if (E.getErrorCode() == LIBMCDATA_ERROR_INVALIDCLIENTFILENAME)
throw ELibMCEnvInterfaceException(LIBMCENV_ERROR_INVALIDDOWNLOADSTREAMFILENAME, E.what());
throw;
}

m_ClientActions.push_back(std::make_shared<AMC::CUIClientAction_StreamDownload>(sTicketUUID, sFilename));
}
Expand Down Expand Up @@ -1097,4 +1108,4 @@ IJSONObject* CUIEnvironment::ParseJSONData(const LibMCEnv_uint64 nJSONDataBuffer
IMachineConfigurationHandler* CUIEnvironment::CreateMachineConfigurationHandler()
{
return new CMachineConfigurationHandler(m_pUISystemState->getDataModel());
}
}
Loading