phalcon/incubator

DB Session adapter corupts session data with Postgresql DB

Maximskv opened this issue · 0 comments

Expected and Actual Behavior

When using the Db session adapter with Postgresql the session fails to be written and read properly.
The adapter serializes the session->data and tries to store the result in a text field. The serialized session->data text has null bytes. Postgresql is omitting everything after the first null byte resulting in cropped session->data that cannot be read, rendering the whole component unusable.

A quick dirty fix I have used to overcome the issue:

  1. Use a json type field for the data field in the DB session table.
  2. json_encode() the session->data prior to writing it to db (json_decode the data after reading it respectively ).

As demonstrated in this gist.

Steps to reproduce:

will add a demonstration project at a later point

  1. Use the DB session adapter with a Postgresql database
  2. Generate a new session.
  3. Try to read the generated session -> fails as the serialized session->data has been corrupted while being saved to the db.

Details

  • Phalcon Framework version: 4.0
  • Phalcon Incubator version: 1.1
  • PHP Version: 7.4
  • Operating System: maxOS
  • Server: Nginx | Apache
  • Other related info :
    • Database : Postgresql 13.1