Skip to content

Issue 429 Trust Duration Ignored

Ed Mozley edited this page Nov 23, 2026 · 1 revision

πŸ” #429 Changing the trust duration did nothing for devices already trusted

GitHub #429, reported by @acelr22 Β· Sign-in, System β†’ Security Β· fixed after 5.10.1 (#3147)

What you saw

System β†’ Security β†’ Trusted Device β†’ Trust duration says how many days a browser may skip the one-time code after someone has passed it once. Changing it made no difference to anyone who had already trusted a browser. Setting it to 0 - which the screen describes as turning the feature off entirely - still let every trusted browser sign in without a code, and shortening it from 30 days to 5 left existing browsers trusted for the full 30.

What was wrong

The setting was read in one place only: the moment a browser became trusted. api/myaccount/verify_login_otp.php worked out an expiry date from it and stored that date with the device:

// api/myaccount/verify_login_otp.php - when the code is accepted
$trustDays = (int)($tdRow['setting_value'] ?? 0);
...
INSERT INTO trusted_devices (..., created_datetime, expires_datetime)
VALUES (..., UTC_TIMESTAMP(), DATE_ADD(UTC_TIMESTAMP(), INTERVAL ? DAY))

Sign-in then checked only that stored date:

// auth/login.php (before)
$tdStmt = $conn->prepare("SELECT id FROM trusted_devices
    WHERE device_token_hash = ? AND analyst_id = ? AND expires_datetime > UTC_TIMESTAMP()");

Nothing at sign-in looked at the setting again. Once a row was written, its expiry was fixed, whatever the administrator later chose.

The check that looked like enough

expires_datetime > UTC_TIMESTAMP() reads like a complete trust check - and while the setting never changes, it is one. It only goes wrong when an administrator tightens the policy, which is exactly when they most need it to work: after a laptop goes missing, or when a security review says "no skipping the code". A check that is only correct while nobody changes the setting is not checking the setting.

It was one place, not several

Every reader of trusted_devices and of the trusted_device cookie was searched for. There is one: the staff sign-in in auth/login.php. The self-service portal has one-time codes but no trusted devices, so it was not affected. api/myaccount/toggle_trust_device.php only deletes rows (when someone turns Trust this device off), which was already right.

The fix

Sign-in now reads today's duration and requires the device to pass both its own expiry and the current duration, counted from when it was trusted:

// auth/login.php (after)
$trustDays = (int)($tdDaysStmt->fetchColumn() ?: 0);
if ($trustDays > 0) {
    $tdStmt = $conn->prepare("SELECT id FROM trusted_devices
                              WHERE device_token_hash = ? AND analyst_id = ?
                                AND expires_datetime > UTC_TIMESTAMP()
                                AND created_datetime > DATE_SUB(UTC_TIMESTAMP(), INTERVAL ? DAY)");

So:

  • 0 turns the skip off for everyone at their next sign-in.
  • Shortening the duration shortens every existing device's trust.
  • Lengthening it does not extend a device past the expiry it was given - lengthening is only ever a policy loosening, and the person simply enters a code once more to get the new, longer trust.

Two smaller things in the same code:

  • The cookie is now marked Secure when the site is on HTTPS, so the browser never sends it over plain HTTP. It was hard-coded to false.
  • A cookie that is not valid hex is ignored rather than passed to hex2bin(), which would have raised a PHP warning.

πŸ“ Files

File Change
πŸ”΅ auth/login.php trust duration checked at every sign-in; malformed cookie ignored
πŸ”΅ api/myaccount/verify_login_otp.php cookie Secure on HTTPS, SameSite=Lax
🟒 tests/trusted-device-duration.php new regression test

How it was verified

tests/trusted-device-duration.php signs in over HTTP as a temporary analyst with a browser trusted 10 days ago that expires in 20 days, then changes the duration:

Duration Expected Old code New code
30 days code skipped βœ… βœ…
5 days code asked for ❌ skipped βœ…
0 (off) code asked for ❌ skipped βœ…
malformed cookie code asked for, no error βœ… βœ…
back to 30 days code skipped βœ… βœ…

The last row is the control: it proves the new check still lets a genuinely trusted browser through, so the passes above are not just "everything now asks for a code". The test removes its analyst, device rows and setting afterwards.

Not proven: the Secure flag was not exercised over a real HTTPS connection - the test install runs on plain HTTP. It uses the same requestIsHttps() the session cookie uses.

What this means for you

After upgrading:

  • Every trusted browser is held to the trust duration as it is set now. If you lowered it at some point, browsers trusted before then may ask for a code at their next sign-in - expected, once.

Before upgrading, anyone can clear their own trusted browsers by turning Trust this device off in their avatar menu.

The trust duration only decides whether someone can skip the code at sign-in. It does not sign anybody out - how long a signed-in session lasts is separate.

Related

FreeITSM

Getting Started

Modules

Multi-tenancy (planned)

Responses to feedback

Blue sky thinking

Bugs resolved

Pull requests

Links

Clone this wiki locally