Skip to content

Commit 19278f8

Browse files
summeroffclaude
andauthored
fix: validate recording output paths (#1755)
* Validate recording output directories * fix: report unsafe recording paths distinctly from invalid ones Splitting the empty-path and os_is_path_safe() checks lets the IPC error and the log line say which one tripped, so a rejected symlink/junction directory is diagnosable instead of just "Invalid recording path." Also switch osn-encoders.hpp to a quoted include, matching every other consumer of that header. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent c839169 commit 19278f8

4 files changed

Lines changed: 26 additions & 2 deletions

File tree

obs-studio-server/source/osn-advanced-recording.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
#include "shared.hpp"
2222
#include "osn-audio-track.hpp"
2323
#include "osn-file-output.hpp"
24-
#include <osn-encoders.hpp>
24+
#include "osn-encoders.hpp"
25+
#include <util/platform.h>
2526

2627
void osn::IAdvancedRecording::Register(ipc::server &srv)
2728
{
@@ -282,6 +283,14 @@ void osn::IAdvancedRecording::Start(void *data, const int64_t id, const std::vec
282283

283284
obs_output_set_video_encoder(recording->GetOutput(), recording->videoEncoder);
284285

286+
if (!recording->path.size()) {
287+
PRETTY_ERROR_RETURN(ErrorCode::InvalidReference, "Invalid recording path.");
288+
}
289+
290+
if (!os_is_path_safe(recording->path.c_str())) {
291+
PRETTY_ERROR_RETURN(ErrorCode::InvalidReference, "Unsafe recording path: symbolic links and junctions are not allowed.");
292+
}
293+
285294
std::string path = recording->path;
286295

287296
char lastChar = path.back();

obs-studio-server/source/osn-advanced-replay-buffer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "shared.hpp"
2323
#include "osn-audio-track.hpp"
2424
#include "osn-encoders.hpp"
25+
#include <util/platform.h>
2526

2627
void osn::IAdvancedReplayBuffer::Register(ipc::server &srv)
2728
{
@@ -205,6 +206,10 @@ void osn::IAdvancedReplayBuffer::Start(void *data, const int64_t id, const std::
205206
PRETTY_ERROR_RETURN(ErrorCode::InvalidReference, "Invalid recording path.");
206207
}
207208

209+
if (!os_is_path_safe(replayBuffer->path.c_str())) {
210+
PRETTY_ERROR_RETURN(ErrorCode::InvalidReference, "Unsafe recording path: symbolic links and junctions are not allowed.");
211+
}
212+
208213
const char *rbPrefix = replayBuffer->prefix.c_str();
209214
const char *rbSuffix = replayBuffer->suffix.c_str();
210215
int64_t rbSize = replayBuffer->usesStream ? 0 : 512;

obs-studio-server/source/osn-simple-recording.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "nodeobs_audio_encoders.h"
2525
#include "osn-file-output.hpp"
2626
#include "osn-encoders.hpp"
27+
#include <util/platform.h>
2728

2829
void osn::ISimpleRecording::Register(ipc::server &srv)
2930
{
@@ -401,6 +402,10 @@ void osn::ISimpleRecording::Start(void *data, const int64_t id, const std::vecto
401402
PRETTY_ERROR_RETURN(ErrorCode::InvalidReference, "Invalid recording path.");
402403
}
403404

405+
if (!os_is_path_safe(recording->path.c_str())) {
406+
PRETTY_ERROR_RETURN(ErrorCode::InvalidReference, "Unsafe recording path: symbolic links and junctions are not allowed.");
407+
}
408+
404409
std::string path = recording->path;
405410

406411
char lastChar = path.back();

obs-studio-server/source/osn-simple-replay-buffer.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "shared.hpp"
2323
#include "nodeobs_audio_encoders.h"
2424
#include "osn-encoders.hpp"
25+
#include <util/platform.h>
2526

2627
void osn::ISimpleReplayBuffer::Register(ipc::server &srv)
2728
{
@@ -147,6 +148,10 @@ void osn::ISimpleReplayBuffer::Start(void *data, const int64_t id, const std::ve
147148
PRETTY_ERROR_RETURN(ErrorCode::InvalidReference, "Invalid recording path.");
148149
}
149150

151+
if (!os_is_path_safe(replayBuffer->path.c_str())) {
152+
PRETTY_ERROR_RETURN(ErrorCode::InvalidReference, "Unsafe recording path: symbolic links and junctions are not allowed.");
153+
}
154+
150155
const char *rbPrefix = replayBuffer->prefix.c_str();
151156
const char *rbSuffix = replayBuffer->suffix.c_str();
152157
int64_t rbSize = replayBuffer->usesStream ? 0 : 512;
@@ -312,4 +317,4 @@ void osn::ISimpleReplayBuffer::SetRecording(void *data, const int64_t id, const
312317

313318
rval.push_back(ipc::value((uint64_t)ErrorCode::Ok));
314319
AUTO_DEBUG;
315-
}
320+
}

0 commit comments

Comments
 (0)