Skip to content

Commit 2b00ed2

Browse files
author
Rémi Denis-Courmont
committed
http: block special ports
This follows the defacto standard list of blocked ports for web browsing (see also "Mozilla Port Blocking").
1 parent 2f18f55 commit 2b00ed2

File tree

4 files changed

+119
-0
lines changed

4 files changed

+119
-0
lines changed

modules/access/http/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ libvlc_http_la_SOURCES = \
1212
access/http/h2frame.c access/http/h2frame.h \
1313
access/http/h2output.c access/http/h2output.h \
1414
access/http/h2conn.c access/http/h1conn.c \
15+
access/http/ports.c \
1516
access/http/chunked.c access/http/tunnel.c access/http/conn.h \
1617
access/http/connmgr.c access/http/connmgr.h
1718
libvlc_http_la_CPPFLAGS = -Dneedsomethinghere

modules/access/http/connmgr.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ struct vlc_http_msg *vlc_http_mgr_request(struct vlc_http_mgr *mgr, bool https,
260260
const char *host, unsigned port,
261261
const struct vlc_http_msg *m)
262262
{
263+
if (port && vlc_http_port_blocked(port))
264+
return NULL;
265+
263266
return (https ? vlc_https_request : vlc_http_request)(mgr, host, port, m);
264267
}
265268

modules/access/http/ports.c

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*****************************************************************************
2+
* ports.c: special ports block list
3+
*****************************************************************************
4+
* Copyright © 2019 Rémi Denis-Courmont
5+
*
6+
* This program is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU Lesser General Public License as published by
8+
* the Free Software Foundation; either version 2.1 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19+
*****************************************************************************/
20+
21+
#ifdef HAVE_CONFIG_H
22+
# include <config.h>
23+
#endif
24+
25+
#include <stdbool.h>
26+
#include <stdlib.h>
27+
#include "transport.h"
28+
#include <vlc_common.h>
29+
30+
/* Must be in ascending order */
31+
static const unsigned short blocked_ports[] = {
32+
1, // tcpmux
33+
7, // echo
34+
9, // discard
35+
11, // systat
36+
13, // daytime
37+
15, // netstat
38+
17, // QOTD
39+
19, // character generator
40+
20, // FTP data
41+
21, // FTP access
42+
22, // SSH
43+
23, // Telnet
44+
25, // SMTP
45+
37, // time
46+
42, // name
47+
43, // nicname
48+
53, // DNS
49+
77, // priv-rjs
50+
79, // finger
51+
87, // ttylink
52+
95, // supdup
53+
101, // hostriame
54+
102, // iso-tsap
55+
103, // gppitnp
56+
104, // acr-nema
57+
109, // POP2
58+
110, // POP3
59+
111, // Sun RPC
60+
113, // auth
61+
115, // SFTP
62+
117, // UUCP path service
63+
119, // NNTP (i.e. Usenet)
64+
123, // NTP
65+
135, // DCE endpoint resolution
66+
139, // NetBIOS
67+
143, // IMAP2
68+
179, // BGP
69+
389, // LDAP
70+
465, // SMTP/TLS
71+
512, // remote exec
72+
513, // remote login
73+
514, // remote shell
74+
515, // printer
75+
526, // tempo
76+
530, // courier
77+
531, // chat
78+
532, // netnews
79+
540, // UUCP
80+
556, // remotefs
81+
563, // NNTP/TLS
82+
587, // Submission (i.e. first hop SMTP)
83+
601, // rsyslog
84+
636, // LDAP/TLS
85+
993, // LDAP/TLS
86+
995, // POP3/TLS
87+
2049, // NFS
88+
3659, // Apple SASL
89+
4045, // NFS RPC lockd
90+
6000, // X11
91+
6665, // IRC
92+
6666, // IRC
93+
6667, // IRC
94+
6668, // IRC
95+
6669, // IRC
96+
};
97+
98+
static int portcmp(const void *key, const void *entry)
99+
{
100+
const unsigned *port = key;
101+
const unsigned short *blocked_port = entry;
102+
103+
return ((int)*port) - ((int)*blocked_port);
104+
}
105+
106+
bool vlc_http_port_blocked(unsigned port)
107+
{
108+
if (port > 0xffff)
109+
return true;
110+
111+
return bsearch(&port, blocked_ports, ARRAY_SIZE(blocked_ports),
112+
sizeof (unsigned short), portcmp) != NULL;
113+
}

modules/access/http/transport.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@ struct vlc_tls *vlc_https_connect_proxy(void *ctx,
3434
struct vlc_tls_client *creds,
3535
const char *name, unsigned port,
3636
bool *restrict two, const char *proxy);
37+
bool vlc_http_port_blocked(unsigned port);
38+
3739
#endif

0 commit comments

Comments
 (0)