diff --git a/backend/.env.sample b/backend/.env.sample index 98f96881..fbdd39d8 100644 --- a/backend/.env.sample +++ b/backend/.env.sample @@ -1,3 +1,4 @@ PORT=5000 MONGO_URI=mongodb://localhost:27017/githubTracker SESSION_SECRET=your-secret-key +NODE_ENV=development diff --git a/backend/Dockerfile.prod b/backend/Dockerfile.prod index 9f35a107..1a229349 100644 --- a/backend/Dockerfile.prod +++ b/backend/Dockerfile.prod @@ -13,6 +13,9 @@ RUN npm install --production # Copy the rest of the application files COPY . . +# Set production environment so session cookies get Secure + SameSite=Strict +ENV NODE_ENV=production + # Expose the port for the application EXPOSE 5000 diff --git a/backend/server.js b/backend/server.js index 3f19f00b..68f4cc3e 100644 --- a/backend/server.js +++ b/backend/server.js @@ -20,6 +20,12 @@ app.use(session({ secret: process.env.SESSION_SECRET, resave: false, saveUninitialized: false, + cookie: { + httpOnly: true, + secure: process.env.NODE_ENV === 'production', + sameSite: process.env.NODE_ENV === 'production' ? 'strict' : 'lax', + maxAge: 24 * 60 * 60 * 1000, + }, })); app.use(passport.initialize()); app.use(passport.session());