Skip to content

Commit

Permalink
Fixing CSP for iOS devices. Fixes #669 (#678)
Browse files Browse the repository at this point in the history
  • Loading branch information
dessalines authored Jun 1, 2022
1 parent 9f9b9ca commit 3e7579b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
21 changes: 10 additions & 11 deletions src/server/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import process from "process";
import serialize from "serialize-javascript";
import { App } from "../shared/components/app/app";
import { SYMBOLS } from "../shared/components/common/symbols";
import { httpBaseInternal } from "../shared/env";
import { httpBaseInternal, wsUriBase } from "../shared/env";
import {
ILemmyConfig,
InitialFetchRequest,
Expand All @@ -27,16 +27,15 @@ const [hostname, port] = process.env["LEMMY_UI_HOST"]
const extraThemesFolder =
process.env["LEMMY_UI_EXTRA_THEMES_FOLDER"] || "./extra_themes";

// Commenting out for now, since this broke iOS / webkit browsers.
// if (!process.env["LEMMY_UI_DEBUG"]) {
// server.use(function (_req, res, next) {
// res.setHeader(
// "Content-Security-Policy",
// `default-src 'none'; connect-src 'self' ${wsUriBase}; img-src * data:; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; form-action 'self'; base-uri 'self'`
// );
// next();
// });
// }
if (!process.env["LEMMY_UI_DEBUG"]) {
server.use(function (_req, res, next) {
res.setHeader(
"Content-Security-Policy",
`default-src 'none'; connect-src 'self' ${wsUriBase}; img-src * data:; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; form-action 'self'; base-uri 'self'`
);
next();
});
}
const customHtmlHeader = process.env["LEMMY_UI_CUSTOM_HTML_HEADER"] || "";

server.use(express.json());
Expand Down
2 changes: 1 addition & 1 deletion src/shared/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if (isBrowser()) {
// server-side
externalHost = process.env.LEMMY_EXTERNAL_HOST || testHost;
host = internalHost;
wsHost = process.env.LEMMY_WS_HOST || host;
wsHost = process.env.LEMMY_WS_HOST || externalHost;
secure = process.env.LEMMY_HTTPS == "true" ? "s" : "";
}

Expand Down

0 comments on commit 3e7579b

Please sign in to comment.