Update for split tunneled proxy origin
This commit is contained in:
parent
a1f26bc61f
commit
9e8347876c
5 changed files with 32 additions and 2 deletions
|
|
@ -58,6 +58,12 @@ CLOUDFLARED_TUNNEL_TOKEN=
|
|||
# (isolated cookies/storage via /proxy-ticket). Also published by LAN compose.
|
||||
# GCOORD_PROXY_PORT=3001
|
||||
|
||||
# Public browser-reachable origin for the dedicated isolated proxy port
|
||||
# (e.g. `https://proxy.example.com` when `proxy.example.com` is published through
|
||||
# your reverse proxy / Cloudflare Tunnel to GCOORD_PROXY_PORT). When set, proxy
|
||||
# launch tickets redirect to this origin instead of `http://<host>:<port>`.
|
||||
# GCOORD_PROXY_PUBLIC_ORIGIN=
|
||||
|
||||
# Alternative wildcard subdomain base host for origin-isolated proxy tunnels
|
||||
# GCOORD_PROXY_BASE_DOMAIN=proxy.example.com
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ services:
|
|||
- GCOORD_THROTTLE_MODE=${GCOORD_THROTTLE_MODE:-low-resource}
|
||||
- GCOORD_ALLOW_LAN_TUNNELS=${GCOORD_ALLOW_LAN_TUNNELS:-false}
|
||||
- GCOORD_PROXY_PORT=${GCOORD_PROXY_PORT:-}
|
||||
- GCOORD_PROXY_PUBLIC_ORIGIN=${GCOORD_PROXY_PUBLIC_ORIGIN:-}
|
||||
- GCOORD_PROXY_BASE_DOMAIN=${GCOORD_PROXY_BASE_DOMAIN:-}
|
||||
- GCOORD_WEBAUTHN_RP_ID=${GCOORD_WEBAUTHN_RP_ID:-}
|
||||
- GCOORD_WEBAUTHN_ORIGINS=${GCOORD_WEBAUTHN_ORIGINS:-}
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ export interface ServerOptions {
|
|||
allowLanTunnels?: boolean;
|
||||
proxyBaseDomain?: string;
|
||||
proxyPort?: number;
|
||||
proxyPublicOrigin?: string;
|
||||
webauthnRpId?: string;
|
||||
webauthnOrigins?: string[];
|
||||
metricsToken?: string;
|
||||
|
|
@ -186,6 +187,7 @@ export async function createGCoordinatorServer(
|
|||
allowLanTunnels: options.allowLanTunnels,
|
||||
proxyBaseDomain: options.proxyBaseDomain,
|
||||
proxyPort: options.proxyPort,
|
||||
proxyPublicOrigin: options.proxyPublicOrigin,
|
||||
trustCloudflare,
|
||||
});
|
||||
const customSystemsEngine = new CustomSystemsEngine(
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ async function main(): Promise<void> {
|
|||
allowLanTunnels: process.env.GCOORD_ALLOW_LAN_TUNNELS === 'true',
|
||||
proxyBaseDomain: process.env.GCOORD_PROXY_BASE_DOMAIN?.trim() || undefined,
|
||||
proxyPort: proxyPortRaw && Number.isFinite(proxyPortRaw) ? proxyPortRaw : undefined,
|
||||
proxyPublicOrigin: process.env.GCOORD_PROXY_PUBLIC_ORIGIN?.trim() || undefined,
|
||||
webauthnRpId: process.env.GCOORD_WEBAUTHN_RP_ID?.trim() || undefined,
|
||||
webauthnOrigins: parseCsvList(process.env.GCOORD_WEBAUTHN_ORIGINS),
|
||||
metricsToken: process.env.GCOORD_METRICS_TOKEN?.trim() || undefined,
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ export interface TunnelManagerOptions {
|
|||
allowLanTunnels?: boolean;
|
||||
proxyBaseDomain?: string;
|
||||
proxyPort?: number;
|
||||
proxyPublicOrigin?: string;
|
||||
trustCloudflare?: boolean;
|
||||
}
|
||||
|
||||
|
|
@ -225,6 +226,8 @@ export class TunnelManager {
|
|||
private readonly allowLanTunnels: boolean;
|
||||
private readonly proxyBaseDomain?: string;
|
||||
private readonly configuredProxyPort?: number;
|
||||
private readonly proxyPublicOrigin?: string;
|
||||
private readonly proxyPublicOriginSecure: boolean;
|
||||
private readonly trustCloudflare: boolean;
|
||||
|
||||
constructor(
|
||||
|
|
@ -238,6 +241,20 @@ export class TunnelManager {
|
|||
this.allowLanTunnels = Boolean(options.allowLanTunnels);
|
||||
this.proxyBaseDomain = options.proxyBaseDomain?.trim().toLowerCase() || undefined;
|
||||
this.configuredProxyPort = options.proxyPort;
|
||||
const rawPublicOrigin = options.proxyPublicOrigin?.trim().replace(/\/+$/, '');
|
||||
let publicOriginSecure = false;
|
||||
if (rawPublicOrigin) {
|
||||
try {
|
||||
const parsed = new URL(rawPublicOrigin);
|
||||
if (parsed.protocol === 'http:' || parsed.protocol === 'https:') {
|
||||
this.proxyPublicOrigin = `${parsed.protocol}//${parsed.host}`;
|
||||
publicOriginSecure = parsed.protocol === 'https:';
|
||||
}
|
||||
} catch {
|
||||
// Invalid proxy public origin ignored; fall back to host:port URLs.
|
||||
}
|
||||
}
|
||||
this.proxyPublicOriginSecure = publicOriginSecure;
|
||||
this.trustCloudflare = Boolean(options.trustCloudflare);
|
||||
}
|
||||
|
||||
|
|
@ -437,9 +454,11 @@ export class TunnelManager {
|
|||
sessionIdHash,
|
||||
expiresAt: Date.now() + 30_000,
|
||||
});
|
||||
const launchBase =
|
||||
this.proxyPublicOrigin ?? `http://${rawHostOnly}:${this.boundProxyPort}`;
|
||||
return {
|
||||
ticket,
|
||||
launchUrl: `http://${rawHostOnly}:${this.boundProxyPort}/__gcoord_ticket?ticket=${encodeURIComponent(ticket)}`,
|
||||
launchUrl: `${launchBase}/__gcoord_ticket?ticket=${encodeURIComponent(ticket)}`,
|
||||
mode: 'port',
|
||||
expiresInSec: 30,
|
||||
};
|
||||
|
|
@ -540,10 +559,11 @@ export class TunnelManager {
|
|||
res.end(JSON.stringify({ error: 'INVALID_OR_EXPIRED_TICKET' }));
|
||||
return;
|
||||
}
|
||||
const secureAttr = this.proxyPublicOriginSecure ? '; Secure' : '';
|
||||
res.writeHead(302, {
|
||||
Location: redeemed.redirectPath,
|
||||
'Cache-Control': 'no-store',
|
||||
'Set-Cookie': `${PROXY_SESSION_COOKIE_NAME}=${redeemed.proxySid}; HttpOnly; SameSite=Lax; Path=/`,
|
||||
'Set-Cookie': `${PROXY_SESSION_COOKIE_NAME}=${redeemed.proxySid}; HttpOnly; SameSite=Lax; Path=/${secureAttr}`,
|
||||
});
|
||||
res.end();
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue