Skip to content
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

fix: trim config before use #1756

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cmd/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ func handleUpdateSettings(c echo.Context) error {
set.SMTP[i].UUID = uuid.Must(uuid.NewV4()).String()
}

// Ensure the HOST is trimmed of any whitespace.
// This is a common mistake when copy-pasting SMTP settings.
set.SMTP[i].Host = strings.TrimSpace(s.Host)

// If there's no password coming in from the frontend, copy the existing
// password by matching the UUID.
if s.Password == "" {
Expand All @@ -134,6 +138,10 @@ func handleUpdateSettings(c echo.Context) error {
set.BounceBoxes[i].UUID = uuid.Must(uuid.NewV4()).String()
}

// Ensure the HOST is trimmed of any whitespace.
// This is a common mistake when copy-pasting SMTP settings.
set.BounceBoxes[i].Host = strings.TrimSpace(s.Host)

if d, _ := time.ParseDuration(s.ScanInterval); d.Minutes() < 1 {
return echo.NewHTTPError(http.StatusBadRequest, app.i18n.T("settings.bounces.invalidScanInterval"))
}
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ export default Vue.extend({
// SMTP boxes.
let hasDummy = '';
for (let i = 0; i < form.smtp.length; i += 1) {
// trim the host before saving
form.smtp[i].host = form.smtp[i].host?.trim();

// If it's the dummy UI password placeholder, ignore it.
if (this.isDummy(form.smtp[i].password)) {
form.smtp[i].password = '';
Expand All @@ -128,6 +131,9 @@ export default Vue.extend({

// Bounces boxes.
for (let i = 0; i < form['bounce.mailboxes'].length; i += 1) {
// trim the host before saving
form['bounce.mailboxes'][i].host = form['bounce.mailboxes'][i].host?.trim();

// If it's the dummy UI password placeholder, ignore it.
if (this.isDummy(form['bounce.mailboxes'][i].password)) {
form['bounce.mailboxes'][i].password = '';
Expand Down