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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ target_sources(
cef-headers.hpp
deps/base64/base64.cpp
deps/base64/base64.hpp
deps/ip-string.hpp
deps/signal-restore.cpp
deps/signal-restore.hpp
deps/wide-string.cpp
Expand Down
3 changes: 2 additions & 1 deletion browser-app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ CefRefPtr<CefBrowserProcessHandler> BrowserApp::GetBrowserProcessHandler()

void BrowserApp::OnRegisterCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar)
{
registrar->AddCustomScheme("http", CEF_SCHEME_OPTION_STANDARD | CEF_SCHEME_OPTION_CORS_ENABLED);
registrar->AddCustomScheme("obsbrowser", CEF_SCHEME_OPTION_STANDARD | CEF_SCHEME_OPTION_CORS_ENABLED |
CEF_SCHEME_OPTION_FETCH_ENABLED);
}

void BrowserApp::OnBeforeChildProcessLaunch(CefRefPtr<CefCommandLine> command_line)
Expand Down
35 changes: 23 additions & 12 deletions browser-scheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
******************************************************************************/

#include "browser-scheme.hpp"
#include "ip-string.hpp"
#include "wide-string.hpp"
#include <include/wrapper/cef_stream_resource_handler.h>

Expand All @@ -41,18 +42,28 @@ CefRefPtr<CefResourceHandler> BrowserSchemeHandlerFactory::Create(CefRefPtr<CefB
if (fileExtension.compare("woff2") == 0)
fileExtension = "woff";

#ifdef _WIN32
CefRefPtr<CefStreamReader> stream = CefStreamReader::CreateForFile(path.substr(1));
#else
CefRefPtr<CefStreamReader> stream = CefStreamReader::CreateForFile(path);
#endif

if (stream) {
CefString mimeType = CefGetMimeType(fileExtension);
if (mimeType.empty())
mimeType = "application/octet-stream";
return new CefStreamResourceHandler(mimeType, stream);
} else {
std::string filePath = path.substr(path.find_first_not_of("/"));
std::string checkString = filePath.substr(0, filePath.find_first_of("/"));

// An IP address should never be a valid path for CreateForFile normally, but in some cases an OS
// can resolve one as such. As an extra safeguard, we prevent any IP addresses in the path.
if (checkForIpv4String(checkString)) {
return nullptr;
}

if (checkForIpv6String(checkString)) {
return nullptr;
}

CefRefPtr<CefStreamReader> stream = CefStreamReader::CreateForFile(filePath);
if (!stream) {
return nullptr;
}

CefString mimeType = CefGetMimeType(fileExtension);
if (mimeType.empty()) {
mimeType = "application/octet-stream";
}

return new CefStreamResourceHandler(mimeType, stream);
}
2 changes: 2 additions & 0 deletions cmake/os-linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ target_include_directories(browser-helper PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/d

target_link_libraries(browser-helper PRIVATE CEF::Wrapper CEF::Library)

target_sources(obs-browser PRIVATE deps/ip-string.cpp)

set(OBS_EXECUTABLE_DESTINATION "${OBS_PLUGIN_DESTINATION}")

# cmake-format: off
Expand Down
2 changes: 2 additions & 0 deletions cmake/os-macos.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ foreach(helper IN LISTS helper_suffixes)
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/macos/entitlements-helper${helper_plist}.plist")
endforeach()

target_sources(obs-browser PRIVATE deps/ip-string.cpp)

set_target_properties(
obs-browser
PROPERTIES AUTOMOC ON
Expand Down
3 changes: 3 additions & 0 deletions cmake/os-windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ target_compile_definitions(obs-browser-helper PRIVATE ENABLE_BROWSER_SHARED_TEXT
target_link_libraries(obs-browser-helper PRIVATE CEF::Wrapper CEF::Library nlohmann_json::nlohmann_json)
target_link_options(obs-browser-helper PRIVATE /IGNORE:4099 /SUBSYSTEM:WINDOWS)

target_link_libraries(obs-browser PRIVATE Ws2_32)
target_sources(obs-browser PRIVATE deps/ip-string-windows.cpp)

set(OBS_EXECUTABLE_DESTINATION "${OBS_PLUGIN_DESTINATION}")
set_target_properties_obs(
obs-browser-helper
Expand Down
35 changes: 35 additions & 0 deletions deps/ip-string-posix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/******************************************************************************
Copyright (C) 2026 by Warchamp7 <[email protected]>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

#include "ip-string.hpp"

#include <arpa/inet.h>
#include <stdio.h>

bool checkForIpv4String(const std::string &path)
{
sockaddr_in sa4;

return inet_pton(AF_INET, path.c_str(), &sa4.sin_addr) == 1;
}

bool checkForIpv6String(const std::string &path)
{
sockaddr_in6 sa6;

return inet_pton(AF_INET6, path.c_str(), &sa6.sin6_addr) == 1;
}
37 changes: 37 additions & 0 deletions deps/ip-string-windows.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/******************************************************************************
Copyright (C) 2026 by Warchamp7 <[email protected]>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

#include "ip-string.hpp"

#include <stdio.h>
#define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#include <ws2tcpip.h>

bool checkForIpv4String(const std::string &path)
{
sockaddr_in sa4;

return inet_pton(AF_INET, path.c_str(), &sa4.sin_addr) == 1;
}

bool checkForIpv6String(const std::string &path)
{
sockaddr_in6 sa6;

return inet_pton(AF_INET6, path.c_str(), &sa6.sin6_addr) == 1;
}
23 changes: 23 additions & 0 deletions deps/ip-string.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/******************************************************************************
Copyright (C) 2026 by Warchamp7 <[email protected]>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

#pragma once

#include <string>

extern bool checkForIpv4String(const std::string &path);
extern bool checkForIpv6String(const std::string &path);
5 changes: 2 additions & 3 deletions obs-browser-plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,8 @@ static void BrowserInit(void)
return;
}

/* Register http://absolute/ scheme handler for older
* CEF builds which do not support file:// URLs */
CefRegisterSchemeHandlerFactory("http", "absolute", new BrowserSchemeHandlerFactory());
// Register custom scheme handler for local browser sources
CefRegisterSchemeHandlerFactory("obsbrowser", "file", new BrowserSchemeHandlerFactory());

os_event_signal(cef_started_event);
}
Expand Down
4 changes: 2 additions & 2 deletions obs-browser-source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,8 @@ void BrowserSource::Update(obs_data_t *settings)
while (n_url.find("%2F") != std::string::npos)
n_url.replace(n_url.find("%2F"), 3, "/");

/* http://absolute/ based mapping for older CEF */
n_url = "http://absolute/" + n_url;
// Local files are routed through our custom scheme handler to give them acess to other local files
n_url = "obsbrowser://file/" + n_url;
}

if (n_is_local == is_local && n_fps_custom == fps_custom && n_fps == fps &&
Expand Down