Skip to content

Commit 9ed618c

Browse files
committed
Fix local HTTP Safari loads by disabling HTTPS upgrade headers
1 parent 8f1a338 commit 9ed618c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

packages/backend/src/main.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ export async function bootstrap() {
1717
app.enableShutdownHooks();
1818
app.useGlobalFilters(new SpaFallbackFilter());
1919

20+
const betterAuthUrl = process.env['BETTER_AUTH_URL'] || '';
21+
const hstsEnabled = /^https:\/\//i.test(betterAuthUrl);
22+
2023
app.use(
2124
helmet({
25+
hsts: hstsEnabled,
2226
contentSecurityPolicy: {
2327
directives: {
2428
defaultSrc: ["'self'"],
@@ -34,6 +38,10 @@ export async function bootstrap() {
3438
.map((v) => v.trim())
3539
.filter((v) => v !== '*')
3640
: ["'none'"],
41+
// Helmet ships `upgrade-insecure-requests` in its defaults. Safari enforces it
42+
// even on loopback (Chrome/Firefox skip for localhost), which rewrites every
43+
// same-origin subresource to https:// and breaks plain-HTTP dev/Docker setups.
44+
upgradeInsecureRequests: null,
3745
},
3846
},
3947
}),

0 commit comments

Comments
 (0)