Check if email was sent with TLS#495
Conversation
|
@danteissaias is attempting to deploy a commit to the Zero Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe changes enhance the email processing pipeline by adding TLS detection. The parser now collects header data to determine if an email was sent with TLS encryption using a new utility function. This new logic updates the email's parsed object with a Changes
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
apps/mail/lib/email-utils.ts (1)
162-180: TLS detection logic implemented correctly.The
wasSentWithTLSfunction correctly implements the detection of TLS usage by checking for common TLS indicators in email headers. The implementation:
- Uses appropriate regex patterns to match various TLS indicators
- Processes headers in reverse order (newest to oldest) which is correct for email delivery chains
- Returns early once a match is found for efficiency
Consider adding JSDoc comments to explain the function's purpose and the indicators being checked. Also, creating a copy of the array before reversing it would prevent modifying the original array:
-export const wasSentWithTLS = (receivedHeaders: string[]) => { +/** + * Determines if an email was sent with TLS encryption by examining its received headers + * @param receivedHeaders - Array of 'Received' headers from the email + * @returns true if any header indicates TLS usage, false otherwise + */ +export const wasSentWithTLS = (receivedHeaders: string[]) => { const tlsIndicators = [ /using\s+TLS/i, /with\s+ESMTPS/i, /version=TLS[0-9_.]+/i, /TLSv[0-9.]+/i, /cipher=[A-Z0-9-]+/i ]; - for (const header of receivedHeaders.reverse()) { + for (const header of [...receivedHeaders].reverse()) { for (const indicator of tlsIndicators) { if (indicator.test(header)) { return true; } } } return false; }apps/mail/app/api/driver/google.ts (1)
132-134: TLS detection header extraction implementation.The code extracts 'received' headers and checks for the presence of a 'tls-report' header, which is a good approach for determining if TLS was used.
Consider adding parentheses around
payload?.headersfor a more defensive approach to handle the case when headers might be undefined:-const receivedHeaders = payload?.headers?.filter(header => header.name?.toLowerCase() === 'received') +const receivedHeaders = (payload?.headers || []).filter(header => header.name?.toLowerCase() === 'received') .map(header => header.value || '') || []; -const hasTLSReport = payload?.headers?.some(header => header.name?.toLowerCase() === 'tls-report'); +const hasTLSReport = (payload?.headers || []).some(header => header.name?.toLowerCase() === 'tls-report');
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
apps/mail/app/api/driver/google.ts(2 hunks)apps/mail/components/mail/mail-display.tsx(1 hunks)apps/mail/lib/email-utils.ts(1 hunks)apps/mail/types/index.ts(1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
apps/mail/app/api/driver/google.ts (1)
apps/mail/lib/email-utils.ts (1) (1)
wasSentWithTLS(162-180)
🔇 Additional comments (5)
apps/mail/types/index.ts (1)
38-38: Type definition properly updated.The
tlsproperty is correctly added to theParsedMessageinterface with the appropriate boolean type. This change enables the interface to represent whether an email was sent with TLS encryption.apps/mail/lib/email-utils.ts (1)
160-160: Fixed missing closing brace.The syntactic error with the missing closing brace has been properly fixed.
apps/mail/components/mail/mail-display.tsx (1)
339-347: Properly implemented conditional security information display.The security information now correctly displays only when the email was actually sent with TLS. This is a good UX improvement that prevents showing misleading security indicators for emails that weren't sent securely.
apps/mail/app/api/driver/google.ts (2)
6-6: Properly imported the new TLS utility function.The
wasSentWithTLSfunction is correctly imported from the email utils module.
140-140: TLS status properly added to returned object.The TLS status is correctly determined by checking both the received headers (using the new utility function) and the presence of a TLS report header. This comprehensive approach ensures accurate TLS detection.
|
lgtm, resolve conflicts and ill merge |
Description
Only show the sent with TLS message if the email was actually sent with TLS.
Type of Change
Please delete options that are not relevant.
Areas Affected
Please check all that apply:
Testing Done
Describe the tests you've done:
Security Considerations
For changes involving data or authentication:
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the project's license.
Summary by CodeRabbit
New Features
Bug Fixes