Skip to content

Commit 317d16e

Browse files
committed
Prevent emulation of SQL prepare-statements
1 parent 36f92e3 commit 317d16e

4 files changed

Lines changed: 5 additions & 0 deletions

File tree

docs/simplesamlphp-customauth.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ class MyAuth extends \SimpleSAML\Module\core\Auth\UserPassBase
352352
/* Connect to the database. */
353353
$db = new PDO($this->dsn, $this->username, $this->password, $this->options);
354354
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
355+
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
355356

356357
/* Ensure that we are operating with UTF-8 encoding.
357358
* This command is for MySQL. Other databases may need different commands.

modules/core/src/Storage/SQLPermanentStorage.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public function __construct(string $name, ?Configuration $config = null)
6565
$this->db = new PDO($dbfile);
6666
if ($this->db) {
6767
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
68+
$this->db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
69+
6870
$q = @$this->db->query('SELECT key1 FROM data LIMIT 1');
6971
if ($q === false) {
7072
$this->db->exec('

src/SimpleSAML/Database.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ private function connect(
162162
try {
163163
$db = new PDO($dsn, $username, $password, $options);
164164
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
165+
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
165166

166167
return $db;
167168
} catch (PDOException $e) {

src/SimpleSAML/Store/SQLStore.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function __construct()
7878
throw new Exception("Database error: " . $e->getMessage());
7979
}
8080
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
81+
$this->pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
8182

8283
$this->driver = $this->pdo->getAttribute(PDO::ATTR_DRIVER_NAME);
8384

0 commit comments

Comments
 (0)