-
Notifications
You must be signed in to change notification settings - Fork 0
Implemented refresh token rotation and secure cookie option #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -139,3 +139,5 @@ dist | |
| vite.config.js.timestamp-* | ||
| vite.config.ts.timestamp-* | ||
| .vite/ | ||
|
|
||
| Temp folder/ | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,8 @@ | ||
| import dotenv from "dotenv"; | ||
| dotenv.config(); | ||
|
|
||
| import express from "express"; | ||
| import cookieParser from 'cookie-parser'; | ||
| import { createServer } from "http"; | ||
| import cors from "cors"; | ||
| import { | ||
|
|
@@ -7,7 +11,8 @@ | |
| generalLimiter, | ||
| speedLimiter, | ||
| securityHeaders, | ||
| requestSizeLimiter | ||
| requestSizeLimiter, | ||
| csrfProtection | ||
| } from "./middleware/security"; | ||
| import healthRoutes from "./routes/health"; | ||
| import authRoutes from "./routes/auth"; | ||
|
|
@@ -30,6 +35,10 @@ | |
| app.use(helmetConfig); // Security headers | ||
| app.use(securityHeaders); // Additional custom security headers | ||
| app.use(corsConfig); // CORS policy | ||
| // Cookie parser (needed for refresh token cookie parsing) | ||
| app.use(cookieParser()); | ||
Check failureCode scanning / CodeQL Missing CSRF middleware High
This cookie middleware is serving a
request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading This cookie middleware is serving a request handler Error loading related location Loading Copilot AutofixAI 6 months ago Copilot could not generate an autofix suggestion Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support. |
||
| // CSRF Protection (defense in depth with SameSite cookies) | ||
| app.use(csrfProtection); | ||
| app.use(requestSizeLimiter); // Request size limiting | ||
| // Note: Rate limiting now applied per-route for better control | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import mongoose, { Schema, Document } from 'mongoose'; | ||
|
|
||
| export interface IRefreshToken extends Document { | ||
| user: mongoose.Types.ObjectId; | ||
| tokenHash: string; | ||
| expiresAt: Date; | ||
| createdAt: Date; | ||
| createdByIp?: string; | ||
| revoked?: boolean; | ||
| revokedAt?: Date; | ||
| revokedByIp?: string; | ||
| replacedByToken?: string; | ||
| } | ||
|
|
||
| const refreshTokenSchema = new Schema<IRefreshToken>( | ||
| { | ||
| user: { type: Schema.Types.ObjectId, ref: 'User', required: true }, | ||
| tokenHash: { type: String, required: true, index: true }, | ||
| expiresAt: { type: Date, required: true }, | ||
| createdAt: { type: Date, default: Date.now }, | ||
| createdByIp: { type: String }, | ||
| revoked: { type: Boolean, default: false }, | ||
| revokedAt: { type: Date }, | ||
| revokedByIp: { type: String }, | ||
| replacedByToken: { type: String } | ||
| }, | ||
| { timestamps: false } | ||
| ); | ||
|
|
||
| export default mongoose.model<IRefreshToken>('RefreshToken', refreshTokenSchema); |
Uh oh!
There was an error while loading. Please reload this page.