Skip to content

Commit d4c8e8a

Browse files
feat(appconfig): add email security options for TLS and HTML handling
- Add IgnoreTLSErrors option for insecure TLS connections - Add AllowUnsafeHTML option for unsafe HTML embedding in Markdown - Support configuration via config.yaml, environment variables, and CLI flags - Include validation for security-sensitive options - Document security implications in defaults and comments
1 parent 6f7599c commit d4c8e8a

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

internal/appconfig/appconfig.go

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/*
2+
Copyright © 2025 canaria-computer
3+
*/
14
package appconfig
25

36
import (
@@ -88,9 +91,10 @@ type ConsentConfig struct {
8891
}
8992

9093
type EmailConfig struct {
91-
IMAP IMAPConfig `koanf:"imap"`
92-
SMTP SMTPConfig `koanf:"smtp"`
93-
MimeType string `koanf:"mime-type"`
94+
IMAP IMAPConfig `koanf:"imap"`
95+
SMTP SMTPConfig `koanf:"smtp"`
96+
MimeType string `koanf:"mime_type"`
97+
Security SecurityConfig `koanf:"security"`
9498
}
9599

96100
type IMAPConfig struct {
@@ -104,6 +108,21 @@ type SMTPConfig struct {
104108
Secure string `koanf:"secure"`
105109
}
106110

111+
// SecurityConfig contains security-related options for email operations
112+
type SecurityConfig struct {
113+
// IgnoreTLSErrors allows SMTP/IMAP connections to proceed even if TLS verification fails.
114+
// WARNING: This disables certificate validation and should only be used for testing with
115+
// self-signed certificates or in development environments. Do NOT use in production.
116+
// Default: false (TLS verification is enforced)
117+
IgnoreTLSErrors bool `koanf:"ignore_tls_errors"`
118+
119+
// AllowUnsafeHTML permits the embedding of potentially unsafe HTML in Markdown-generated emails.
120+
// WARNING: When enabled, user-supplied or untrusted HTML content may be embedded without sanitization,
121+
// potentially leading to XSS attacks or malicious content injection. Only enable if you trust the source
122+
// of the HTML content. Default: false (unsafe HTML is sanitized/escaped)
123+
AllowUnsafeHTML bool `koanf:"allow_unsafe_html"`
124+
}
125+
107126
var globalConfig *AppConfig
108127
var globalKoanf *koanf.Koanf
109128

@@ -147,6 +166,10 @@ func DefaultConfig() *AppConfig {
147166
// Defaults removed
148167
},
149168
MimeType: "text/plain",
169+
Security: SecurityConfig{
170+
IgnoreTLSErrors: false, // TLS verification enforced by default
171+
AllowUnsafeHTML: false, // HTML sanitization enforced by default
172+
},
150173
},
151174
}
152175
}
@@ -267,6 +290,14 @@ func ValidateConfig(cfg *AppConfig) []error {
267290
errs = append(errs, fmt.Errorf("email.mime-type must be one of: text/plain, multipart/alternative"))
268291
}
269292

293+
// Warn about security options in production
294+
if cfg.Email.Security.IgnoreTLSErrors {
295+
errs = append(errs, fmt.Errorf("SECURITY WARNING: email.security.ignore_tls_errors is enabled - TLS verification is disabled (development only)"))
296+
}
297+
if cfg.Email.Security.AllowUnsafeHTML {
298+
errs = append(errs, fmt.Errorf("SECURITY WARNING: email.security.allow_unsafe_html is enabled - unsafe HTML will be embedded without sanitization (untrusted content at risk)"))
299+
}
300+
270301
return errs
271302
}
272303

0 commit comments

Comments
 (0)