Skip to content

Commit 011191f

Browse files
authored
Merge pull request #5260 from jerry-yuan/develop
Add trust_forwarded_proto option for SSL redirect handling in r…
2 parents 13fbc53 + eeab425 commit 011191f

17 files changed

Lines changed: 148 additions & 7 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { migrate as logger } from "../logger.js";
2+
3+
const migrateName = "trust_forwarded_proto";
4+
5+
/**
6+
* Migrate
7+
*
8+
* @see http://knexjs.org/#Schema
9+
*
10+
* @param {Object} knex
11+
* @returns {Promise}
12+
*/
13+
const up = function (knex) {
14+
logger.info(`[${migrateName}] Migrating Up...`);
15+
16+
return knex.schema
17+
.alterTable('proxy_host', (table) => {
18+
table.tinyint('trust_forwarded_proto').notNullable().defaultTo(0);
19+
})
20+
.then(() => {
21+
logger.info(`[${migrateName}] proxy_host Table altered`);
22+
});
23+
};
24+
25+
/**
26+
* Undo Migrate
27+
*
28+
* @param {Object} knex
29+
* @returns {Promise}
30+
*/
31+
const down = function (knex) {
32+
logger.info(`[${migrateName}] Migrating Down...`);
33+
34+
return knex.schema
35+
.alterTable('proxy_host', (table) => {
36+
table.dropColumn('trust_forwarded_proto');
37+
})
38+
.then(() => {
39+
logger.info(`[${migrateName}] proxy_host Table altered`);
40+
});
41+
};
42+
43+
export { up, down };

backend/models/proxy_host.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const boolFields = [
2121
"enabled",
2222
"hsts_enabled",
2323
"hsts_subdomains",
24+
"trust_forwarded_proto",
2425
];
2526

2627
class ProxyHost extends Model {

backend/schema/components/proxy-host-object.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"enabled",
2323
"locations",
2424
"hsts_enabled",
25-
"hsts_subdomains"
25+
"hsts_subdomains",
26+
"trust_forwarded_proto"
2627
],
2728
"properties": {
2829
"id": {
@@ -141,6 +142,11 @@
141142
"hsts_subdomains": {
142143
"$ref": "../common.json#/properties/hsts_subdomains"
143144
},
145+
"trust_forwarded_proto":{
146+
"type": "boolean",
147+
"description": "Trust the forwarded headers",
148+
"example": false
149+
},
144150
"certificate": {
145151
"oneOf": [
146152
{

backend/schema/paths/nginx/proxy-hosts/get.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
"enabled": true,
5959
"locations": [],
6060
"hsts_enabled": false,
61-
"hsts_subdomains": false
61+
"hsts_subdomains": false,
62+
"trust_forwarded_proto": false
6263
}
6364
]
6465
}

backend/schema/paths/nginx/proxy-hosts/hostID/get.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"locations": [],
5757
"hsts_enabled": false,
5858
"hsts_subdomains": false,
59+
"trust_forwarded_proto": false,
5960
"owner": {
6061
"id": 1,
6162
"created_on": "2025-10-28T00:50:24.000Z",

backend/schema/paths/nginx/proxy-hosts/hostID/put.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
"hsts_subdomains": {
5757
"$ref": "../../../../components/proxy-host-object.json#/properties/hsts_subdomains"
5858
},
59+
"trust_forwarded_proto": {
60+
"$ref": "../../../../components/proxy-host-object.json#/properties/trust_forwarded_proto"
61+
},
5962
"http2_support": {
6063
"$ref": "../../../../components/proxy-host-object.json#/properties/http2_support"
6164
},
@@ -122,6 +125,7 @@
122125
"locations": [],
123126
"hsts_enabled": false,
124127
"hsts_subdomains": false,
128+
"trust_forwarded_proto": false,
125129
"owner": {
126130
"id": 1,
127131
"created_on": "2025-10-28T00:50:24.000Z",

backend/schema/paths/nginx/proxy-hosts/post.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
"hsts_subdomains": {
4949
"$ref": "../../../components/proxy-host-object.json#/properties/hsts_subdomains"
5050
},
51+
"trust_forwarded_proto": {
52+
"$ref": "../../../components/proxy-host-object.json#/properties/trust_forwarded_proto"
53+
},
5154
"http2_support": {
5255
"$ref": "../../../components/proxy-host-object.json#/properties/http2_support"
5356
},
@@ -119,6 +122,7 @@
119122
"locations": [],
120123
"hsts_enabled": false,
121124
"hsts_subdomains": false,
125+
"trust_forwarded_proto": false,
122126
"certificate": null,
123127
"owner": {
124128
"id": 1,

backend/templates/_forced_ssl.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{% if certificate and certificate_id > 0 -%}
22
{% if ssl_forced == 1 or ssl_forced == true %}
33
# Force SSL
4+
{% if trust_forwarded_proto == true %}
5+
set $trust_forwarded_proto "T";
6+
{% else %}
7+
set $trust_forwarded_proto "F";
8+
{% endif %}
49
include conf.d/include/force-ssl.conf;
510
{% endif %}
611
{% endif %}

docker/rootfs/etc/nginx/conf.d/include/force-ssl.conf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,28 @@ if ($scheme = "http") {
55
if ($request_uri = /.well-known/acme-challenge/test-challenge) {
66
set $test "${test}T";
77
}
8+
9+
# Check if the ssl staff has been handled
10+
set $test_ssl_handled "";
11+
if ($trust_forwarded_proto = "") {
12+
set $trust_forwarded_proto "F";
13+
}
14+
if ($trust_forwarded_proto = "T") {
15+
set $test_ssl_handled "${test_ssl_handled}T";
16+
}
817
if ($http_x_forwarded_proto = "https") {
18+
set $test_ssl_handled "${test_ssl_handled}S";
19+
}
20+
if ($http_x_forwarded_scheme = "https") {
21+
set $test_ssl_handled "${test_ssl_handled}S";
22+
}
23+
if ($test_ssl_handled = "TSS") {
24+
set $test_ssl_handled "TS";
25+
}
26+
if ($test_ssl_handled = "TS") {
927
set $test "${test}S";
1028
}
29+
1130
if ($test = H) {
1231
return 301 https://$host$request_uri;
1332
}

docker/rootfs/etc/nginx/conf.d/include/proxy.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
add_header X-Served-By $host;
22
proxy_set_header Host $host;
3-
proxy_set_header X-Forwarded-Scheme $scheme;
4-
proxy_set_header X-Forwarded-Proto $scheme;
3+
proxy_set_header X-Forwarded-Scheme $x_forwarded_scheme;
4+
proxy_set_header X-Forwarded-Proto $x_forwarded_proto;
55
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
66
proxy_set_header X-Real-IP $remote_addr;
77
proxy_pass $forward_scheme://$server:$port$request_uri;

0 commit comments

Comments
 (0)