Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit edfa29b

Browse files
author
Miha Vrhovnik
committed
session data needs to be encoded because it can contain non binary safe
characters e.g null. Fixes #2067
1 parent d2d849c commit edfa29b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/Symfony/Component/HttpFoundation/SessionStorage/PdoSessionStorage.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public function sessionRead($id)
182182
$sessionRows = $stmt->fetchAll(\PDO::FETCH_NUM);
183183

184184
if (count($sessionRows) == 1) {
185-
return $sessionRows[0][0];
185+
return base64_decode($sessionRows[0][0]);
186186
}
187187

188188
// session does not exist, create it
@@ -218,9 +218,11 @@ public function sessionWrite($id, $data)
218218
: "UPDATE $dbTable SET $dbDataCol = :data, $dbTimeCol = :time WHERE $dbIdCol = :id";
219219

220220
try {
221+
//session data can contain non binary safe characters so we need to encode it
222+
$encoded = base64_encode($data);
221223
$stmt = $this->db->prepare($sql);
222224
$stmt->bindParam(':id', $id, \PDO::PARAM_STR);
223-
$stmt->bindParam(':data', $data, \PDO::PARAM_STR);
225+
$stmt->bindParam(':data', $encoded, \PDO::PARAM_STR);
224226
$stmt->bindValue(':time', time(), \PDO::PARAM_INT);
225227
$stmt->execute();
226228

@@ -252,9 +254,11 @@ private function createNewSession($id, $data = '')
252254

253255
$sql = "INSERT INTO $dbTable ($dbIdCol, $dbDataCol, $dbTimeCol) VALUES (:id, :data, :time)";
254256

257+
//session data can contain non binary safe characters so we need to encode it
258+
$encoded = base64_encode($data);
255259
$stmt = $this->db->prepare($sql);
256260
$stmt->bindParam(':id', $id, \PDO::PARAM_STR);
257-
$stmt->bindParam(':data', $data, \PDO::PARAM_STR);
261+
$stmt->bindParam(':data', $encoded, \PDO::PARAM_STR);
258262
$stmt->bindValue(':time', time(), \PDO::PARAM_INT);
259263
$stmt->execute();
260264

0 commit comments

Comments
 (0)