fix: reject dynamic links in imported mail templates

This commit is contained in:
abaishu0730 committed 2026-10-21 16:05:53 +08:00
1 parent 2fe5a3fe5d
commit 2cf776d7d8
2 files changed
+16 -2

No files matched your search

+1 -1
View File
@@ -6,7 +6,7 @@ const escape=value=>String(value??'').replace(/[&<>"']/g,c=>({'&':'&amp;','<':'&
const VARIABLES=['产品线','订单号','日期','订单列表','订单明细','存放地址','类别名称'];
function validateVariables(...parts){for(const part of parts)for(const token of String(part||'').matchAll(/{{([\s\S]*?)}}/g))if(!VARIABLES.includes(token[1].trim()))fail('模板含有不支持的变量,请使用:'+VARIABLES.map(x=>'{{'+x+'}}').join('、'));}
function safeLink(value){
if(typeof value!=='string'||!/^https?:\/\/[^/?#]/i.test(value)||/[\s\p{Cc}\p{Cf}\\]/u.test(value))return false;
if(typeof value!=='string'||!/^https?:\/\/[^/?#]/i.test(value)||/{{|}}/.test(value)||/[\s\p{Cc}\p{Cf}\\]/u.test(value))return false;
try{
if(/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}\\]/u.test(decodeURIComponent(value)))return false;
const url=new URL(value),authority=value.slice(value.indexOf('://')+3).split(/[/?#]/,1)[0];