Skip to content

Commit

Permalink
Revert "Set content security policy http header for all responses (#608
Browse files Browse the repository at this point in the history
…)" (#613)

This reverts commit f1c5c60.
  • Loading branch information
dessalines authored Apr 8, 2022
1 parent 052438f commit 7d88439
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/server/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ const [hostname, port] = process.env["LEMMY_UI_HOST"]
const extraThemesFolder =
process.env["LEMMY_UI_EXTRA_THEMES_FOLDER"] || "./extra_themes";

server.use(function (_req, res, next) {
res.setHeader(
"Content-Security-Policy",
"default-src data: 'self'; connect-src * ws: wss:; frame-src *; img-src * data:; script-src 'self'; style-src 'self' 'unsafe-inline'; manifest-src 'self'"
);
next();
});
server.use(express.json());
server.use(express.urlencoded({ extended: false }));
server.use("/static", express.static(path.resolve("./dist")));
Expand Down Expand Up @@ -171,8 +164,18 @@ server.get("/*", async (req, res) => {
return res.redirect(context.url);
}

const cspHtml = (
<meta
http-equiv="Content-Security-Policy"
content="default-src data: 'self'; connect-src * ws: wss:; frame-src *; img-src * data:; script-src 'self'; style-src 'self' 'unsafe-inline'; manifest-src 'self'"
/>
);

const root = renderToString(wrapper);
const symbols = renderToString(SYMBOLS);
const cspStr = process.env.LEMMY_EXTERNAL_HOST
? renderToString(cspHtml)
: "";
const helmet = Helmet.renderStatic();

const config: ILemmyConfig = { wsHost: process.env.LEMMY_WS_HOST };
Expand All @@ -197,6 +200,9 @@ server.get("/*", async (req, res) => {
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Content Security Policy -->
${cspStr}
<!-- Web app manifest -->
<link rel="manifest" href="/static/assets/manifest.webmanifest">
Expand Down

0 comments on commit 7d88439

Please sign in to comment.