Skip to content

Commit 30f2909

Browse files
Support unrestricted ports usage for custom URI schemes
Some custom URI schemes may assign a different meaning to the port of an URI. Webkit restricts, by default, usage of certain ports. To bypass the check, an env var allows specifying which protocols shall be allowed unrestricted ports usage. Some network based protocols (e.g. http, https, and others) are kept still restricted.
1 parent 039ccfe commit 30f2909

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

Source/WTF/wtf/URL.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,32 @@ const URL& aboutSrcDocURL()
988988
return staticSrcDocURL;
989989
}
990990

991+
static bool protocolIsWhitelistedForAllPortsAcccess(StringView protocol)
992+
{
993+
static Vector<String> s_protocolsWhitelisted;
994+
static std::once_flag s_onceFlag;
995+
std::call_once(s_onceFlag,
996+
[] {
997+
// The env var contains a comma separated list of protocols that need to have
998+
// access to all ports.
999+
// Example: WPE_WHITELIST_ALL_PORTS_FOR_PROTOCOLS="dvb,echo,custom"
1000+
String s(String::fromLatin1(std::getenv("WPE_WHITELIST_ALL_PORTS_FOR_PROTOCOLS")));
1001+
if (s.isEmpty())
1002+
return;
1003+
1004+
s_protocolsWhitelisted.appendVector(s.convertToASCIILowercase().split(','));
1005+
1006+
const Vector<String> excludeFromWhitelist( { "http"_s, "https"_s, "ws"_s, "wss"_s, "ftp"_s, "ftps"_s} );
1007+
1008+
// Ensure reserved protocols are not whitelisted
1009+
s_protocolsWhitelisted.removeAllMatching([&](const auto& protocol) {
1010+
return excludeFromWhitelist.contains(protocol);
1011+
});
1012+
});
1013+
1014+
return s_protocolsWhitelisted.contains(protocol.convertToASCIILowercase());
1015+
}
1016+
9911017
bool portAllowed(const URL& url)
9921018
{
9931019
std::optional<uint16_t> port = url.port();
@@ -996,6 +1022,9 @@ bool portAllowed(const URL& url)
9961022
if (!port)
9971023
return true;
9981024

1025+
if (protocolIsWhitelistedForAllPortsAcccess(url.protocol()))
1026+
return true;
1027+
9991028
// This blocked port list matches the port blocking that Mozilla implements.
10001029
// See http://www.mozilla.org/projects/netlib/PortBanning.html for more information.
10011030
static const uint16_t blockedPortList[] = {

0 commit comments

Comments
 (0)