Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"dotenv": "^16.4.5",
"express": "^4.19.2",
"express-session": "^1.18.0",
"helmet": "^8.1.0",
"node-cache": "^5.1.2",
"nunjucks": "^3.2.4",
"passport": "^0.7.0",
Expand Down
20 changes: 20 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ dotenv.config({ path: '.env', debug: true });
// Imports for the server
import express from 'express';

// Imports of security middleware
import helmet from "helmet";

// Imports for the database connection
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
Expand Down Expand Up @@ -48,6 +51,23 @@ const main = async () => {
// Set up the Express app
const app = express();

// Adding helmet
app.use(helmet.contentSecurityPolicy({
directives: {
"defaultSrc": ["'self'"],
"scriptSrc": ["'self'", "'unsafe-inline'", "https://cdn.jsdelivr.net/", "https://cdnjs.cloudflare.com/"],
"styleSrc": ["'self'", "'unsafe-inline'", "https://cdn.jsdelivr.net/"],
"imgSrc": ["'self'", "data:", "https://cdn.intra.42.fr/"],
"connectSrc": ["'self'", "https://cdn.jsdelivr.net/", "https://cdnjs.cloudflare.com/"], // For fetch, XMLHttpRequest, WebSocket, EventSource
"fontSrc": ["'self'", "data:"],
"objectSrc": ["'none'"],
"frameAncestors": ["'none'"],
"baseUri": ["'self'"],
"formAction": ["'self'"],
"upgradeInsecureRequests": [],
}
}));

// Configure passport for OAuth2 authentication with Intra
setupPassport(prisma);

Expand Down