mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-09-10 18:07:00 +08:00
fix: enhance input validation with trim() for address creation
- Add trim() handling in newAddress() function to prevent whitespace issues - Add trim() handling for address prefixes to ensure consistent formatting - Add trim() handling in Telegram API address parsing for robustness - Prevents edge cases with whitespace-only or padded input strings 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude
parent
711378cb11
commit
8e5293f010
@@ -101,8 +101,8 @@ export const newAddress = async (
|
|||||||
enableCheckNameRegex?: boolean,
|
enableCheckNameRegex?: boolean,
|
||||||
}
|
}
|
||||||
): Promise<{ address: string, jwt: string }> => {
|
): Promise<{ address: string, jwt: string }> => {
|
||||||
// remove special characters
|
// trim whitespace and remove special characters
|
||||||
name = name.replace(getNameRegex(c), '')
|
name = name.trim().replace(getNameRegex(c), '')
|
||||||
// check name
|
// check name
|
||||||
if (enableCheckNameRegex) {
|
if (enableCheckNameRegex) {
|
||||||
await checkNameBlockList(c, name);
|
await checkNameBlockList(c, name);
|
||||||
@@ -127,9 +127,9 @@ export const newAddress = async (
|
|||||||
}
|
}
|
||||||
// create address with prefix
|
// create address with prefix
|
||||||
if (typeof addressPrefix === "string") {
|
if (typeof addressPrefix === "string") {
|
||||||
name = addressPrefix + name;
|
name = addressPrefix.trim() + name;
|
||||||
} else if (enablePrefix) {
|
} else if (enablePrefix) {
|
||||||
name = getStringValue(c.env.PREFIX) + name;
|
name = getStringValue(c.env.PREFIX).trim() + name;
|
||||||
}
|
}
|
||||||
// check domain
|
// check domain
|
||||||
const allowDomains = checkAllowDomains ? await getAllowDomains(c) : getDomains(c);
|
const allowDomains = checkAllowDomains ? await getAllowDomains(c) : getDomains(c);
|
||||||
|
|||||||
@@ -18,8 +18,9 @@ export const tgUserNewAddress = async (
|
|||||||
// Check if custom address names are disabled
|
// Check if custom address names are disabled
|
||||||
const disableCustomAddressName = getBooleanValue(c.env.DISABLE_CUSTOM_ADDRESS_NAME);
|
const disableCustomAddressName = getBooleanValue(c.env.DISABLE_CUSTOM_ADDRESS_NAME);
|
||||||
|
|
||||||
// Parse address parameter
|
// Parse address parameter - handle empty or whitespace-only address
|
||||||
const [name, domain] = address.includes("@") ? address.split("@") : [address, null];
|
const trimmedAddress = address ? address.trim() : "";
|
||||||
|
const [name, domain] = trimmedAddress.includes("@") ? trimmedAddress.split("@") : [trimmedAddress, null];
|
||||||
const jwtList = await c.env.KV.get<string[]>(`${CONSTANTS.TG_KV_PREFIX}:${userId}`, 'json') || [];
|
const jwtList = await c.env.KV.get<string[]>(`${CONSTANTS.TG_KV_PREFIX}:${userId}`, 'json') || [];
|
||||||
if (jwtList.length >= getIntValue(c.env.TG_MAX_ADDRESS, 5)) {
|
if (jwtList.length >= getIntValue(c.env.TG_MAX_ADDRESS, 5)) {
|
||||||
throw Error("绑定地址数量已达上限");
|
throw Error("绑定地址数量已达上限");
|
||||||
|
|||||||
Reference in New Issue
Block a user