风险与安全写法对比
风险与安全写法对比
风险:/login?next=https://伪装站点.example
安全:仅接受以 / 开头的相对路径,或使用跳转映射表
if not next_url.startswith('/') or next_url.startswith('//'):
next_url = '/'校验时同时拒绝 // 与 /\ 开头的双斜杠形式(协议相对跳转),并在统一解码后再判断。
应用把用户可控参数当作跳转目标(redirect、next、returnUrl 等),可被用于钓鱼与凭据诱导;防护是使用站内相对路径或白名单映射,避免直接透传完整 URL。
风险:/login?next=https://伪装站点.example
安全:仅接受以 / 开头的相对路径,或使用跳转映射表
if not next_url.startswith('/') or next_url.startswith('//'):
next_url = '/'