Skip to content

Commit

Permalink
fix: prevent spamming users that do not use smtp anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Nov 22, 2023
1 parent 956d0a7 commit b273f3d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/views/layout.pug
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//- Pug makes it DOCTYPE if we do this:
//- `doctype html`
!= "<!doctype html>"
- const isNotPrivateRoute = ["/my-account", "/admin", "/verify", "/denylist", "/forgot-password", "/reset-password", "/help", "/auth", "/register", config.loginOtpRoute, config.loginRoute, config.verifyRoute].every((s) => !ctx.pathWithoutLocale.startsWith(s));
- const isNotPrivateRoute = ["/my-account", "/admin", "/verify", "/denylist", "/forgot-password", "/reset-password", "/help", "/auth", "/register", config.loginOtpRoute, config.loginRoute, config.verifyRoute, config.otpRoutePrefix].every((s) => !ctx.pathWithoutLocale.startsWith(s));
html.h-100.no-js(
lang=locale,
class=isBot(ctx.get("User-Agent")) ? "bot-detected" : ""
Expand Down
4 changes: 2 additions & 2 deletions ecosystem-sqlite.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
{
"name": "sqlite",
"script": "sqlite.js",
"exec_mode": "fork",
"wait_ready": true,
"instances": "1",
"exec_mode": "cluster",
"instances": "max",
"pmx": false,
"env_production": {
"NODE_ENV": "production"
Expand Down
17 changes: 12 additions & 5 deletions helpers/parse-payload.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const getDatabase = require('#helpers/get-database');
const getPathToDatabase = require('#helpers/get-path-to-database');
const i18n = require('#helpers/i18n');
const isCodeBug = require('#helpers/is-code-bug');
const isTimeoutError = require('#helpers/is-timeout-error');
const logger = require('#helpers/logger');
const migrateSchema = require('#helpers/migrate-schema');
const onAppend = require('#helpers/imap/on-append');
Expand Down Expand Up @@ -153,10 +154,12 @@ async function getTemporaryDatabase(payload) {
}

// release lock
try {
await releaseLock(this, tmpDb, lock);
} catch (err) {
logger.fatal(err, { payload });
if (lock) {
try {
await releaseLock(this, tmpDb, lock);
} catch (err) {
logger.fatal(err, { payload });
}
}

return tmpDb;
Expand Down Expand Up @@ -744,7 +747,11 @@ async function parsePayload(data, ws) {
logger.fatal(err, { payload });
}
} catch (err) {
logger.error(err, { payload });
if (isTimeoutError(err)) {
logger.warn(err, { payload });
} else {
logger.error(err, { payload });
}
}

//
Expand Down
9 changes: 4 additions & 5 deletions helpers/process-email.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ const { authenticate } = require('mailauth');
const { dkimSign } = require('mailauth/lib/dkim/sign');
const { isEmail } = require('validator');

const sendEmail = require('./send-email');

const combineErrors = require('./combine-errors');
const createBounce = require('./create-bounce');
const createSession = require('./create-session');
Expand All @@ -34,12 +32,13 @@ const getBlockedHashes = require('./get-blocked-hashes');
const getErrorCode = require('./get-error-code');
const i18n = require('./i18n');
const isCodeBug = require('./is-code-bug');
const logger = require('./logger');
const parseRootDomain = require('./parse-root-domain');
const { decrypt } = require('./encrypt-decrypt');
const isRetryableError = require('./is-retryable-error');
const isSSLError = require('./is-ssl-error');
const isTLSError = require('./is-tls-error');
const logger = require('./logger');
const parseRootDomain = require('./parse-root-domain');
const sendEmail = require('./send-email');
const { decrypt } = require('./encrypt-decrypt');

const config = require('#config');
const env = require('#config/env');
Expand Down
14 changes: 12 additions & 2 deletions jobs/check-smtp.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const pMapSeries = require('p-map-series');
const sharedConfig = require('@ladjs/shared-config');
const mongoose = require('mongoose');

const Emails = require('#models/emails');
const Domains = require('#models/domains');
const config = require('#config');
const createTangerine = require('#helpers/create-tangerine');
Expand Down Expand Up @@ -138,11 +139,20 @@ async function mapper(id) {
return;
}

// only email the user if there were emails in the past 30+ days
// (otherwise we spam users that may no longer use outbound smtp)
const count = await Emails.countDocuments({
domain: domain._id,
created_at: {
$gte: dayjs().subtract(1, 'month').toDate()
}
});

const isVerified = dkim && returnPath && dmarc;

if (domain.has_smtp && !isVerified) {
domain.smtp_verified_at = undefined;
if (!_.isDate(domain.missing_smtp_sent_at)) {
if (count > 0 && !_.isDate(domain.missing_smtp_sent_at)) {
// if the domain has_smtp and it is not verified
// and it hasn't been sent error notification
// then send the notification and mark it as being sent
Expand Down Expand Up @@ -172,7 +182,7 @@ async function mapper(id) {
}
} else if (!domain.has_smtp && isVerified) {
domain.missing_smtp_sent_at = undefined;
if (!_.isDate(domain.smtp_verified_at)) {
if (count > 0 && !_.isDate(domain.smtp_verified_at)) {
// otherwise if the domain was newly verified
// and doesn't have smtp yet then email admins
const subject = i18n.translate(
Expand Down

0 comments on commit b273f3d

Please sign in to comment.