Skip to content

Commit 0552066

Browse files
authored
Merge pull request #1205 from DEVTomatoCake/feat/dont-send-x-powered-by
Stop sending X-Powered-By & use API CORS + BodyParser middlewares in CDN
2 parents c1906d6 + 342ef1b commit 0552066

File tree

2 files changed

+13
-25
lines changed

2 files changed

+13
-25
lines changed

src/api/Server.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/*
22
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
33
Copyright (C) 2023 Spacebar and Spacebar Contributors
4-
4+
55
This program is free software: you can redistribute it and/or modify
66
it under the terms of the GNU Affero General Public License as published
77
by the Free Software Foundation, either version 3 of the License, or
88
(at your option) any later version.
9-
9+
1010
This program is distributed in the hope that it will be useful,
1111
but WITHOUT ANY WARRANTY; without even the implied warranty of
1212
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313
GNU Affero General Public License for more details.
14-
14+
1515
You should have received a copy of the GNU Affero General Public License
1616
along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
@@ -98,6 +98,7 @@ export class SpacebarServer extends Server {
9898
}
9999

100100
this.app.set("json replacer", JSONReplacer);
101+
this.app.disable("x-powered-by");
101102

102103
const trustedProxies = Config.get().security.trustedProxies;
103104
if (trustedProxies) this.app.set("trust proxy", trustedProxies);

src/cdn/Server.ts

+9-22
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/*
22
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
33
Copyright (C) 2023 Spacebar and Spacebar Contributors
4-
4+
55
This program is free software: you can redistribute it and/or modify
66
it under the terms of the GNU Affero General Public License as published
77
by the Free Software Foundation, either version 3 of the License, or
88
(at your option) any later version.
9-
9+
1010
This program is distributed in the hope that it will be useful,
1111
but WITHOUT ANY WARRANTY; without even the implied warranty of
1212
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313
GNU Affero General Public License for more details.
14-
14+
1515
You should have received a copy of the GNU Affero General Public License
1616
along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
@@ -22,7 +22,8 @@ import path from "path";
2222
import avatarsRoute from "./routes/avatars";
2323
import guildProfilesRoute from "./routes/guild-profiles";
2424
import iconsRoute from "./routes/role-icons";
25-
import bodyParser from "body-parser";
25+
import { CORS } from "../api/middlewares/CORS";
26+
import { BodyParser } from "../api/middlewares/BodyParser";
2627

2728
export type CDNServerOptions = ServerOptions;
2829

@@ -38,24 +39,10 @@ export class CDNServer extends Server {
3839
await Config.init();
3940
await Sentry.init(this.app);
4041

41-
this.app.use((req, res, next) => {
42-
res.set("Access-Control-Allow-Origin", "*");
43-
// TODO: use better CSP policy
44-
res.set(
45-
"Content-security-policy",
46-
"default-src * data: blob: filesystem: about: ws: wss: 'unsafe-inline' 'unsafe-eval'; script-src * data: blob: 'unsafe-inline' 'unsafe-eval'; connect-src * data: blob: 'unsafe-inline'; img-src * data: blob: 'unsafe-inline'; frame-src * data: blob: ; style-src * data: blob: 'unsafe-inline'; font-src * data: blob: 'unsafe-inline';",
47-
);
48-
res.set(
49-
"Access-Control-Allow-Headers",
50-
req.header("Access-Control-Request-Headers") || "*",
51-
);
52-
res.set(
53-
"Access-Control-Allow-Methods",
54-
req.header("Access-Control-Request-Methods") || "*",
55-
);
56-
next();
57-
});
58-
this.app.use(bodyParser.json({ inflate: true, limit: "10mb" }));
42+
this.app.disable("x-powered-by");
43+
44+
this.app.use(CORS);
45+
this.app.use(BodyParser({ inflate: true, limit: "10mb" }));
5946

6047
await registerRoutes(this, path.join(__dirname, "routes/"));
6148

0 commit comments

Comments
 (0)