Skip to content

Commit c16cc2b

Browse files
committed
fix: TLS Cookie without "secure" flag
1 parent e73371c commit c16cc2b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

phpmyfaq/src/Bootstrap.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@
123123
$faqConfig = new Configuration($db);
124124
$faqConfig->getAll();
125125

126+
$secureCookie = 'false';
127+
if (isset($_SERVER['HTTPS']) && strtoupper($_SERVER['HTTPS']) === 'ON') {
128+
$secureCookie = 'true';
129+
}
130+
126131
//
127132
// We always need a valid session!
128133
//
@@ -131,6 +136,7 @@
131136
ini_set('session.use_trans_sid', '0');
132137
ini_set('session.cookie_samesite', 'Strict');
133138
ini_set('session.cookie_httponly', 'true');
139+
ini_set('session.cookie_secure', $secureCookie);
134140
ini_set('url_rewriter.tags', '');
135141

136142
//

phpmyfaq/src/phpMyFAQ/Session.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,9 @@ public function userTracking(string $action, $data = null): void
356356
*/
357357
public function setCookie(string $name, $sessionId, int $timeout = 3600): bool
358358
{
359-
$protocol = 'http';
359+
$secure = false;
360360
if (isset($_SERVER['HTTPS']) && strtoupper($_SERVER['HTTPS']) === 'ON') {
361-
$protocol = 'https';
361+
$secure = true;
362362
}
363363

364364
if (PHP_VERSION_ID < 70300) {
@@ -368,7 +368,7 @@ public function setCookie(string $name, $sessionId, int $timeout = 3600): bool
368368
$_SERVER['REQUEST_TIME'] + $timeout,
369369
dirname($_SERVER['SCRIPT_NAME']) . '; samesite=strict',
370370
parse_url($this->config->getDefaultUrl(), PHP_URL_HOST),
371-
'https' === $protocol, // only secure running via HTTPS
371+
$secure,
372372
true
373373
);
374374
} else {
@@ -380,7 +380,7 @@ public function setCookie(string $name, $sessionId, int $timeout = 3600): bool
380380
'path' => dirname($_SERVER['SCRIPT_NAME']),
381381
'domain' => parse_url($this->config->getDefaultUrl(), PHP_URL_HOST),
382382
'samesite' => 'strict',
383-
'secure' => 'https' === $protocol, // only secure running via HTTPS
383+
'secure' => $secure,
384384
'httponly' => true,
385385
]
386386
);

0 commit comments

Comments
 (0)