Skip to content

Commit

Permalink
Fix validity of the FROM email address not being checked (#29347) (#2…
Browse files Browse the repository at this point in the history
…9360)

Backport #29347 by @carlosfelgueiras

Fixes #27188.
Introduces a check on the installation that tries to parse the FROM
address. If it fails, shows a new error message to the user.

Co-authored-by: Carlos Felgueiras <[email protected]>
Co-authored-by: KN4CK3R <[email protected]>
  • Loading branch information
3 people authored Feb 24, 2024
1 parent 5043ad5 commit 35db5a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ email_title = Email Settings
smtp_addr = SMTP Host
smtp_port = SMTP Port
smtp_from = Send Email As
smtp_from_invalid = The "Send Email As" address is invalid
smtp_from_helper = Email address Gitea will use. Enter a plain email address or use the "Name" <[email protected]> format.
mailer_user = SMTP Username
mailer_password = SMTP Password
Expand Down
6 changes: 6 additions & 0 deletions routers/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package install
import (
"fmt"
"net/http"
"net/mail"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -417,6 +418,11 @@ func SubmitInstall(ctx *context.Context) {
}

if len(strings.TrimSpace(form.SMTPAddr)) > 0 {
if _, err := mail.ParseAddress(form.SMTPFrom); err != nil {
ctx.RenderWithErr(ctx.Tr("install.smtp_from_invalid"), tplInstall, &form)
return
}

cfg.Section("mailer").Key("ENABLED").SetValue("true")
cfg.Section("mailer").Key("SMTP_ADDR").SetValue(form.SMTPAddr)
cfg.Section("mailer").Key("SMTP_PORT").SetValue(form.SMTPPort)
Expand Down

0 comments on commit 35db5a3

Please sign in to comment.