Skip to content

Commit 35db5a3

Browse files
GiteaBotcarlosfelgueirasKN4CK3R
authored
Fix validity of the FROM email address not being checked (#29347) (#29360)
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]>
1 parent 5043ad5 commit 35db5a3

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ email_title = Email Settings
246246
smtp_addr = SMTP Host
247247
smtp_port = SMTP Port
248248
smtp_from = Send Email As
249+
smtp_from_invalid = The "Send Email As" address is invalid
249250
smtp_from_helper = Email address Gitea will use. Enter a plain email address or use the "Name" <[email protected]> format.
250251
mailer_user = SMTP Username
251252
mailer_password = SMTP Password

routers/install/install.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package install
77
import (
88
"fmt"
99
"net/http"
10+
"net/mail"
1011
"os"
1112
"os/exec"
1213
"path/filepath"
@@ -417,6 +418,11 @@ func SubmitInstall(ctx *context.Context) {
417418
}
418419

419420
if len(strings.TrimSpace(form.SMTPAddr)) > 0 {
421+
if _, err := mail.ParseAddress(form.SMTPFrom); err != nil {
422+
ctx.RenderWithErr(ctx.Tr("install.smtp_from_invalid"), tplInstall, &form)
423+
return
424+
}
425+
420426
cfg.Section("mailer").Key("ENABLED").SetValue("true")
421427
cfg.Section("mailer").Key("SMTP_ADDR").SetValue(form.SMTPAddr)
422428
cfg.Section("mailer").Key("SMTP_PORT").SetValue(form.SMTPPort)

0 commit comments

Comments
 (0)