Binding of IP address with Session id

前端 未结 4 2149
情话喂你
情话喂你 2021-02-10 02:36

To prevent the session fixation problem, how can we bind the IP address with the session id? Is it possible to bind the session id with that of the IP address??

相关标签:
4条回答
  • 2021-02-10 03:08

    I don't think that this is a good idea. Subsequent request from the same users might not necessarily come from the same IP address because the request might come from a different proxy. IIRC this used to be the case for all AOL users and might be the case for other providers or some corporate networks, too.

    It is better to secure your session with page tokens to prevent highjacking a session.

    0 讨论(0)
  • 2021-02-10 03:12

    I've read some article about it before. it is possible that you check the user IP address as an extra session meta data. but if you want to use it as a general session ID, you might have problem to deal with users behind a certain proxy gateway, where all users will have the same IP address. although it could be used to prevent session theft (using techniques like cookie highjacking) for some level. but it should be considered that the cookie hijacker can also mimic the IP address of the victim. so checking the user session and also the IP address can be a good practice to have a higher security, but is not a bullet proof solution.

    0 讨论(0)
  • 2021-02-10 03:19

    http://en.wikipedia.org/wiki/Session_fixation

    if($_SERVER['REMOTE_ADDR'] != $_SESSION['PREV_REMOTEADDR']) {
       session_destroy(); // destroy all data in session
    }
    session_regenerate_id(); // generate a new session identifier
    $_SESSION['PREV_REMOTEADDR'] = $_SERVER['REMOTE_ADDR'];
    
    0 讨论(0)
  • 2021-02-10 03:34

    You can, but its not such a good idea. If your client is behind a farm of proxies their external IP address may change on every request. AOL do this, for example.

    0 讨论(0)
提交回复
热议问题