Skip to content

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

Open
wants to merge 1 commit into
base: alpha
Choose a base branch
from

Conversation

dblythy
Copy link
Member

@dblythy dblythy commented May 13, 2025

New Pull Request Checklist

Issue Description

Closes: #2759

Approach

TODOs before merging

Summary by CodeRabbit

  • Bug Fixes

    • Improved session management for enhanced reliability and security during authentication and logout processes.
  • Chores

    • Updated authentication dependencies to use more current and secure packages.

Copy link

I will reformat the title to use the proper commit message syntax.

@parse-github-assistant parse-github-assistant bot changed the title feat: update passport feat: Update passport May 13, 2025
Copy link

🚀 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.

Copy link

coderabbitai bot commented May 13, 2025

📝 Walkthrough

Walkthrough

The session management in the authentication middleware was migrated from cookie-session to express-session, with updated configuration for session cookies. The passport dependency was upgraded from version 0.5.3 to 0.7.0, and the cookie-session package was removed from dependencies. Logout handling was updated for asynchronous error handling.

Changes

File(s) Change Summary
Parse-Dashboard/Authentication.js Migrated session middleware from cookie-session to express-session with new config; improved logout route for async error handling; applied minor formatting changes.
package.json Removed cookie-session, added express-session, and upgraded passport from 0.5.3 to 0.7.0.

Assessment against linked issues

Objective Addressed Explanation
Upgrade passport from 0.5.3 to 0.6.0 or later to address vulnerability (#2759)

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 62b7e6f and 2af85fb.

⛔ 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.

Comment on lines +63 to 74
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'
}
}));
Copy link

@coderabbitai coderabbitai bot May 13, 2025

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.

Suggested change
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.

Copy link
Member

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?

Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants