aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarlos Felgueiras <carlosfelgueiras@tecnico.ulisboa.pt>2024-02-24 00:02:14 +0100
committerGitHub <noreply@github.com>2024-02-23 23:02:14 +0000
commit6f6120dfa8d549d0b866eeb9317054fea831c844 (patch)
treec53e23d8ea5c87e5f01ca6210bdd4ce216cc010c
parent08c1926e1c3e2487f207b5f225d8b0f2831d0708 (diff)
downloadgitea-6f6120dfa8d549d0b866eeb9317054fea831c844.tar.gz
gitea-6f6120dfa8d549d0b866eeb9317054fea831c844.zip
Fix validity of the FROM email address not being checked (#29347)
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: KN4CK3R <admin@oldschoolhack.me>
-rw-r--r--options/locale/locale_en-US.ini1
-rw-r--r--routers/install/install.go6
2 files changed, 7 insertions, 0 deletions
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index ae34d72e41..31dbabe874 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -247,6 +247,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@example.com> format.
mailer_user = SMTP Username
mailer_password = SMTP Password
diff --git a/routers/install/install.go b/routers/install/install.go
index 78372669f4..decf74cecb 100644
--- a/routers/install/install.go
+++ b/routers/install/install.go
@@ -7,6 +7,7 @@ package install
import (
"fmt"
"net/http"
+ "net/mail"
"os"
"os/exec"
"path/filepath"
@@ -419,6 +420,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)