Skip to content

Commit 17a3d7d

Browse files
committed
sanitize the log filename
* do not allow path separator
1 parent 9a9bf97 commit 17a3d7d

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

obs-studio-server/source/nodeobs_api.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,17 @@ void addModulePaths()
835835
#endif
836836
}
837837

838+
std::filesystem::path sanitize_path(const std::filesystem::path &input)
839+
{
840+
std::filesystem::path normalized = input.lexically_normal();
841+
842+
if (normalized.is_absolute() || normalized.string().find("..") != std::string::npos) {
843+
throw std::runtime_error("Invalid path");
844+
}
845+
846+
return normalized;
847+
}
848+
838849
static void listEncoders(obs_encoder_type type)
839850
{
840851
constexpr uint32_t hide_flags = OBS_ENCODER_CAP_DEPRECATED | OBS_ENCODER_CAP_INTERNAL;
@@ -881,7 +892,7 @@ void OBS_API::OBS_API_initAPI(void *data, const int64_t id, const std::vector<ip
881892
if (logPath.size() > 0) {
882893
// Parse the log filename
883894
std::ostringstream ss;
884-
ss << logPath << '-' << GenerateTimeDateFilename("txt");
895+
ss << sanitize_path(logPath) << '-' << GenerateTimeDateFilename("txt");
885896
logFilename = ss.str();
886897
}
887898
}

0 commit comments

Comments
 (0)