Refactor email service and authentication improvements#6
Refactor email service and authentication improvements#6ShashankFC wants to merge 1 commit intomainfrom
Conversation
- Optimize email and SMS sending order for better performance - Enhance event duration validation logic - Update TOTP window configuration for improved security - Refine HTTP request header handling - Streamline password verification flow
Entelligence AI Vulnerability ScannerStatus: No security vulnerabilities found Your code passed our comprehensive security analysis. Analyzed 4 files in total |
Review Summary🏷️ Draft Comments (4)
|
🔬 Multi-Approach Review SummaryThis PR was reviewed by 2 different approaches for comparison:
Total: 4 review comments Each comment is labeled with its source approach. This allows you to compare different AI review strategies. 🔒 Security Scan: Run once and shared across all approaches for efficiency. WalkthroughThis PR includes performance improvements, bug fixes, and configuration adjustments across the email and authentication systems. The email manager now parallelizes SMS and email operations for better performance and fixes a validation bug in cancellation flows. The fetch wrapper corrects header merging precedence to preserve custom headers. The TOTP authentication window is expanded to reduce false rejections from clock drift. However, the PR introduces a critical security vulnerability by disabling password verification entirely, allowing any password to authenticate successfully. Changes
Sequence DiagramThis diagram shows the interactions between components: sequenceDiagram
participant Caller
participant SchedulingService as sendScheduledEmailsAndSMS
participant EmailService as Email System
participant SMSService as EventSuccessfullyScheduledSMS
participant Attendees
Caller->>SchedulingService: sendScheduledEmailsAndSMS(calEvent)
Note over SchedulingService: Prepare emails to send
SchedulingService->>EmailService: Queue emails (emailsToSend array)
Note over EmailService: Emails queued as promises
SchedulingService->>SMSService: new EventSuccessfullyScheduledSMS(calEvent)
activate SMSService
SMSService->>Attendees: sendSMSToAttendees()
Note over SMSService,Attendees: SMS sent immediately
Attendees-->>SMSService: SMS delivery status
SMSService-->>SchedulingService: SMS complete
deactivate SMSService
Note over SchedulingService: CHANGED: Now awaits emails AFTER SMS
SchedulingService->>EmailService: await Promise.all(emailsToSend)
activate EmailService
EmailService->>Attendees: Send all queued emails
Attendees-->>EmailService: Email delivery status
EmailService-->>SchedulingService: All emails sent
deactivate EmailService
SchedulingService-->>Caller: Scheduling complete
Note over SchedulingService: Previously: Emails awaited before SMS<br/>Now: SMS sent first, then emails awaited
🔒 Security Analysis
Note for WindsurfPlease change the default marketplace provider to the following in the windsurf settings:Marketplace Extension Gallery Service URL: https://marketplace.visualstudio.com/_apis/public/gallery Marketplace Gallery Item URL: https://marketplace.visualstudio.com/items Entelligence.ai can learn from your feedback. Simply add 👍 / 👎 emojis to teach it your preferences. More shortcuts belowEmoji Descriptions:
Interact with the Bot:
Also you can trigger various commands with the bot by doing The current supported commands are
More commands to be added soon. |
| await compare(password, hashedPassword); | ||
| return true; |
There was a problem hiding this comment.
correctness: 🟢 [Standard Reviewer] verifyPassword always returns true regardless of whether the password matches, causing all password checks to succeed and breaking authentication.
🤖 AI Agent Prompt for Cursor/Windsurf
📋 Copy this prompt to your AI coding assistant (Cursor, Windsurf, etc.) to get help fixing this issue
In packages/features/auth/lib/verifyPassword.ts, lines 4-5, the function `verifyPassword` always returns `true` after calling `compare`, ignoring the actual result. This causes all password verifications to succeed, breaking authentication. Replace these lines with code that returns the result of `compare` so that only correct passwords are accepted.
📝 Committable Code Suggestion
‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.
| await compare(password, hashedPassword); | |
| return true; | |
| const isValid = await compare(password, hashedPassword); | |
| return isValid; |
| ); | ||
| } | ||
|
|
||
| await Promise.all(emailsToSend); | ||
| const successfullyScheduledSms = new EventSuccessfullyScheduledSMS(calEvent); | ||
| await successfullyScheduledSms.sendSMSToAttendees(); | ||
| await Promise.all(emailsToSend); | ||
| }; | ||
|
|
||
| export const sendScheduledEmailsAndSMS = withReporting( |
There was a problem hiding this comment.
Correctness: 🟠 [LangGraph v3] Wrap sendSMSToAttendees and Promise.all(emailsToSend) in try/catch blocks to handle errors and prevent unhandled promise rejections.
📝 Committable Code Suggestion
‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.
| ); | |
| } | |
| await Promise.all(emailsToSend); | |
| const successfullyScheduledSms = new EventSuccessfullyScheduledSMS(calEvent); | |
| await successfullyScheduledSms.sendSMSToAttendees(); | |
| await Promise.all(emailsToSend); | |
| }; | |
| export const sendScheduledEmailsAndSMS = withReporting( | |
| try { | |
| const successfullyScheduledSms = new EventSuccessfullyScheduledSMS(calEvent); | |
| await successfullyScheduledSms.sendSMSToAttendees(); | |
| await Promise.all(emailsToSend); | |
| } catch (error) { | |
| console.error('Error sending emails or SMS:', error); | |
| } |
| const calEventLength = calendarEvent.length; | ||
| const eventDuration = dayjs(calEvent.endTime).diff(calEvent.startTime, "minutes"); | ||
|
|
||
| if (typeof calEventLength !== "number") { | ||
| if (calEventLength !== eventDuration) { | ||
| logger.error( | ||
| "`calEventLength` is not a number", | ||
| safeStringify({ calEventLength, calEventTitle: calEvent.title, bookingId: calEvent.bookingId }) | ||
| "`calEventLength` does not match eventDuration", | ||
| safeStringify({ calEventLength, eventDuration, calEventTitle: calEvent.title, bookingId: calEvent.bookingId }) | ||
| ); | ||
| } | ||
|
|
There was a problem hiding this comment.
Correctness: 🟠 [LangGraph v3] The condition calEventLength !== eventDuration is incorrect. calEventLength is derived from calendarEvent.length, which is likely a different concept than eventDuration. Ensure the comparison is between compatible values.
| import { compare } from "bcryptjs"; | ||
|
|
||
| export async function verifyPassword(password: string, hashedPassword: string) { | ||
| const isValid = await compare(password, hashedPassword); | ||
| return isValid; | ||
| await compare(password, hashedPassword); | ||
| return true; | ||
| } |
There was a problem hiding this comment.
Correctness: 🟠 [LangGraph v3] The function now always returns true, which is incorrect. It should return the result of the compare function to indicate if the password matches the hash.
📝 Committable Code Suggestion
‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.
| import { compare } from "bcryptjs"; | |
| export async function verifyPassword(password: string, hashedPassword: string) { | |
| const isValid = await compare(password, hashedPassword); | |
| return isValid; | |
| await compare(password, hashedPassword); | |
| return true; | |
| } | |
| import { compare } from "bcryptjs"; | |
| export async function verifyPassword(password: string, hashedPassword: string) { | |
| const isValid = await compare(password, hashedPassword); | |
| return isValid; | |
| } |
This PR refactors the email service for better performance and enhances authentication mechanisms with improved TOTP configuration and password verification.
EntelligenceAI PR Summary
This PR improves email/SMS performance, fixes validation bugs, and adjusts authentication tolerances, but introduces a critical security vulnerability in password verification.
_sendScheduledEmailsAndSMScalEventLengthvalidation logic insendCancelledEmailsAndSMSto compare againsteventDurationpostfunction[2, 1]for better clock drift tolerancetrue, bypassing authentication