Constant Flask Session IDs

。_饼干妹妹 提交于 2019-12-05 03:23:14

It looks like you're using the Flask-Login extension. Here's the code that generates the id token:

def _create_identifier():
    base = unicode("%s|%s" % (request.remote_addr,
                              request.headers.get("User-Agent")), 'utf8', errors='replace')
    hsh = md5()
    hsh.update(base.encode("utf8"))
    return hsh.digest()

It's basically just md5(ip_address + user_agent).

Flask uses Werkzeug's secure cookies to store this identifier. Secure cookies are (as their name suggests) secure:

This module implements a cookie that is not alterable from the client because it adds a checksum the server checks for. You can use it as session replacement if all you have is a user id or something to mark a logged in user.

session['_id'] is not an actual session identifier. It's just a value used by Flask-Login to implement Session Protection.

Standard Flask sessions do not have an SID - as it would serve no purpose since the actual content of the session is stored in the cookie itself. Also see this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!