Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions backend/migrations/20260131163528_trust_forwarded_proto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { migrate as logger } from "../logger.js";

const migrateName = "trust_forwarded_proto";

/**
* Migrate
*
* @see http://knexjs.org/#Schema
*
* @param {Object} knex
* @returns {Promise}
*/
const up = function (knex) {
logger.info(`[${migrateName}] Migrating Up...`);

return knex.schema
.alterTable('proxy_host', (table) => {
table.tinyint('trust_forwarded_proto').notNullable().defaultTo(0);
})
.then(() => {
logger.info(`[${migrateName}] proxy_host Table altered`);
});
};

/**
* Undo Migrate
*
* @param {Object} knex
* @returns {Promise}
*/
const down = function (knex) {
logger.info(`[${migrateName}] Migrating Down...`);

return knex.schema
.alterTable('proxy_host', (table) => {
table.dropColumn('trust_forwarded_proto');
})
.then(() => {
logger.info(`[${migrateName}] proxy_host Table altered`);
});
};

export { up, down };
1 change: 1 addition & 0 deletions backend/models/proxy_host.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const boolFields = [
"enabled",
"hsts_enabled",
"hsts_subdomains",
"trust_forwarded_proto",
];

class ProxyHost extends Model {
Expand Down
8 changes: 7 additions & 1 deletion backend/schema/components/proxy-host-object.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"enabled",
"locations",
"hsts_enabled",
"hsts_subdomains"
"hsts_subdomains",
"trust_forwarded_proto"
],
"properties": {
"id": {
Expand Down Expand Up @@ -141,6 +142,11 @@
"hsts_subdomains": {
"$ref": "../common.json#/properties/hsts_subdomains"
},
"trust_forwarded_proto":{
"type": "boolean",
"description": "Trust the forwarded headers",
"example": false
},
"certificate": {
"oneOf": [
{
Expand Down
3 changes: 2 additions & 1 deletion backend/schema/paths/nginx/proxy-hosts/get.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
"enabled": true,
"locations": [],
"hsts_enabled": false,
"hsts_subdomains": false
"hsts_subdomains": false,
"trust_forwarded_proto": false
}
]
}
Expand Down
1 change: 1 addition & 0 deletions backend/schema/paths/nginx/proxy-hosts/hostID/get.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"locations": [],
"hsts_enabled": false,
"hsts_subdomains": false,
"trust_forwarded_proto": false,
"owner": {
"id": 1,
"created_on": "2025-10-28T00:50:24.000Z",
Expand Down
4 changes: 4 additions & 0 deletions backend/schema/paths/nginx/proxy-hosts/hostID/put.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
"hsts_subdomains": {
"$ref": "../../../../components/proxy-host-object.json#/properties/hsts_subdomains"
},
"trust_forwarded_proto": {
"$ref": "../../../../components/proxy-host-object.json#/properties/trust_forwarded_proto"
},
"http2_support": {
"$ref": "../../../../components/proxy-host-object.json#/properties/http2_support"
},
Expand Down Expand Up @@ -122,6 +125,7 @@
"locations": [],
"hsts_enabled": false,
"hsts_subdomains": false,
"trust_forwarded_proto": false,
"owner": {
"id": 1,
"created_on": "2025-10-28T00:50:24.000Z",
Expand Down
4 changes: 4 additions & 0 deletions backend/schema/paths/nginx/proxy-hosts/post.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
"hsts_subdomains": {
"$ref": "../../../components/proxy-host-object.json#/properties/hsts_subdomains"
},
"trust_forwarded_proto": {
"$ref": "../../../components/proxy-host-object.json#/properties/trust_forwarded_proto"
},
"http2_support": {
"$ref": "../../../components/proxy-host-object.json#/properties/http2_support"
},
Expand Down Expand Up @@ -119,6 +122,7 @@
"locations": [],
"hsts_enabled": false,
"hsts_subdomains": false,
"trust_forwarded_proto": false,
"certificate": null,
"owner": {
"id": 1,
Expand Down
5 changes: 5 additions & 0 deletions backend/templates/_forced_ssl.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{% if certificate and certificate_id > 0 -%}
{% if ssl_forced == 1 or ssl_forced == true %}
# Force SSL
{% if trust_forwarded_proto == true %}
set $trust_forwarded_proto "T";
{% else %}
set $trust_forwarded_proto "F";
{% endif %}
include conf.d/include/force-ssl.conf;
{% endif %}
{% endif %}
19 changes: 19 additions & 0 deletions docker/rootfs/etc/nginx/conf.d/include/force-ssl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,28 @@ if ($scheme = "http") {
if ($request_uri = /.well-known/acme-challenge/test-challenge) {
set $test "${test}T";
}

# Check if the ssl staff has been handled
set $test_ssl_handled "";
if ($trust_forwarded_proto = "") {
set $trust_forwarded_proto "F";
}
if ($trust_forwarded_proto = "T") {
set $test_ssl_handled "${test_ssl_handled}T";
}
if ($http_x_forwarded_proto = "https") {
set $test_ssl_handled "${test_ssl_handled}S";
}
if ($http_x_forwarded_scheme = "https") {
set $test_ssl_handled "${test_ssl_handled}S";
}
if ($test_ssl_handled = "TSS") {
set $test_ssl_handled "TS";
}
if ($test_ssl_handled = "TS") {
set $test "${test}S";
}

if ($test = H) {
return 301 https://$host$request_uri;
}
4 changes: 2 additions & 2 deletions docker/rootfs/etc/nginx/conf.d/include/proxy.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
add_header X-Served-By $host;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Scheme $scheme;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Scheme $x_forwarded_scheme;
proxy_set_header X-Forwarded-Proto $x_forwarded_proto;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass $forward_scheme://$server:$port$request_uri;
Expand Down
12 changes: 12 additions & 0 deletions docker/rootfs/etc/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ http {
default http;
}

# Handle upstream X-Forwarded-Proto and X-Forwarded-Scheme header
map $http_x_forwarded_proto $x_forwarded_proto {
"http" "http";
"https" "https";
default $scheme;
}
map $http_x_forwarded_scheme $x_forwarded_scheme {
"http" "http";
"https" "https";
default $scheme;
}

# Real IP Determination

# Local subnets:
Expand Down
1 change: 1 addition & 0 deletions frontend/src/api/backend/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export interface ProxyHost {
locations?: ProxyLocation[];
hstsEnabled: boolean;
hstsSubdomains: boolean;
trustForwardedProto: boolean;
// Expansions:
owner?: User;
accessList?: AccessList;
Expand Down
34 changes: 32 additions & 2 deletions frontend/src/components/Form/SSLOptionsFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import { T } from "src/locale";

interface Props {
forHttp?: boolean; // the sslForced, http2Support, hstsEnabled, hstsSubdomains fields
forProxyHost?: boolean; // the advanced fields
forceDNSForNew?: boolean;
requireDomainNames?: boolean; // used for streams
color?: string;
}
export function SSLOptionsFields({ forHttp = true, forceDNSForNew, requireDomainNames, color = "bg-cyan" }: Props) {
export function SSLOptionsFields({ forHttp = true, forProxyHost = false, forceDNSForNew, requireDomainNames, color = "bg-cyan" }: Props) {
const { values, setFieldValue } = useFormikContext();
const v: any = values || {};

const newCertificate = v?.certificateId === "new";
const hasCertificate = newCertificate || (v?.certificateId && v?.certificateId > 0);
const { sslForced, http2Support, hstsEnabled, hstsSubdomains, meta } = v;
const { sslForced, http2Support, hstsEnabled, hstsSubdomains, trustForwardedProto, meta } = v;
const { dnsChallenge } = meta || {};

if (forceDNSForNew && newCertificate && !dnsChallenge) {
Expand Down Expand Up @@ -115,6 +116,34 @@ export function SSLOptionsFields({ forHttp = true, forceDNSForNew, requireDomain
</div>
);

const getHttpAdvancedOptions = () =>(
<div>
<details>
<summary className="mb-1"><T id="domains.advanced" /></summary>
<div className="row">
<div className="col-12">
<Field name="trustForwardedProto">
{({ field }: any) => (
<label className="form-check form-switch mt-1">
<input
className={trustForwardedProto ? toggleEnabled : toggleClasses}
type="checkbox"
checked={!!trustForwardedProto}
onChange={(e) => handleToggleChange(e, field.name)}
disabled={!hasCertificate || !sslForced}
/>
<span className="form-check-label">
<T id="domains.trust-forwarded-proto" />
</span>
</label>
)}
</Field>
</div>
</div>
</details>
</div>
);

return (
<div>
{forHttp ? getHttpOptions() : null}
Expand All @@ -140,6 +169,7 @@ export function SSLOptionsFields({ forHttp = true, forceDNSForNew, requireDomain
{dnsChallenge ? <DNSProviderFields showBoundaryBox /> : null}
</>
) : null}
{forProxyHost && forHttp ? getHttpAdvancedOptions() : null}
</div>
);
}
1 change: 1 addition & 0 deletions frontend/src/hooks/useProxyHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const fetchProxyHost = (id: number | "new") => {
enabled: true,
hstsEnabled: false,
hstsSubdomains: false,
trustForwardedProto: false,
} as ProxyHost);
}
return getProxyHost(id, ["owner"]);
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/locale/src/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@
"domain-names.wildcards-not-supported": {
"defaultMessage": "Wildcards not supported for this CA"
},
"domains.advanced": {
"defaultMessage": "Advanced"
},
"domains.force-ssl": {
"defaultMessage": "Force SSL"
},
Expand All @@ -359,6 +362,9 @@
"domains.http2-support": {
"defaultMessage": "HTTP/2 Support"
},
"domains.trust-forwarded-proto": {
"defaultMessage": "Trust Upstream Forwarded Proto Headers"
},
"domains.use-dns": {
"defaultMessage": "Use DNS Challenge"
},
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/locale/src/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@
"domain-names.wildcards-not-supported": {
"defaultMessage": "此 CA 不支持通配符"
},
"domains.advanced": {
"defaultMessage": "高级选项"
},
"domains.force-ssl": {
"defaultMessage": "强制 SSL"
},
Expand All @@ -287,6 +290,9 @@
"domains.http2-support": {
"defaultMessage": "HTTP/2 支持"
},
"domains.trust-forwarded-proto": {
"defaultMessage": "信任上游代理传递的协议类型头"
},
"domains.use-dns": {
"defaultMessage": "使用DNS验证"
},
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/modals/ProxyHostModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const ProxyHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
http2Support: data?.http2Support || false,
hstsEnabled: data?.hstsEnabled || false,
hstsSubdomains: data?.hstsSubdomains || false,
trustForwardedProto: data?.trustForwardedProto || false,
// Advanced tab
advancedConfig: data?.advancedConfig || "",
meta: data?.meta || {},
Expand Down Expand Up @@ -339,7 +340,7 @@ const ProxyHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
label="ssl-certificate"
allowNew
/>
<SSLOptionsFields color="bg-lime" />
<SSLOptionsFields color="bg-lime" forProxyHost={true} />
</div>
<div className="tab-pane" id="tab-advanced" role="tabpanel">
<NginxConfigField />
Expand Down