| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2007, 2008, 2011, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2007, 2008, 2011, 2012 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2012 Research In Motion Limited. All rights reserved. | 3 * Copyright (C) 2012 Research In Motion Limited. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 AtomicallyInitializedStaticReference(DefaultPortsMap, defaultPorts, new Defa
ultPortsMap()); | 44 AtomicallyInitializedStaticReference(DefaultPortsMap, defaultPorts, new Defa
ultPortsMap()); |
| 45 if (defaultPorts.isEmpty()) { | 45 if (defaultPorts.isEmpty()) { |
| 46 defaultPorts.set("http", 80); | 46 defaultPorts.set("http", 80); |
| 47 defaultPorts.set("https", 443); | 47 defaultPorts.set("https", 443); |
| 48 defaultPorts.set("ftp", 21); | 48 defaultPorts.set("ftp", 21); |
| 49 defaultPorts.set("ftps", 990); | 49 defaultPorts.set("ftps", 990); |
| 50 } | 50 } |
| 51 return defaultPorts.get(protocol) == port; | 51 return defaultPorts.get(protocol) == port; |
| 52 } | 52 } |
| 53 | 53 |
| 54 bool portAllowed(const KURL& url) | |
| 55 { | |
| 56 unsigned short port = url.port(); | |
| 57 | |
| 58 // Since most URLs don't have a port, return early for the "no port" case. | |
| 59 if (!port) | |
| 60 return true; | |
| 61 | |
| 62 // This blocked port list matches the port blocking that Mozilla implements. | |
| 63 // See http://www.mozilla.org/projects/netlib/PortBanning.html for more info
rmation. | |
| 64 static const unsigned short blockedPortList[] = { | |
| 65 1, // tcpmux | |
| 66 7, // echo | |
| 67 9, // discard | |
| 68 11, // systat | |
| 69 13, // daytime | |
| 70 15, // netstat | |
| 71 17, // qotd | |
| 72 19, // chargen | |
| 73 20, // FTP-data | |
| 74 21, // FTP-control | |
| 75 22, // SSH | |
| 76 23, // telnet | |
| 77 25, // SMTP | |
| 78 37, // time | |
| 79 42, // name | |
| 80 43, // nicname | |
| 81 53, // domain | |
| 82 77, // priv-rjs | |
| 83 79, // finger | |
| 84 87, // ttylink | |
| 85 95, // supdup | |
| 86 101, // hostriame | |
| 87 102, // iso-tsap | |
| 88 103, // gppitnp | |
| 89 104, // acr-nema | |
| 90 109, // POP2 | |
| 91 110, // POP3 | |
| 92 111, // sunrpc | |
| 93 113, // auth | |
| 94 115, // SFTP | |
| 95 117, // uucp-path | |
| 96 119, // nntp | |
| 97 123, // NTP | |
| 98 135, // loc-srv / epmap | |
| 99 139, // netbios | |
| 100 143, // IMAP2 | |
| 101 179, // BGP | |
| 102 389, // LDAP | |
| 103 465, // SMTP+SSL | |
| 104 512, // print / exec | |
| 105 513, // login | |
| 106 514, // shell | |
| 107 515, // printer | |
| 108 526, // tempo | |
| 109 530, // courier | |
| 110 531, // Chat | |
| 111 532, // netnews | |
| 112 540, // UUCP | |
| 113 556, // remotefs | |
| 114 563, // NNTP+SSL | |
| 115 587, // ESMTP | |
| 116 601, // syslog-conn | |
| 117 636, // LDAP+SSL | |
| 118 993, // IMAP+SSL | |
| 119 995, // POP3+SSL | |
| 120 2049, // NFS | |
| 121 3659, // apple-sasl / PasswordServer [Apple addition] | |
| 122 4045, // lockd | |
| 123 6000, // X11 | |
| 124 6665, // Alternate IRC [Apple addition] | |
| 125 6666, // Alternate IRC [Apple addition] | |
| 126 6667, // Standard IRC [Apple addition] | |
| 127 6668, // Alternate IRC [Apple addition] | |
| 128 6669, // Alternate IRC [Apple addition] | |
| 129 0xFFFF, // Used to block all invalid port numbers | |
| 130 }; | |
| 131 const unsigned short* const blockedPortListEnd = blockedPortList + WTF_ARRAY
_LENGTH(blockedPortList); | |
| 132 | |
| 133 #if ENABLE(ASSERT) | |
| 134 // The port list must be sorted for binary_search to work. | |
| 135 static bool checkedPortList = false; | |
| 136 if (!checkedPortList) { | |
| 137 for (const unsigned short* p = blockedPortList; p != blockedPortListEnd
- 1; ++p) | |
| 138 ASSERT(*p < *(p + 1)); | |
| 139 checkedPortList = true; | |
| 140 } | |
| 141 #endif | |
| 142 | |
| 143 // If the port is not in the blocked port list, allow it. | |
| 144 if (!std::binary_search(blockedPortList, blockedPortListEnd, port)) | |
| 145 return true; | |
| 146 | |
| 147 // Allow ports 21 and 22 for FTP URLs, as Mozilla does. | |
| 148 if ((port == 21 || port == 22) && url.protocolIs("ftp")) | |
| 149 return true; | |
| 150 | |
| 151 // Allow any port number in a file URL, since the port number is ignored. | |
| 152 if (url.protocolIs("file")) | |
| 153 return true; | |
| 154 | |
| 155 return false; | |
| 156 } | 54 } |
| 157 | |
| 158 } | |
| OLD | NEW |