Fix helpers/config: timezone, comment leak, silent misconfig, cache perms
- Database.php: pin MySQL session time_zone to the configured named zone (mysql.time_zone tables now loaded on the DB) with a fixed-offset fallback, so NOW()/TIMESTAMP and PHP agree regardless of the DB server's SYSTEM tz. Best-effort, never fatals the connection. - NotificationHelper: redact comment-body previews for internal/ confidential tickets in sendCommentNotification and notifyWatchers so they are not leaked to the shared Matrix notify list (new $visibility param; callers wired in the API batch). - config.php: die with a clear error if parse_ini_file fails instead of silently falling back to insecure defaults (empty DB pass / proxies). - CacheHelper: create cache dir 0700 and cache files 0600 so other local users cannot read or poison security-relevant cached data. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -57,6 +57,32 @@ class Database
|
||||
// Set charset to utf8mb4 for proper Unicode support
|
||||
$conn->set_charset('utf8mb4');
|
||||
|
||||
// Pin the MySQL session time zone to the app's configured zone so that
|
||||
// NOW()/CURRENT_TIMESTAMP and PHP agree on wall-clock time regardless of
|
||||
// the DB server's SYSTEM tz. Prefer the named zone (requires the
|
||||
// mysql.time_zone_* tables); if that isn't available, fall back to the
|
||||
// fixed numeric offset PHP computes for the same zone. Best-effort: a
|
||||
// failure here must never fatal the connection.
|
||||
$tz = $GLOBALS['config']['TIMEZONE'] ?? 'UTC';
|
||||
try {
|
||||
$escaped = $conn->real_escape_string($tz);
|
||||
try {
|
||||
// mysqli throws (does not return false) on failure under the
|
||||
// default PHP 8.1+ report mode, so catch it rather than testing
|
||||
// the return value.
|
||||
$conn->query("SET time_zone = '{$escaped}'");
|
||||
} catch (\Throwable $inner) {
|
||||
// Named zone unavailable (mysql.time_zone_* not populated) — fall
|
||||
// back to a fixed numeric offset so PHP and MySQL still agree on
|
||||
// wall-clock time regardless of the DB server's SYSTEM tz.
|
||||
$offset = (new DateTime('now', new DateTimeZone($tz)))->format('P');
|
||||
$escapedOffset = $conn->real_escape_string($offset);
|
||||
$conn->query("SET time_zone = '{$escapedOffset}'");
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
error_log('Database: failed to set session time_zone: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
return $conn;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user