Repository navigation
Description
Found in the post-merge review of #4420 (TALE-947, agent #6, run 2d1106e9), at merge 464e1d9b / head 1948429b. The cited files are unchanged on main 8b750caf30.
Summary
When an admin shortens the two-factor grace period, nobody who already has a grace anchor is blocked any earlier. The deadline the account is shown moves forward on every evaluation, so the account is still blocked only when its original anchor passes.
The domain spec states the opposite. #4420 added a test that asserts the spec's claim, but at one frozen instant, so it passes.
Where
- Code:
services/platform/backend/domains/two_factor/service.ts:267-283cap = now + gracePeriodDays * 24 * 60 * 60 * 1000(:268) is recomputed from the current time on every evaluation.deadline = Math.min(anchor, cap)(:276) and the block testdeadline <= now(:277) follow.- With
gracePeriodDays > 0,capis always later thannow, so the account is blocked only once the stored anchor itself has passed. - The anchor is written once and only when absent, by
setGraceUntilIfAbsentwithON CONFLICT (user_id) DO NOTHING(:294-304,:302). Nothing shortens it. - GitHub code search for
two_factor_gracefinds only DELETE statements elsewhere:members/service.ts:733anderasure/service.ts:1401. - The comment at
:274-275says "a shortened grace takes effect immediately".
- Spec:
services/platform/backend/domains/two_factor/spec.md:37-44(TFA-R4)- The rule says: "A policy that is made shorter applies at once."
- The example says: "Mia first signs in on Monday → she has until the next Monday. An admin then cuts the period to 2 days → she has until Wednesday."
- Test:
services/platform/backend/domains/two_factor/service.enforcement.test.ts:154-169, titled "never restarts a running grace period, and applies a shorter one at once [TFA-R4]".- It evaluates once at the frozen
NOW, with anchorNOW+10dand policy 2 days, and assertsgraceDeadline: NOW + 2 days. - It never advances time, so it cannot see that the 2-day deadline is never reached.
- It evaluates once at the frozen
Scenario (the test's own data)
The anchor is NOW+10d (a 10-day policy at first sign-in). The policy is then cut to 2 days.
| When | cap |
Deadline shown | Decision |
|---|---|---|---|
NOW |
NOW+2d |
NOW+2d |
grace |
NOW+3d |
NOW+5d |
NOW+5d |
grace (the deadline slid) |
NOW+9d |
NOW+11d |
NOW+10d |
grace |
NOW+10d |
— | — | blocked, the original anchor |
In the spec's own example, Mia is blocked next Monday, not on Wednesday.
Expected (per TFA-R4)
A shortened policy moves the effective block time earlier. For example, the deadline becomes min(anchor, <start> + newDays) with the start of the grace stored, or the anchors are capped when the policy is saved. Owners decide which "at once" means.
Fix notes
- Under the repo rule since feat(platform): state every backend domain's rules in a spec that tests hold #4420, the fix moves TFA-R4's text and its test title in the same change.
- The regression test should advance fake time past the shortened deadline and expect
blocked. It should be red at464e1d9b.
I ran no tests; this comes from reading the code. A check phase can confirm it with the probe above.
Activity