365日更挑战

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

2021-10-27  本文已影响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";

}
上一篇 下一篇

猜你喜欢

热点阅读