HTTPS Redirect Loops on Raseef: Configure Express Proxy Trust
Reproduce the TLS termination mismatch, configure Express proxy trust, and troubleshoot HTTPS redirect loops and secure session cookies on Raseef.
Why an HTTPS site can keep redirecting to itself
Your browser opens an HTTPS URL, but your Node.js application thinks the connection is HTTP. A middleware redirects to HTTPS again, the browser repeats the request, and the loop continues. The missing distinction is between the visitor-to-gateway connection and the gateway-to-application connection.
This guide is for teams running Express APIs and web applications behind Raseef Public HTTP. It explains the documented proxy contract, gives a small local reproduction, and shows what to check before changing redirects or session settings. It is not a dashboard walkthrough or a production gateway test.
What Raseef forwards
According to the Public HTTP documentation, Raseef terminates HTTPS at its gateway and forwards requests to the application over HTTP/1.1. Plain HTTP requests receive a 308 redirect to HTTPS. The gateway removes visitor-supplied forwarding headers and sets its own:
Host: the address the visitor used.X-Forwarded-Host: the same host.X-Forwarded-Proto:https.X-Forwarded-For: the visitor IP address.
A socket reporting no TLS therefore does not establish that the visitor used an insecure connection. It describes only the immediate connection to your process.
Reproduce the mismatch locally
Save the following as proxy-demo.cjs and run node proxy-demo.cjs. It binds only to localhost and requires no third-party dependencies.
const http = require('node:http');
const server = http.createServer((req, res) => {
const tls = Boolean(req.socket.encrypted);
const forwarded = req.headers['x-forwarded-proto'];
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({
tls,
forwarded: forwarded ?? null,
naiveRedirect: !tls,
trustedProxyRedirect: forwarded !== 'https'
}));
});
server.listen(3000, '127.0.0.1');In another terminal, send these requests:
curl -s http://127.0.0.1:3000/
curl -s -H 'X-Forwarded-Proto: https' http://127.0.0.1:3000/
curl -s -H 'X-Forwarded-Proto: http' http://127.0.0.1:3000/We ran the same handler in a local harness on Node.js v24.22.1 on 23 November 2026. The harness selected an ephemeral localhost port to avoid conflicts. These are the observed Boolean results, not latency measurements:
| Forwarded protocol | Socket TLS | Naive redirect | Proxy-aware decision |
|---|---|---|---|
| Missing | false | true | true |
| https | false | true | false |
| http | false | true | true |
The middle row explains the loop: checking the socket alone asks for another redirect even when the forwarded protocol is HTTPS. The last column assumes the header came from a trusted proxy; it is deliberately not production security code.
The same experiment also demonstrates why blindly trusting the header is unsafe: a local client can send https without using TLS. Raseef's documented header replacement, and the actual route into your application, matter. Stop the demo with Ctrl+C.
Configure Express for the actual network path
Raseef documents this Express example:
const express = require('express');
const app = express();
app.set('trust proxy', 1);
// Configure sessions and other protocol-sensitive middleware after this.
app.get('/healthz', (req, res) => res.sendStatus(200));
const port = Number(process.env.PORT || 3000);
app.listen(port, '0.0.0.0');This is a configuration excerpt, not a complete session implementation. The setting tells Express to interpret proxy information; it affects req.protocol, and therefore req.secure, as well as client-IP interpretation. Do not copy the raw-header comparison from the demo into authorization logic.
The value 1 is the platform's documented example, not a universal safe setting. Express explicitly warns about different-length paths to an application. If the service can also be reached directly or through another proxy, review those paths first. Do not increase the hop count merely because you added a CDN, or use true as a generic fix. Match trust to the infrastructure you control and the headers it actually overwrites.
Choose Public web (HTTPS), or enable Public HTTP under Networking, and set the application's listening port. For an image service, Raseef does not automatically set PORT; configure the image to listen on the selected port. A listening-port mismatch is a separate problem from HTTPS detection.
Verify one layer at a time
- On a disposable staging service, inspect whether Express sees
req.protocol === 'https'andreq.secure === truethrough the public HTTPS address. Use a restricted diagnostic endpoint or minimal temporary logs; do not expose cookies, authorization headers or full request dumps. - Request the plain HTTP address without following redirects. Expect the documented gateway 308 toward HTTPS.
- Request HTTPS without following redirects. Check
Locationon each unexpected response. Compare scheme, host and path to identify whether the app, a CDN or a canonical-host rule is redirecting. - If secure session cookies are missing, confirm proxy trust before weakening cookie security. Also check cookie domain, path, SameSite behavior and the browser's rejection reason. Proxy configuration does not fix every session issue.
- Remove diagnostics and confirm readiness still succeeds. A health endpoint should not depend on a login redirect; see the Raseef readiness guide.
Use an address you control in the following commands; YOUR-SERVICE.raseef.run is a placeholder.
curl -sS -D - -o /dev/null http://YOUR-SERVICE.raseef.run/
curl -sS -D - -o /dev/null https://YOUR-SERVICE.raseef.run/Troubleshooting boundaries
- Repeated HTTPS-to-HTTPS redirects: inspect application protocol detection and canonical URL rules.
- Redirects bouncing between two hosts: compare application, CDN and custom-domain rules; proxy trust alone will not resolve contradictory host policies.
- 503 instead of a redirect: the documented gateway meaning includes an unreachable, starting or restarting app. Check the process, port and logs first.
- 502 or 504: these are not evidence of an HTTPS-detection bug. The docs associate them with invalid/oversized responses and response timeouts respectively.
- Unexpected client IPs: inspect the trusted path before using IPs for rate limits. Avoid assuming an IP identifies a unique user.
Do not build redirects from arbitrary incoming hosts. Prefer a configured canonical origin or a validated host allowlist when your application needs its own redirect policy.
Evidence and next step
The platform behavior above was checked against current official documentation on 23 November 2026. The local experiment proves the socket/header distinction only; it does not independently verify Raseef's gateway header sanitization, test customer sessions or measure platform performance.
Sources: Raseef Public HTTP, container networking and ports, Express behind proxies, and Node.js HTTP API.
Raseef currently offers a private pilot. To discuss running your application behind its HTTPS gateway, request access.