@@ -907,6 +907,32 @@ bool URL::protocolIsAbout() const
907907 return protocolIs (" about" _s);
908908}
909909
910+ static bool protocolIsWhitelistedForAllPortsAcccess (StringView protocol)
911+ {
912+ static Vector<String> s_protocolsWhitelisted;
913+ static std::once_flag s_onceFlag;
914+ std::call_once (s_onceFlag,
915+ [] {
916+ // The env var contains a comma separated list of protocols that need to have
917+ // access to all ports.
918+ // Example: WPE_WHITELIST_ALL_PORTS_FOR_PROTOCOLS="dvb,echo,custom"
919+ String s (String::fromLatin1 (std::getenv (" WPE_WHITELIST_ALL_PORTS_FOR_PROTOCOLS" )));
920+ if (s.isEmpty ())
921+ return ;
922+
923+ s_protocolsWhitelisted.appendVector (s.convertToASCIILowercase ().split (' ,' ));
924+
925+ const Vector<String> excludeFromWhitelist ( { " http" _s, " https" _s, " ws" _s, " wss" _s, " ftp" _s, " ftps" _s} );
926+
927+ // Ensure reserved protocols are not whitelisted
928+ s_protocolsWhitelisted.removeAllMatching ([&](const auto & protocol) {
929+ return excludeFromWhitelist.contains (protocol);
930+ });
931+ });
932+
933+ return s_protocolsWhitelisted.contains (protocol.convertToASCIILowercase ());
934+ }
935+
910936bool portAllowed (const URL& url)
911937{
912938 std::optional<uint16_t > port = url.port ();
@@ -915,6 +941,9 @@ bool portAllowed(const URL& url)
915941 if (!port)
916942 return true ;
917943
944+ if (protocolIsWhitelistedForAllPortsAcccess (url.protocol ()))
945+ return true ;
946+
918947 // This blocked port list matches the port blocking that Mozilla implements.
919948 // See http://www.mozilla.org/projects/netlib/PortBanning.html for more information.
920949 static const uint16_t blockedPortList[] = {
0 commit comments