Skip to content

Potential fix for code scanning alert no. 2: Email content injection#64

Merged
ziembor merged 1 commit into
mainfrom
alert-autofix-2
May 6, 2026
Merged

Potential fix for code scanning alert no. 2: Email content injection#64
ziembor merged 1 commit into
mainfrom
alert-autofix-2

Conversation

@ziembor
Copy link
Copy Markdown
Owner

@ziembor ziembor commented May 6, 2026

Potential fix for https://github.com/ziembor/gomailtesttool/security/code-scanning/2

General fix: sanitize/normalize untrusted email fields at request handling time before placing them into config, so downstream SMTP writing only receives pre-sanitized content. This is the best single fix because it addresses both alert variants at the trust boundary (r.Body flow), preserves existing behavior, and complements existing sanitization in buildEmailMessage.

Best concrete change:

  • In internal/serve/smtp_handler.go, add local sanitization helpers for subject/body.
  • Apply them when assigning cfg.Subject and cfg.Body (lines around current 64–65 in provided snippet).
  • Use existing strings package functions (add strings import) to:
    • strip CR/LF from subject to avoid header-shaping behavior and normalize whitespace;
    • normalize body newlines and remove unsafe control chars except \n and \t.

No external dependency is required.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@ziembor ziembor marked this pull request as ready for review May 6, 2026 15:34
@ziembor ziembor merged commit 04d674b into main May 6, 2026
3 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant