美文网首页365日更挑战
日更第15日: (翻)nginx加固之避免敏感数据的缓存

日更第15日: (翻)nginx加固之避免敏感数据的缓存

作者: 微凉哇 | 来源:发表于2021-10-27 09:20 被阅读0次

避免敏感数据的缓存

Prevent caching of sensitive data

尽管这个策略应该由应用本身实现,但是,很多时候还是需要反向代理服务进行处理。

不要缓存或持久化敏感数据

由于浏览器对缓存HTTPS内容有不同的默认行为,包含敏感信息的页面应该包含Cache-Control头,以确保内容不被缓存。

实现方式

  1. 在响应中添加防缓存头,例如: Cache-Control: no-cache, no-storeExpires: 0
  2. 为了兼容多种浏览器实现,建议响应头配置如下:
Cache-Control: no-cache, no-store, private, must-revalidate, max-age=0, no-transform
Pragma: no-cache
Expires: 0

nginx配置样例

基于location上下文

location /api {

  expires 0;
  add_header Pragma "no-cache";
  add_header Cache-Control "no-cache, no-store, private, must-revalidate, max-age=0, no-transform";

}

相关文章

网友评论

    本文标题:日更第15日: (翻)nginx加固之避免敏感数据的缓存

    本文链接:https://www.haomeiwen.com/subject/xmutaltx.html