Skip to content

Commit cd90a77

Browse files
committed
Default connect_port to 443 only
CONNECT tunnels are restricted to port 443 by default. HTTP forwarding (GET/POST) is unaffected. Config entries replace the default.
1 parent 428db36 commit cd90a77

4 files changed

Lines changed: 12 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ See `thinproxy.conf.example` for a full example.
116116
| Directive | Description | Default |
117117
|-----------|-------------|---------|
118118
| `deny_private <yes\|no>` | Block connections to private/reserved addresses | `yes` |
119-
| `connect_port <port>` | Allowed CONNECT port (whitelist, repeatable) | all |
119+
| `connect_port <port>` | Allowed CONNECT port (whitelist, repeatable) | `443` |
120120
| `allow <ip[/prefix]>` | Allow source address (whitelist mode) | |
121121
| `deny <ip[/prefix]>` | Deny source address (blacklist mode) | |
122122

thinproxy.8

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ When any
130130
.Cm connect_port
131131
directive is present, CONNECT requests to unlisted ports are denied
132132
with 403 Forbidden.
133-
If omitted, all ports are allowed.
133+
The default allows port 443 only.
134+
Config entries replace the defaults.
134135
.It Cm allow Ar address Ns Op / Ns Ar prefix
135136
Allow connections from
136137
.Ar address .

thinproxy.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ static int nacl;
159159

160160
/* CONNECT port whitelist */
161161
#define MAX_CONNECT_PORTS 64
162-
static int connect_ports[MAX_CONNECT_PORTS];
163-
static int nconnect_ports;
162+
static int connect_ports[MAX_CONNECT_PORTS] = { 443 };
163+
static int nconnect_ports = 1;
164164

165165
/* forward declarations */
166166
static void conn_close(struct conn *);
@@ -736,6 +736,7 @@ parse_config(const char *path, int must_exist)
736736
}
737737
cfg_deny_private = b;
738738
} else if (strcasecmp(key, "connect_port") == 0) {
739+
static int connect_port_seen;
739740
int n = atoi(val);
740741
if (n <= 0 || n > 65535) {
741742
logmsg(LOG_ERR,
@@ -744,6 +745,10 @@ parse_config(const char *path, int must_exist)
744745
fclose(fp);
745746
return -1;
746747
}
748+
if (!connect_port_seen) {
749+
nconnect_ports = 0;
750+
connect_port_seen = 1;
751+
}
747752
if (nconnect_ports >= MAX_CONNECT_PORTS) {
748753
logmsg(LOG_ERR,
749754
"%s:%d: too many connect_port entries",

thinproxy.conf.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ port 8080
3030
# Prevents SSRF by denying RFC 1918, loopback, link-local, etc.
3131
#deny_private yes
3232

33-
# Restrict CONNECT method to specific ports (default: all ports allowed)
33+
# Restrict CONNECT method to specific ports (default: 443)
3434
# When set, CONNECT to unlisted ports is denied with 403.
35+
# Config entries replace the defaults.
3536
#connect_port 443
3637
#connect_port 8443
3738

0 commit comments

Comments
 (0)