che*_*nj7 2 python authentication tornado
我刚刚在线添加了一些使用tornado.web.authenticated的简单登录.不幸的是,在成功注销后,当我按下浏览器上的后退按钮时,我仍然可以看到已登录的页面.有没有办法触发浏览历史记录中页面的登录屏幕?
编辑:为了澄清,我已经在使用@ tornado.web.authenticated注释,它适用于正常的用例,但我遇到的问题是,当使用浏览器的Back按钮返回时,我仍然能够看到页面好像我已登录.我希望有办法解决这个潜在的安全问题.
当您在注销后点击后退按钮时,浏览器会从缓存中加载上一页.要防止受保护的页面被缓存,您必须按照此问题中的描述设置以下标题
self.set_header('Cache-Control', 'no-cache, no-store, must-revalidate')
self.set_header('Pragma', 'no-cache')
self.set_header('Expires', '0')
Run Code Online (Sandbox Code Playgroud)
你可以把它放在装饰器中,例如:
def protected(method):
@tornado.web.authenticated
@functools.wraps(method)
def wrapper(self, *args, **kwargs):
self.set_header('Cache-Control', 'no-cache, no-store, must-revalidate')
self.set_header('Pragma', 'no-cache')
self.set_header('Expires', '0')
return method(self, *args, **kwargs)
return wrapper
Run Code Online (Sandbox Code Playgroud)
然后使用@protected而不是@ tornado.web.authenticated装饰受保护的页面.
归档时间: |
|
查看次数: |
351 次 |
最近记录: |