---
title: Clear-Site-Data清理与风险处置(cookies/storage/cache)最佳实践
keywords:
- Clear-Site-Data
- cookies
- storage
- cache
- 会话清理
description: 通过在风险处置或登出流程下发Clear-Site-Data头,统一清理cookies/storage/cache,降低残留数据导致的越权与隐私风险。
categories:
- 文章资讯
- 编程技术
---
背景与价值
在风控或登出时清理站点数据可降低残留风险。Clear-Site-Data提供标准化的清理能力,保障会话与隐私安全。
统一规范
- 清理维度:
"cookies","storage","cache"。 - 条件触发:风控、登出或高风险处置时启用。
- 搭配:配合
Set-Cookie清除会话标识。
核心实现
头设置
type Res = { setHeader: (k: string, v: string) => void; end: (b?: string) => void }
function clearSiteData(res: Res, cookies = true, storage = true, cache = true) {
const items: string[] = []
if (cookies) items.push('"cookies"')
if (storage) items.push('"storage"')
if (cache) items.push('"cache"')
res.setHeader('Clear-Site-Data', items.join(', '))
}
落地建议
- 在登出与高风险处置中统一下发清理头并清除会话Cookie,提升安全。
验证清单
- 是否下发包含必要维度的Clear-Site-Data;会话是否同步清除。

发表评论 取消回复