fix: limit SEND_MAIL domain checks to binding paths (#987)

* fix: scope SEND_MAIL domain gating to binding

* test: cover SEND_MAIL domain gating in e2e
This commit is contained in:
Dream Hunter
2026-04-17 18:08:19 +08:00
committed by GitHub
parent e772db8c3e
commit 000cd0ddfa
11 changed files with 124 additions and 4 deletions
+17 -2
View File
@@ -2,7 +2,7 @@ import { Context } from 'hono';
import { Jwt } from 'hono/utils/jwt'
import { WorkerMailerOptions } from 'worker-mailer';
import { getBooleanValue, getDomains, getStringValue, getIntValue, getUserRoles, getDefaultDomains, getJsonSetting, getAnotherWorkerList, hashPassword, getJsonObjectValue, getRandomSubdomainDomains } from './utils';
import { getBooleanValue, getDomains, getStringArray, getStringValue, getIntValue, getUserRoles, getDefaultDomains, getJsonSetting, getAnotherWorkerList, hashPassword, getJsonObjectValue, getRandomSubdomainDomains } from './utils';
import { unbindTelegramByAddress } from './telegram_api/common';
import { CONSTANTS } from './constants';
import { AddressCreationSettings, AdminWebhookSettings, WebhookMail, WebhookSettings } from './models';
@@ -44,11 +44,26 @@ export const isSendMailEnabled = (
if (smtpConfigMap && smtpConfigMap[mailDomain]) return true;
// Check SEND_MAIL binding
if (c.env.SEND_MAIL) return true;
if (isSendMailBindingEnabled(c, mailDomain)) return true;
return false;
}
export const isSendMailBindingEnabled = (
c: Context<HonoCustomType>,
mailDomain: string
): boolean => {
if (!c.env.SEND_MAIL) {
return false;
}
const sendMailDomains = getStringArray(c.env.SEND_MAIL_DOMAINS)
.map((domain) => normalizeDomainValue(domain));
if (sendMailDomains.length === 0) {
return true;
}
return sendMailDomains.includes(normalizeDomainValue(mailDomain));
}
/**
* Check if send mail is enabled for any configured domain
*/