1717 ******************************************************************************/
1818
1919#include " browser-scheme.hpp"
20+ #include " ip-string.hpp"
2021#include " wide-string.hpp"
2122#include < include/wrapper/cef_stream_resource_handler.h>
2223
@@ -31,8 +32,15 @@ CefRefPtr<CefResourceHandler> BrowserSchemeHandlerFactory::Create(CefRefPtr<CefB
3132
3233 std::string path = CefString (&parts.path );
3334
34- path = CefURIDecode (path, true , cef_uri_unescape_rule_t ::UU_SPACES);
35- path = CefURIDecode (path, true , cef_uri_unescape_rule_t ::UU_URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS);
35+ // An IP address should never be a valid path for CreateForFile normally, but in some cases an OS
36+ // can resolve one as such. As an extra safeguard, we prevent any IP addresses in the path.
37+ if (checkForIpv4String (path)) {
38+ return nullptr ;
39+ }
40+
41+ if (checkForIpv6String (path)) {
42+ return nullptr ;
43+ }
3644
3745 std::string fileExtension = path.substr (path.find_last_of (" ." ) + 1 );
3846
@@ -41,11 +49,8 @@ CefRefPtr<CefResourceHandler> BrowserSchemeHandlerFactory::Create(CefRefPtr<CefB
4149 if (fileExtension.compare (" woff2" ) == 0 )
4250 fileExtension = " woff" ;
4351
44- #ifdef _WIN32
45- CefRefPtr<CefStreamReader> stream = CefStreamReader::CreateForFile (path.substr (1 ));
46- #else
47- CefRefPtr<CefStreamReader> stream = CefStreamReader::CreateForFile (path);
48- #endif
52+ std::string filePath = path.substr (path.find_first_of (" //file" ) + 7 );
53+ CefRefPtr<CefStreamReader> stream = CefStreamReader::CreateForFile (filePath);
4954
5055 if (stream) {
5156 CefString mimeType = CefGetMimeType (fileExtension);
0 commit comments