---

title: IDN同形异义域名防护与Punycode治理最佳实践

keywords:

  • IDN
  • Punycode
  • 同形异义
  • 域名白名单
  • ASCII策略

description: 通过ASCII域名策略与Punycode标识检测、白名单治理与来源校验,防止IDN同形异义域名造成的钓鱼与混淆风险。

categories:

  • 文章资讯
  • 编程技术

---

背景与价值

IDN可能引入同形异义攻击。采用ASCII策略与Punycode检测可降低风险并提升治理效率。

统一规范

  • ASCII策略:默认仅接受ASCII域名(A-Za-z0-9.-)。
  • Punycode检测:标识 xn-- 前缀的域名并仅白名单允许。
  • 来源校验:对来源域进行严格匹配与审计。

核心实现

域名校验

const allowHosts = new Set(['app.example.com','api.example.com'])

function asciiHost(h: string): boolean { return /^[A-Za-z0-9.-]+$/.test(h) }
function isPunycode(h: string): boolean { return h.toLowerCase().includes('xn--') }

function hostAllowed(h: string): boolean {
  const host = h.toLowerCase()
  if (!asciiHost(host)) return false
  if (isPunycode(host) && !allowHosts.has(host)) return false
  return allowHosts.has(host)
}

来源校验

function originAllowed(o: string | undefined): boolean { if (!o) return false; try { const u = new URL(o); return hostAllowed(u.hostname) } catch { return false } }

落地建议

  • 默认仅接受ASCII域名来源;对含 xn-- 的Punycode域名实行白名单策略。
  • 对来源进行严格校验与审计,发现疑似同形域名及时加入屏蔽清单。

验证清单

  • 来源域名是否为ASCII或白名单Punycode;是否严格匹配允许集合。

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部