Skip to content

Commit 5f5f297

Browse files
committed
fix: use timegm/_mkgmtime instead of std::mktime for permission timestamps
std::mktime interprets the broken-down time as local time, so permission validity periods change depending on the timezone of the host parsing the XML. This breaks deployments where permissions documents are distributed across hosts in different timezones. Replace std::mktime with timegm (POSIX) / _mkgmtime (Windows) so the not_before and not_after timestamps are always interpreted as UTC. Fixes #6403. Test Plan: Parsed a permissions XML with validity="2025-01-01T00:00:00" and verified the epoch time is the same regardless of TZ environment variable. Signed-off-by: Yuchen Fan <functionhx@gmail.com>
1 parent dd66ef2 commit 5f5f297

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/cpp/security/accesscontrol/PermissionsParser.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <iostream>
2121
#include <sstream>
2222
#include <iomanip>
23+
#include <ctime>
2324

2425
#if TIXML2_MAJOR_VERSION >= 6
2526
#define PRINTLINE(node) node->GetLineNum()
@@ -339,7 +340,11 @@ bool PermissionsParser::parse_validity(
339340

340341
if (!stream.fail())
341342
{
342-
validity.not_before = std::mktime(&time);
343+
#ifdef _WIN32
344+
validity.not_before = _mkgmtime(&time);
345+
#else
346+
validity.not_before = timegm(&time);
347+
#endif // ifdef _WIN32
343348
#endif // if _MSC_VER != 1800
344349

345350
tinyxml2::XMLElement* old_node = node;
@@ -360,7 +365,11 @@ bool PermissionsParser::parse_validity(
360365

361366
if (!stream.fail())
362367
{
363-
validity.not_after = std::mktime(&time);
368+
#ifdef _WIN32
369+
validity.not_after = _mkgmtime(&time);
370+
#else
371+
validity.not_after = timegm(&time);
372+
#endif // ifdef _WIN32
364373
#endif // if _MSC_VER != 1800
365374
returned_value = true;
366375
}

0 commit comments

Comments
 (0)