Skip to content

Commit d0db3b1

Browse files
committed
feat: re-enabled rate limiting
1 parent 78ecc1f commit d0db3b1

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

.env.defaults

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ DNSBL_REMOVALS=https://www.spamhaus.org/lookup/,https://www.spamcop.net/bl.shtml
1919
SPAM_SCORE_THRESHOLD=5
2020
MAX_FORWARDED_ADDRESSES=5
2121
TXT_RECORD_PREFIX=forward-email
22-
BLACKLIST=biz-catalogs.com
22+
BLACKLIST=biz-catalogs.com,tiproulette.com,mail.tiproulette.com
2323
CERTBOT_WELL_KNOWN_NAME=
2424
CERTBOT_WELL_KNOWN_CONTENTS=
25+
RATELIMIT_DURATION=3600000
26+
RATELIMIT_MAX=300

.env.schema

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ DNSBL_REMOVALS=
2222
BLACKLIST=
2323
CERTBOT_WELL_KNOWN_NAME=
2424
CERTBOT_WELL_KNOWN_CONTENTS=
25+
RATELIMIT_DURATION=
26+
RATELIMIT_MAX=

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ Yes! As of October 2, 2018 we have added this feature. See [Send Mail As Using
520520
521521
### Can I forward unlimited emails with this
522522
523-
Practically yes - the only current restriction is that senders are limited to sending `200` emails per hour through the system.
523+
Practically yes - the only current restriction is that senders (by unique email address) are limited to sending `300` emails per hour through the system.
524524
525525
If this limit is exceeded we send a `451` response code which tells the senders mail server to retry later.
526526

index.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,12 @@ class ForwardEmail {
160160
);
161161

162162
// setup rate limiting with redis
163-
/*
164163
if (this.config.rateLimit) {
165164
this.limiter = {
166165
db: client,
167166
...this.config.rateLimit
168167
};
169168
}
170-
*/
171169

172170
// expose client
173171
this.client = client;
@@ -944,18 +942,28 @@ class ForwardEmail {
944942
return new Promise((resolve, reject) => {
945943
if (email === this.config.noReply || !this.limiter) return resolve();
946944
const id = email;
947-
const limit = new Limiter({ id, ...this.limiter });
945+
const limit = new Limiter({ ...this.limiter, id });
948946
limit.get((err, limit) => {
949947
if (err) {
950948
err.responseCode = 421;
951949
return reject(err);
952950
}
953951

954-
if (limit.remaining) return resolve();
952+
if (limit.remaining) {
953+
logger.info(
954+
`Rate limit for ${email} is now ${limit.remaining - 1}/${
955+
limit.total
956+
}`
957+
);
958+
return resolve();
959+
}
960+
955961
const delta = (limit.reset * 1000 - Date.now()) | 0;
956962
reject(
957963
new CustomError(
958-
`Rate limit exceeded, retry in ${ms(delta, { long: true })}`,
964+
`Rate limit exceeded for ${id}, retry in ${ms(delta, {
965+
long: true
966+
})}`,
959967
451
960968
)
961969
);

0 commit comments

Comments
 (0)