Skip to content

fix: floor the seal policy timestamp so it is never in the future#116

Merged
rubenhensen merged 1 commit into
mainfrom
fix/seal-timestamp-floor
Jul 17, 2026
Merged

fix: floor the seal policy timestamp so it is never in the future#116
rubenhensen merged 1 commit into
mainfrom
fix/seal-timestamp-floor

Conversation

@rubenhensen

Copy link
Copy Markdown
Contributor

The PKG rejects a USK request whose timestamp is > now ("chronology error"). The seal policy timestamp was stamped with Math.round(Date.now() / 1000), which can land up to ~1 second in the future — so an encrypt→decrypt within the same second can fail.

In normal usage the multi-second encrypt→decrypt gap masks this, which is why it's gone unnoticed. The e2e harness (encryption4all/postguard-e2e#15) runs the full flow headless in <1s and surfaced it: decrypt failed with [http 400] {"error":true,"message":"chronology error"}.

Fix: extract nowSeconds() (uses Math.floor, always ≤ now) and use it for both seal timestamps (encryptPipeline + sealRaw). Adds unit tests pinning the floor behavior (a sub-second past 0.5 must not round up to the next second).

No wire-format or API change — the timestamp is already wall-clock-derived; this only removes the ≤1s forward skew.

The PKG rejects a USK request whose timestamp is > now ("chronology error").
The seal timestamp was stamped with Math.round(Date.now()/1000), which can
land up to ~1s ahead of the real time, so an encrypt→decrypt within the same
second could fail. In normal usage the multi-second gap masks it; the e2e
harness's headless flow (encryptionall/postguard-e2e) completes in <1s and
surfaced it.

Extract nowSeconds() (floor) and use it for both seal timestamps. Adds unit
tests pinning the floor behavior.
@dobby-coder

dobby-coder Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Thanks for the detailed write-up, @rubenhensen! I'm on it — kicking off a review of this PR now (correctness + rule-compliance), and I'll follow up with a consolidated review (approve / request changes / comment).

@dobby-coder dobby-coder Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — approving.

Correctly diagnosed and cleanly scoped: nowSeconds() uses Math.floor, so the seal policy timestamp is always ≤ wall-clock now and can no longer trip the PKG's > now "chronology error" on a same-second encrypt→decrypt. Both stamping sites (encryptPipeline and sealRaw) now go through it, and the regression tests pin the floor behaviour (1000.700s → 1000, where Math.round would have given 1001).

No wire-format or API change, no rule findings.

@dobby-coder

dobby-coder Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Approved! The fix is clean and correctly scoped — routing both encryptPipeline and sealRaw through a Math.floor-based nowSeconds() closes the same-second encrypt→decrypt gap that was tripping the PKG's chronology check, and the regression tests pin the floor behavior nicely (1000.700s → 1000). No wire-format or API changes. Nice catch from the e2e harness surfacing this.

@rubenhensen
rubenhensen merged commit c7d21aa into main Jul 17, 2026
5 checks passed
@rubenhensen
rubenhensen deleted the fix/seal-timestamp-floor branch July 17, 2026 05:56
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 2.3.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant