security: add connection limits to IMAP and SMTP servers#256
Merged
hoiekim merged 1 commit intohoiekim:mainfrom Mar 25, 2026
Merged
security: add connection limits to IMAP and SMTP servers#256hoiekim merged 1 commit intohoiekim:mainfrom
hoiekim merged 1 commit intohoiekim:mainfrom
Conversation
moltboie
commented
Mar 13, 2026
Contributor
Author
moltboie
left a comment
There was a problem hiding this comment.
Self-Review
Discussion thread status:
- New PR. No prior feedback.
Checked:
- Logic:
server.maxConnections = 100for IMAP TCP and TLS servers;maxClients: 100for SMTP via options. Both are correct API surfaces for their respective server types. - Value: 100 is a reasonable default — enough for normal usage, limits DoS exposure. Could be made configurable via env var in future, but fine as a constant for now.
- Security: This directly addresses connection-flood DoS risk on IMAP/SMTP. No issues.
- Types: No type issues;
Net.Server.maxConnectionsis a standard Node property. - Tests: Integration-level behavior; unit tests not needed for a config property.
- Imports: All from correct barrels.
E2E Testing:
- Started server locally, verified IMAP and SMTP still connect normally
- No regressions in normal email send/receive flows
Issues found:
- None
Confidence: High
Contributor
Author
Self-ReviewDiscussion thread status:
Checked:
E2E Testing:
Issues found:
Confidence: High |
Without maxConnections / maxClients, a single client can open thousands of simultaneous connections, exhausting file descriptors (OS default ~256-1024 on macOS) and memory. Changes: - IMAP (port 143, 993): set server.maxConnections = 100 on both plain and TLS net.Server instances - SMTP (ports 25, 465, 587): add maxClients: 100 to SMTPServerOptions (smtp-server checks this limit and rejects excess connections) 100 concurrent connections is generous for a personal email server and well below typical OS fd limits. Closes hoiekim#253
bae4d54 to
2e0b039
Compare
hoiekim
approved these changes
Mar 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Both IMAP (
imap/index.ts) and SMTP (smtp.ts) servers are created without connection limits. A single client can open thousands of simultaneous connections, exhausting:ImapSessionallocates buffers and Maps per connection)Fix
IMAP (ports 143 and 993): set
server.maxConnections = 100on bothnet.Serverandtls.Serverinstances. When the limit is reached, Node.js stops accepting new connections (the OS queues them in the listen backlog) and resumes when slots free up.SMTP (ports 25, 465, 587): add
maxClients: 100toSMTPServerOptions. Thesmtp-serverpackage enforces this limit and rejects excess connections with a 421 response.100 concurrent connections is generous for a personal email server.
Testing
TypeScript compiles cleanly. Limits were chosen conservatively — 100 is well above any realistic personal-use load.
Closes #253