-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(loop): reject messages with too many Received headers
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
// Set module title | ||
module.exports.title = 'DeliveryLoop'; | ||
|
||
// Initialize the module | ||
module.exports.init = (app, done) => { | ||
const MAX_HOPS = app.config.maxHops || 25; | ||
|
||
app.addHook('message:headers', (envelope, messageInfo, next) => { | ||
let receivedLength = envelope.headers.get('Received').length; | ||
|
||
if (receivedLength > MAX_HOPS) { | ||
// too many hops | ||
app.logger.info('DeliveryLoop', 'Too many hops (%s)! Delivery loop detected for %s, rejecting message', receivedLength, envelope.id); | ||
let err = new Error(`A delivery loop was detected which causes this email which caused the email to be undeliverable (${receivedLength})`); | ||
err.name = 'SMTPResponse'; | ||
err.responseCode = 500; | ||
return next(err); | ||
} | ||
|
||
// allow the message to pass | ||
return next(); | ||
}); | ||
|
||
// all set up regarding this plugin | ||
done(); | ||
}; |