Skip to content

Commit

Permalink
Fix #1071: remove mtalocal URL scheme and error out on bad usage
Browse files Browse the repository at this point in the history
  • Loading branch information
patrikjuvonen committed Sep 21, 2019
1 parent a26417f commit c4c01e2
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 63 deletions.
6 changes: 0 additions & 6 deletions Client/ceflauncher_DLL/CCefApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ class CCefApp : public CefApp, public CefRenderProcessHandler
}
}

virtual void OnRegisterCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar) override
{
// Register custom MTA scheme (has to be called in all proceseses)
registrar->AddCustomScheme("mtalocal", CEF_SCHEME_OPTION_CSP_BYPASSING);
}

// http://magpcss.org/ceforum/apidocs3/projects/(default)/CefRenderProcessHandler.html#OnContextCreated(CefRefPtr%3CCefBrowser%3E,CefRefPtr%3CCefFrame%3E,CefRefPtr%3CCefV8Context%3E)
// //
virtual void OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) override
Expand Down
32 changes: 0 additions & 32 deletions Client/cefweb/CWebApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ CefRefPtr<CefResourceHandler> CWebApp::HandleError(const SString& strError, unsi
return new CefStreamResourceHandler(uiError, strError, "text/plain", CefResponse::HeaderMap(), stream);
}

void CWebApp::OnRegisterCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar)
{
// Register custom MTA scheme (has to be called in all proceseses)
registrar->AddCustomScheme("mtalocal", CEF_SCHEME_OPTION_CSP_BYPASSING);
}

void CWebApp::OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr<CefCommandLine> command_line)
{
command_line->AppendSwitch("disable-gpu-compositing");
Expand Down Expand Up @@ -53,32 +47,6 @@ CefRefPtr<CefResourceHandler> CWebApp::Create(CefRefPtr<CefBrowser> browser, Cef
if (!CefParseURL(request->GetURL(), urlParts))
return nullptr;

if (scheme_name == "mtalocal") // Backward compatibility
{
// Get full path
SString path = UTF16ToMbUTF8(urlParts.path.str).substr(2);

// Check if we're dealing with an external resource
if (path[0] == ':')
{
size_t end = path.find_first_of('/');
if (end != std::string::npos)
{
SString resourceName = path.substr(1, end - 1);
SString resourcePath = path.substr(end);

// Call this function recursively and use the mta scheme instead
request->SetURL("http://mta/local/" + resourceName + resourcePath);
return Create(browser, frame, "http", request);
}
return HandleError("404 - Not found", 404);
}

// Redirect mtalocal://* to http://mta/local/*, call recursively
request->SetURL("http://mta/local/" + path);
return Create(browser, frame, "http", request);
}

SString host = UTF16ToMbUTF8(urlParts.host.str);
if (scheme_name == "http" && host == "mta")
{
Expand Down
1 change: 0 additions & 1 deletion Client/cefweb/CWebApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class CWebApp : public CefApp, public CefSchemeHandlerFactory
// Error Handler
static CefRefPtr<CefResourceHandler> HandleError(const SString& strError, unsigned int uiError);

virtual void OnRegisterCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar) override;
virtual void OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr<CefCommandLine> command_line) override;

// CefSchemeHandlerFactory methods
Expand Down
1 change: 0 additions & 1 deletion Client/cefweb/CWebCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ bool CWebCore::Initialise()
bool state = CefInitialize(mainArgs, settings, app, sandboxInfo);

// Register custom scheme handler factory
CefRegisterSchemeHandlerFactory("mtalocal", "", app);
CefRegisterSchemeHandlerFactory("http", "mta", app);

return state;
Expand Down
4 changes: 1 addition & 3 deletions Client/cefweb/CWebView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,8 +810,6 @@ bool CWebView::OnBeforeBrowse(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame>
else
bResult = false;
}
else if (scheme == L"mtalocal")
bResult = false; // Allow mtalocal:// URLs
else
bResult = true; // Block other schemes

Expand Down Expand Up @@ -887,7 +885,7 @@ CefResourceRequestHandler::ReturnValue CWebView::OnBeforeResourceLoad(CefRefPtr<
else
return RV_CONTINUE;
}
else if (scheme == L"mtalocal" || scheme == L"blob")
else if (scheme == L"blob")
{
return RV_CONTINUE;
}
Expand Down
26 changes: 6 additions & 20 deletions Client/mods/deathmatch/logic/luadefs/CLuaBrowserDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,28 +251,14 @@ int CLuaBrowserDefs::LoadBrowserURL(lua_State* luaVM)
lua_pushboolean(luaVM, pWebBrowser->LoadURL(strURL, !isLocalURL, strPostData, bURLEncoded));
return 1;
}

// Are we dealing with a local website? If so, parse resource path. Otherwise, return false and load nothing
// Todo: Add an ACL right which is necessary to load local websites or websites in general
CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine(luaVM);
if (pLuaMain)
else
{
SString strAbsPath;
CResource* pResource = pLuaMain->GetResource();
if (CResourceManager::ParseResourcePathInput(strURL, pResource, &strAbsPath) && pWebBrowser->IsLocal())
{
// Output deprecated warning, TODO: Remove this at a later point
m_pScriptDebugging->LogWarning(luaVM,
"This URL scheme is deprecated and may not work in future versions. Please consider using http://mta/* instead. "
"See https://wiki.mtasa.com/wiki/LoadBrowserURL for details");

lua_pushboolean(luaVM, pWebBrowser->LoadURL("mtalocal://" + strURL, false, strPostData, bURLEncoded));
return 1;
}
argStream.SetCustomError("Invalid URL scheme provided. Only http:// and https:// is supported.", "Invalid parameter");
}
}
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());

if (argStream.HasErrors())
return luaL_error(luaVM, argStream.GetFullErrorMessage());

lua_pushboolean(luaVM, false);
return 1;
Expand Down Expand Up @@ -938,7 +924,7 @@ int CLuaBrowserDefs::GUICreateBrowser(lua_State* luaVM)
}
}
}

if (argStream.HasErrors())
return luaL_error(luaVM, argStream.GetFullErrorMessage());

Expand Down

0 comments on commit c4c01e2

Please sign in to comment.