You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The email sending logic has been moved to a secure server-side API route at send-email.js. The client-side sendEmail function now calls this API route, so your API key is no longer exposed to the client.
In Next.js, any environment variable prefixed with NEXT_PUBLIC_ is embedded into the client-side JavaScript bundle and is accessible in the browser. This means anyone inspecting frontend code could see the API key
Move email sending logic to secure server-side API endpoint
Remove client-side API key exposure vulnerability
Improve error handling and validation
Update environment variable naming convention
Diagram Walkthrough
flowchart LR
A["Client emailService.js"] -- "POST request" --> B["Server API /send-email"]
B -- "Brevo API call" --> C["External Brevo Service"]
D["Environment Variable"] --> B
Loading
File Walkthrough
Relevant files
Enhancement
send-email.js
Create secure server-side email API endpoint
pages/api/send-email.js
Create new server-side API endpoint for email sending
Add email validation and error handling
Implement secure Brevo API integration with server-side key access
Return appropriate HTTP status codes and error messages
Here are some key observations to aid the review process:
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 Security concerns
Environment variable exposure: The PR correctly moves the API key handling to the server side, but the environment variable is still named with the NEXT_PUBLIC_ prefix (line 9 in send-email.js). Variables with this prefix are exposed to the client in Next.js applications. The environment variable should be renamed to remove this prefix (e.g., BREVO_API instead of NEXT_PUBLIC_BREVO_API) to ensure the API key remains secure.
The API key is still using NEXT_PUBLIC_ prefix on the server side. This prefix should be removed since the variable is now only used server-side and should not be exposed to the client.
Email validation is performed both client-side and server-side. While this is good for security, the client-side validation could use the same validation function to ensure consistency.
Why: The suggestion correctly identifies a critical security vulnerability where an API key is exposed to the client-side due to the NEXT_PUBLIC_ prefix, which undermines the PR's goal of securing the key.
High
Use server-only environment variable
Replace process.env.NEXT_PUBLIC_BREVO_API with a server-only environment variable (e.g., process.env.BREVO_API) to prevent exposing the API key on the client-side.
Why: The suggestion correctly points out the use of a client-exposed environment variable on the server, which is a critical security flaw that defeats the purpose of the PR, and proposes the correct fix.
@arpitB-dev hi, could you please review it and merge when you get time?
Also I would like to contribute more on this project, is there any major feature or bug that you suggest I could work on?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
The email sending logic has been moved to a secure server-side API route at
send-email.js. The client-side sendEmail function now calls this API route, so your API key is no longer exposed to the client.In Next.js, any environment variable prefixed with NEXT_PUBLIC_ is embedded into the client-side JavaScript bundle and is accessible in the browser. This means anyone inspecting frontend code could see the API key
PR Type
Enhancement, Fixes #22
Description
Move email sending logic to secure server-side API endpoint
Remove client-side API key exposure vulnerability
Improve error handling and validation
Update environment variable naming convention
Diagram Walkthrough
File Walkthrough
send-email.js
Create secure server-side email API endpointpages/api/send-email.js
emailService.js
Refactor client-side email service to use APIutils/services/emailService.js
.env.example
Update environment variable naming convention.env.example
NEXT_PUBLIC_BREVO_API_KEYtoNEXT_PUBLIC_BREVO_API