Skip to content

Zend Session would throw an exception "The session has already been started. The session id must be set first." upon receiving an invalid session ID #165

@fredericgboutin-yapla

Description

@fredericgboutin-yapla

Long story short,
We monitored a lot of exceptions this morning on our website, all stating "The session has already been started. The session id must be set first."

There are a lot of different reasons why this message can happen.

Our logs indicated that the user ID values were in fact all attempting to break things up, with PHPSESSID cookie having values like:

  • Thread.Sleep(4*1000);
  • C:/winnt/win.ini
  • ${T(java.lang.System).properties}

Etc.

Upon analysis I stumbled on this old issue zendframework/zend-session#119 which helped me to reproduce the issue on my dev. env. locally with a simple curl command like suggested,

curl -I 'http://your-local-website.com/' -H 'Cookie: PHPSESSID=_test_'

I then Xdebug-ed it to realize that Zend doesn't properly account for the situation when session_id is given a rejected ID. In that situation, the SID constant is defined BUT its value is an empty string (at least, on PHP 7.0.33),

session_id() returns the session id for the current session or the empty string ("") if there is no current session

Source: https://www.php.net/manual/en/function.session-id.php

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions