PHP cookie-bases session swapping in phorum

夙愿已清 提交于 2019-12-11 23:19:16

问题


I'm experiencing a strange error in my phorum server - seemingly at random, some users will be swapped with each other, and find themselves fully logged in as one another, with complete access to one another's accounts. I've experienced this bug myself once but cannot recreate it.

Phorum is configured to track sessions via cookie, with the session hashes also stored in the user database. I've confirmed the database is intact and there aren't session ID collisions happening.

You can see the source for phorum's authentication and session management here, it's fairly straightforward. Sessions are only created via log-in or from existing cookies so my working theory (after talking to a phorum developer) is that there is some sort of caching issue on the server. There's a known caching issue that affects ASP (see here or here for examples) but my server is a Linux server running Apache 2.4, MySQL (technically MariaDB 10.1 + InnoDB) and PHP 5.6. Is anyone aware of how this might be happening? I've been plugging away at this for over a week and have made little progress other than confirming the lack of bugs in the phorum session code.

The only clue I have to go on is that the session swapping started on the same day my hosting service took down (and restored) their file servers. They said they don't see how that could be responsible, however.

EDIT #1: I am adding some request and response headers.

Here is the response for an initial GET to get a list of forums. General

Request URL: https://www.example.com/forum/list.php?11 Request

Method: GET Status Code: 200 Remote Address: x.x.x.x:443

Referrer Policy: no-referrer-when-downgrade

Response Headers

content-encoding: gzip content-type: text/html;

charset=UTF-8 date: Mon, 07 May 2018 20:23:08 GMT server: Apache

set-cookie: phorum_session_v5=35%3A412b7c329cc8741de88532342df9; expires=Tue, 08-May-2018 20:23:08 GMT; Max-Age=86400; path=/

status: 200 vary: Accept-Encoding via: e3s

Request Headers

:authority: www.example.com

:method: GET

:path: /forum/list.php?11

:scheme: https

accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8

accept-encoding: gzip, deflate, br accept-language: en-US,en;q=0.9

cache-control: max-age=0

cookie: phorum_session_v5=35%3A412b7c329cc8741de88532342df9;

referer: https://www.example.com/forum/addon.php?11,module=user_list

upgrade-insecure-requests: 1 user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36

And here is a follow-up Ajax call:

General

Request URL: https://www.example.com/forum/ajax.php?client

Request Method: GET Status Code: 200 (from memory cache)

Remote Address: x.x.x.x:443 Referrer Policy: no-referrer-when-downgrade

Response Headers

age: 734

cache-control: must-revalidate

content-encoding: gzip

content-length: 2862

content-type: text/javascript;charset=UTF-8

date: Mon, 07 May 2018 18:29:37 GMT

expires: Tue, 08 May 2018 02:29:37 GMT

pragma: cache

server: Apache

status: 200

vary: Accept-Encoding

via: e2s


回答1:


@Sammitch was correct - phorum was not setting cache-control in the headers for most of my pages. This was causing my hosting service's own caching system to cache responses that included session cookies.

I fixed this by changing my .htaccess file as described here: https://stackoverflow.com/a/7664157/1411376

This seems to work for my server config, since the php code (phorum) had no code that set cache-control (except for ajax requests).



来源:https://stackoverflow.com/questions/50218639/php-cookie-bases-session-swapping-in-phorum

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