Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(devices): refuse a seconds-valued pairingExpiresAt instead of decoding it to 1970

M3gA-Mind3308d7cb2531
diff --git a/src/openhuman/security/devices/tunnel_client.rs b/src/openhuman/security/devices/tunnel_client.rs
index 76b00fcc46..8e0705cdd4 100644
--- a/src/openhuman/security/devices/tunnel_client.rs
+++ b/src/openhuman/security/devices/tunnel_client.rs
@@ -47,6 +47,12 @@ pub struct TunnelRegisterResponse {
pub pairing_expires_at: String,
}
+/// Floor for a plausible epoch-milliseconds `pairingExpiresAt`: 2020-01-01Z.
+///
+/// Anything below it is far likelier to be seconds than a real expiry, and
+/// seconds decode silently into 1970 rather than failing.
+const MIN_PLAUSIBLE_EPOCH_MILLIS: i64 = 1_577_836_800_000;
+
/// Accept `pairingExpiresAt` as either an ISO 8601 string or epoch
/// milliseconds, always yielding the ISO 8601 string the rest of the domain
/// expects.
@@ -73,9 +79,26 @@ where
match Raw::deserialize(deserializer)? {
Raw::Text(text) => Ok(text),
- Raw::EpochMillis(millis) => chrono::DateTime::from_timestamp_millis(millis)
- .map(|dt| dt.to_rfc3339())
- .ok_or_else(|| D::Error::custom(format!("pairingExpiresAt out of range: {millis}"))),
+ Raw::EpochMillis(millis) => {
+ // Reject a value that is not plausibly milliseconds. `getTime()`
+ // returns millis, but a backend that ever switched to seconds would
+ // hand over ~1.79e9, and `from_timestamp_millis` accepts that
+ // happily as 1970-01-21 — a pairing that is already expired before
+ // the QR is drawn, reported to the user as "expired" with nothing
+ // in the log to say why. Failing loudly here keeps the silent
+ // version of this PR's own bug from being reintroduced by a unit
+ // change upstream.
+ if millis < MIN_PLAUSIBLE_EPOCH_MILLIS {
+ return Err(D::Error::custom(format!(
+ "pairingExpiresAt={millis} is too small to be epoch milliseconds \
+ (expected > {MIN_PLAUSIBLE_EPOCH_MILLIS}); a seconds-valued expiry \
+ would silently decode as 1970"
+ )));
+ }
+ chrono::DateTime::from_timestamp_millis(millis)
+ .map(|dt| dt.to_rfc3339_opts(chrono::SecondsFormat::Secs, true))
+ .ok_or_else(|| D::Error::custom(format!("pairingExpiresAt out of range: {millis}")))
+ }
}
}
diff --git a/src/openhuman/security/devices/tunnel_client_tests.rs b/src/openhuman/security/devices/tunnel_client_tests.rs
index bc53b11d7d..c3deecd5be 100644
--- a/src/openhuman/security/devices/tunnel_client_tests.rs
+++ b/src/openhuman/security/devices/tunnel_client_tests.rs
@@ -65,12 +65,39 @@ fn tunnel_register_response_accepts_numeric_pairing_expires_at() {
assert_eq!(response.channel_id, "ch_789");
assert_eq!(
- response.pairing_expires_at, "2026-09-21T14:13:20+00:00",
+ response.pairing_expires_at, "2026-09-21T14:13:20Z",
"epoch milliseconds must be rendered as the ISO 8601 string the rest \
of the domain documents and forwards to the paired device"
);
}
+/// A seconds-valued expiry must fail loudly rather than decode to 1970.
+///
+/// `from_timestamp_millis` accepts ~1.79e9 without complaint and yields
+/// 1970-01-21, so a backend that switched `getTime()` for a seconds-based
+/// clock would produce a pairing already expired before the QR is drawn — the
+/// user sees "expired" and the log says nothing. Raised by the review harness
+/// against the first version of this fix.
+#[test]
+fn a_seconds_valued_pairing_expiry_is_refused_instead_of_decoding_to_1970() {
+ let err = serde_json::from_value::<TunnelRegisterResponse>(json!({
+ "channelId": "ch_s",
+ "pairingToken": "pt_s",
+ "pairingExpiresAt": 1_790_000_000i64
+ }))
+ .expect_err("a seconds-valued expiry must not be accepted");
+
+ let text = err.to_string();
+ assert!(
+ text.contains("epoch milliseconds"),
+ "the error must name the unit mismatch, got: {text}"
+ );
+ assert!(
+ text.contains("1790000000"),
+ "the error must quote the offending value so the log identifies it, got: {text}"
+ );
+}
+
/// A register the backend refuses is answered with `{ ok: false, error }` and
/// no `channelId`. Parsing that as the success shape is what produced the
/// `missing field 'channelId'` in #5871 — a server-side refusal reported to the