Skip to content

fix: validate SMTP credentials using SMTPAuth #9668

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: main
Choose a base branch
from

Conversation

kateliuhyd
Copy link

@kateliuhyd kateliuhyd commented Apr 19, 2025

What does this PR do?

This PR fixes issue #9067 by enabling SMTP authentication in the projects.php controller.
Without setting $mail->SMTPAuth, PHPMailer does not validate the provided username and password.
This fix ensures that invalid SMTP credentials will be correctly rejected when updating a project's SMTP settings.

Test Plan

  • Reproduced the issue by attempting to update SMTP settings with an invalid username and password.
  • Applied the fix by adding $mail->SMTPAuth = (!empty($username) && !empty($password)) ? true : false; to the validation block.
  • Confirmed that the SMTP credentials are now validated before the update is accepted.
  • Code reviewed in a Replit environment.

Related PRs and Issues

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

Summary by CodeRabbit

  • Chores

    • Added a configuration file to define the development environment and deployment commands.
  • Bug Fixes

    • Improved SMTP authentication logic in the project API to correctly enable or disable authentication based on the presence of credentials.

Copy link

coderabbitai bot commented Apr 19, 2025

Walkthrough

A new .replit configuration file has been added to define the development and deployment environments, specifying Node.js, PHP, and Bash modules, along with run commands for both development and deployment. Additionally, the SMTP authentication logic in the app/controllers/api/projects.php file has been updated: the SMTPAuth property is now set to true only when both SMTP username and password are provided, ensuring proper authentication behavior during SMTP settings validation.

Changes

File(s) Change Summary
.replit Added configuration specifying Node.js 20, PHP 8.2, Bash, Nix channel, and run/deployment commands
app/controllers/api/projects.php Updated SMTP validation to set SMTPAuth based on presence of username and password

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API_Controller
    participant PHPMailer

    Client->>API_Controller: PATCH /v1/projects/:projectId/smtp (with SMTP settings)
    API_Controller->>PHPMailer: Initialize and configure SMTP
    API_Controller->>PHPMailer: Set SMTPAuth = (username && password ? true : false)
    API_Controller->>PHPMailer: Attempt SMTP connection
    PHPMailer-->>API_Controller: Success or failure
    API_Controller-->>Client: Respond with result
Loading

Assessment against linked issues

Objective Addressed Explanation
Set SMTPAuth to true when validating SMTP settings so username and password are checked (#9067)

Poem

A hop and a skip, a bug takes flight,
SMTPAuth now set just right!
With username and password checked anew,
Your emails will fly, not askew.
The .replit file brings order, too—
This bunny’s proud of what you do!
🐇✨

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 34d587d and decf874.

📒 Files selected for processing (2)
  • .replit (1 hunks)
  • app/controllers/api/projects.php (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: scan
🔇 Additional comments (2)
.replit (1)

1-9: Configuration looks good for Replit environment

This new configuration file properly sets up the Replit development environment with the necessary modules and run commands.

app/controllers/api/projects.php (1)

686-686: Good fix for SMTP authentication validation

This addition properly enables SMTP authentication only when both username and password are provided, which resolves issue #9067 where invalid SMTP credentials could be accepted. The conditional check is correctly implemented to ensure authentication is only attempted when credentials are present.

The change is consistent with the PR objectives and directly addresses the security issue described. When both username and password are empty, SMTPAuth is set to false, preventing PHPMailer from attempting to authenticate, while ensuring proper validation when credentials are provided.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 docstrings to generate docstrings for 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

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
binutils 2.42-r0 CVE-2025-0840 HIGH
libcrypto3 3.3.2-r0 CVE-2024-12797 HIGH
libecpg 16.3-r0 CVE-2024-10979 HIGH
libecpg 16.3-r0 CVE-2024-7348 HIGH
libecpg 16.3-r0 CVE-2025-1094 HIGH
libecpg-dev 16.3-r0 CVE-2024-10979 HIGH
libecpg-dev 16.3-r0 CVE-2024-7348 HIGH
libecpg-dev 16.3-r0 CVE-2025-1094 HIGH
libexpat 2.6.3-r0 CVE-2024-8176 HIGH
libpq 16.3-r0 CVE-2024-10979 HIGH
libpq 16.3-r0 CVE-2024-7348 HIGH
libpq 16.3-r0 CVE-2025-1094 HIGH
libpq-dev 16.3-r0 CVE-2024-10979 HIGH
libpq-dev 16.3-r0 CVE-2024-7348 HIGH
libpq-dev 16.3-r0 CVE-2025-1094 HIGH
libssl3 3.3.2-r0 CVE-2024-12797 HIGH
libxml2 2.12.7-r0 CVE-2024-56171 HIGH
libxml2 2.12.7-r0 CVE-2025-24928 HIGH
libxml2 2.12.7-r0 CVE-2025-27113 HIGH
openssl 3.3.2-r0 CVE-2024-12797 HIGH
openssl-dev 3.3.2-r0 CVE-2024-12797 HIGH
postgresql16-dev 16.3-r0 CVE-2024-10979 HIGH
postgresql16-dev 16.3-r0 CVE-2024-7348 HIGH
postgresql16-dev 16.3-r0 CVE-2025-1094 HIGH
pyc 3.12.6-r0 CVE-2024-12254 HIGH
pyc 3.12.6-r0 CVE-2024-9287 HIGH
python3 3.12.6-r0 CVE-2024-12254 HIGH
python3 3.12.6-r0 CVE-2024-9287 HIGH
python3-pyc 3.12.6-r0 CVE-2024-12254 HIGH
python3-pyc 3.12.6-r0 CVE-2024-9287 HIGH
python3-pycache-pyc0 3.12.6-r0 CVE-2024-12254 HIGH
python3-pycache-pyc0 3.12.6-r0 CVE-2024-9287 HIGH
rsync 3.3.0-r0 CVE-2024-12084 CRITICAL
rsync 3.3.0-r0 CVE-2024-12085 HIGH
xz 5.6.2-r0 CVE-2025-31115 HIGH
xz-libs 5.6.2-r0 CVE-2025-31115 HIGH
golang.org/x/crypto v0.26.0 CVE-2024-45337 CRITICAL
golang.org/x/crypto v0.26.0 CVE-2025-22869 HIGH

Source Code Scan Results

🎉 No vulnerabilities found!

Copy link
Contributor

@stnguyen90 stnguyen90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you please also add test cases?

@@ -1683,6 +1683,7 @@
if ($enabled) {
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->SMTPAuth = (!empty($username) && !empty($password)) ? true : false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified to

Suggested change
$mail->SMTPAuth = (!empty($username) && !empty($password)) ? true : false;
$mail->SMTPAuth = (!empty($username) && !empty($password));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this

@kateliuhyd
Copy link
Author

Would you please also add test cases?

I just added unit test to verify SMTP authentication with invalid credentials.
Please let me know if anything else needs to be improved. Thank you so much!

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.

🐛 Bug Report: SMTP username and password aren't validated when updating SMTP settings
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy