-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: Update passport #2806
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
base: alpha
Are you sure you want to change the base?
feat: Update passport #2806
Conversation
I will reformat the title to use the proper commit message syntax. |
🚀 Thanks for opening this pull request! We appreciate your effort in improving the project. Please let us know once your pull request is ready for review. |
📝 WalkthroughWalkthroughThe session management in the authentication middleware was migrated from Changes
Assessment against linked issues
Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.json
is excluded by!**/package-lock.json
📒 Files selected for processing (2)
Parse-Dashboard/Authentication.js
(2 hunks)package.json
(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Node 20
- GitHub Check: Docker linux/amd64
🔇 Additional comments (6)
package.json (2)
48-48
: Good move to switch to express-session.Replacing cookie-session with express-session is a solid improvement. Express-session provides better security as it stores only the session identifier in the cookie while keeping session data on the server side.
58-58
: Passport version update properly handled.Upgrading Passport from 0.5.3 to 0.7.0 is a significant version jump with breaking changes, particularly around the logout functionality. I see this has been correctly addressed in the Authentication.js file with the new asynchronous logout pattern.
Parse-Dashboard/Authentication.js (4)
6-7
: Correct import updates for the middleware switch.Properly updated imports to use express-session instead of cookie-session.
94-99
: Correctly implemented async logout pattern.The PR properly updates the logout handler to use the new asynchronous pattern required by Passport 0.7.0, including appropriate error handling.
84-84
: Improved string manipulation logic.The redirect path handling is now more readable with explicit character checks.
89-90
: Cleaned up formatting.Minor formatting improvements to maintain code style consistency.
app.use(session({ | ||
name: 'parse_dash', | ||
secret: cookieSessionSecret, | ||
resave: false, | ||
saveUninitialized: false, | ||
cookie: { | ||
maxAge: cookieSessionMaxAge, | ||
httpOnly: true, | ||
secure: process.env.NODE_ENV === 'production', | ||
sameSite: 'lax' | ||
} | ||
})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Improved session configuration with security enhancements.
The express-session configuration includes good security practices:
- Named session to avoid conflicts
- Explicit resave and saveUninitialized settings
- Enhanced cookie security settings (httpOnly, secure in production, sameSite: 'lax')
However, the default in-memory session store isn't production-ready as it will leak memory in long-running applications.
Consider adding a production-ready session store like Redis or MongoDB for production environments:
app.use(session({
name: 'parse_dash',
secret: cookieSessionSecret,
resave: false,
saveUninitialized: false,
+ store: process.env.NODE_ENV === 'production'
+ ? new RedisStore({ /* redis options */ })
+ : null, // Use memory store in development
cookie: {
maxAge: cookieSessionMaxAge,
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
sameSite: 'lax'
}
}));
🌐 Web query:
What is the best session store for express-session in production?
💡 Result:
When choosing a session store for express-session in production, it's crucial to avoid the default MemoryStore, which is explicitly not recommended for production environments. The default MemoryStore will leak memory and won't scale beyond a single process[4].
Recommended Session Stores
Redis is widely considered one of the best options for session storage in production environments. It's a high-performance, in-memory store that's well-suited for production. Many developers prefer Redis because it offers:
- High performance and speed
- Persistence capabilities
- Scalability across multiple processes
- Built-in TTL (time-to-live) functionality
To implement Redis with express-session, you would:
const redis = require('redis');
const session = require('express-session');
let RedisStore = require('connect-redis')(session);
let redisClient = redis.createClient();
app.use(
session({
secret: ['veryimportantsecret','notsoimportantsecret','highlyprobablysecret'],
name: "secretname",
cookie: {
httpOnly: true,
secure: true,
sameSite: true,
maxAge: 600000 // Time in milliseconds
},
store: new RedisStore({ client: redisClient, ttl: 86400 }),
resave: false
})
);
```[5]
## Other Production-Ready Options
If Redis doesn't suit your needs, there are numerous other production-ready session stores compatible with express-session:
- **Database-based stores**:
- MongoDB (connect-mongo)
- MySQL (express-mysql-session)
- PostgreSQL (via various adapters)
- Oracle (express-oracle-session)
- **Other in-memory stores**:
- DynamoDB (dynamodb-store)
- Firestore (firestore-store)
- Hazelcast (hazelcast-store)
- **ORM-based stores**:
- TypeORM (connect-typeorm)
- Sequelize
Express-session's documentation lists many compatible session stores that you can choose from depending on your application's specific requirements[1][7].
## Selection Criteria
When selecting a session store for production, consider:
1. **Performance needs**: How fast do you need session retrieval to be?
2. **Scalability requirements**: Will your application run on multiple servers?
3. **Persistence needs**: Do you need sessions to survive server restarts?
4. **Existing infrastructure**: It often makes sense to use technology you're already familiar with or have deployed
5. **Security considerations**: Some stores offer additional security features
The key is choosing a store that integrates well with your existing stack while providing the performance and reliability your application requires.
Citations:
- 1: https://expressjs.com/en/resources/middleware/session.html
- 2: https://supertokens.com/blog/should-you-use-express-session-for-your-production-app
- 3: https://expressjs.com/en/advanced/best-practice-security.html
- 4: https://github.com/expressjs/session/issues/556
- 5: https://dev.to/jscrambler/best-practices-for-secure-session-management-in-node-3f01
- 6: https://github.com/expressjs/session/issues/143
- 7: https://www.youtube.com/watch?v=T9MsNRI5T-A
- 8: https://expressjs.com/en/advanced/best-practice-performance.html
---
</details>
**Add a production-ready session store (Redis) to avoid MemoryStore**
The default MemoryStore in express-session isn’t suitable for production—it will leak memory and won’t scale across processes. Integrate a Redis-backed store for high performance, persistence, and scalability:
• File: Parse-Dashboard/Authentication.js (lines 63–74)
• Install dependencies: `redis` and `connect-redis`
• Initialize Redis client and store at the top of the file
• Configure `store` only in production
```diff
// at the top of Parse-Dashboard/Authentication.js
+const redis = require('redis');
+const RedisStore = require('connect-redis')(session);
+const redisClient = redis.createClient({
+ // configure host, port, password, etc., if needed
+});
app.use(
session({
name: 'parse_dash',
secret: cookieSessionSecret,
resave: false,
saveUninitialized: false,
+ store: process.env.NODE_ENV === 'production'
+ ? new RedisStore({
+ client: redisClient,
+ ttl: cookieSessionMaxAge / 1000 // convert ms to seconds
+ })
+ : undefined,
cookie: {
maxAge: cookieSessionMaxAge,
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
sameSite: 'lax'
}
})
);
This ensures session data persists outside of your app process and scales in production environments.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
app.use(session({ | |
name: 'parse_dash', | |
secret: cookieSessionSecret, | |
resave: false, | |
saveUninitialized: false, | |
cookie: { | |
maxAge: cookieSessionMaxAge, | |
httpOnly: true, | |
secure: process.env.NODE_ENV === 'production', | |
sameSite: 'lax' | |
} | |
})); | |
// at the top of Parse-Dashboard/Authentication.js | |
const redis = require('redis'); | |
const RedisStore = require('connect-redis')(session); | |
const redisClient = redis.createClient({ | |
// configure host, port, password, etc., if needed | |
}); | |
app.use( | |
session({ | |
name: 'parse_dash', | |
secret: cookieSessionSecret, | |
resave: false, | |
saveUninitialized: false, | |
store: process.env.NODE_ENV === 'production' | |
? new RedisStore({ | |
client: redisClient, | |
ttl: cookieSessionMaxAge / 1000 // convert ms to seconds | |
}) | |
: undefined, | |
cookie: { | |
maxAge: cookieSessionMaxAge, | |
httpOnly: true, | |
secure: process.env.NODE_ENV === 'production', | |
sameSite: 'lax' | |
} | |
}) | |
); |
🤖 Prompt for AI Agents (early access)
In Parse-Dashboard/Authentication.js around lines 63 to 74, the current
express-session setup uses the default MemoryStore, which is not suitable for
production due to memory leaks and lack of scalability. To fix this, install the
'redis' and 'connect-redis' packages, then initialize a Redis client and
RedisStore at the top of the file. Modify the session middleware to use the
RedisStore as the session store only when in production environment, keeping the
existing configuration for development. This change will ensure session
persistence and scalability in production.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, the default in-memory session store isn't production-ready as it will leak memory in long-running applications.
@dblythy any action needed here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
New Pull Request Checklist
Issue Description
Closes: #2759
Approach
TODOs before merging
Summary by CodeRabbit
Bug Fixes
Chores