Skip to content

Commit 94674c9

Browse files
filipe-norte-redmagomez
authored andcommitted
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 f1dd8ad commit 94674c9

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
@@ -996,6 +996,32 @@ const URL& aboutSrcDocURL()
996996
return staticSrcDocURL;
997997
}
998998

999+
static bool protocolIsWhitelistedForAllPortsAcccess(StringView protocol)
1000+
{
1001+
static Vector<String> s_protocolsWhitelisted;
1002+
static std::once_flag s_onceFlag;
1003+
std::call_once(s_onceFlag,
1004+
[] {
1005+
// The env var contains a comma separated list of protocols that need to have
1006+
// access to all ports.
1007+
// Example: WPE_WHITELIST_ALL_PORTS_FOR_PROTOCOLS="dvb,echo,custom"
1008+
String s(String::fromLatin1(std::getenv("WPE_WHITELIST_ALL_PORTS_FOR_PROTOCOLS")));
1009+
if (s.isEmpty())
1010+
return;
1011+
1012+
s_protocolsWhitelisted.appendVector(s.convertToASCIILowercase().split(','));
1013+
1014+
const Vector<String> excludeFromWhitelist( { "http"_s, "https"_s, "ws"_s, "wss"_s, "ftp"_s, "ftps"_s} );
1015+
1016+
// Ensure reserved protocols are not whitelisted
1017+
s_protocolsWhitelisted.removeAllMatching([&](const auto& protocol) {
1018+
return excludeFromWhitelist.contains(protocol);
1019+
});
1020+
});
1021+
1022+
return s_protocolsWhitelisted.contains(protocol.convertToASCIILowercase());
1023+
}
1024+
9991025
bool portAllowed(const URL& url)
10001026
{
10011027
std::optional<uint16_t> port = url.port();
@@ -1004,6 +1030,9 @@ bool portAllowed(const URL& url)
10041030
if (!port)
10051031
return true;
10061032

1033+
if (protocolIsWhitelistedForAllPortsAcccess(url.protocol()))
1034+
return true;
1035+
10071036
// This blocked port list matches the port blocking that Mozilla implements.
10081037
// See http://www.mozilla.org/projects/netlib/PortBanning.html for more information.
10091038
static const uint16_t blockedPortList[] = {

0 commit comments

Comments
 (0)