Skip to content

fix(fetchers): bound HN timestamp formatting#109

Merged
chaliy merged 2 commits into
mainfrom
2026-05-17-fix-unbounded-timestamp-issue-in-hnitem
May 17, 2026
Merged

fix(fetchers): bound HN timestamp formatting#109
chaliy merged 2 commits into
mainfrom
2026-05-17-fix-unbounded-timestamp-issue-in-hnitem

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented May 17, 2026

Motivation

  • The Hacker News fetcher deserializes time: Option<u64> and passed unchecked values into a year-subtraction formatter, which enables a CPU-bound denial-of-service for crafted large timestamps.
  • The change aims to prevent unbounded work by rejecting out-of-range timestamps before running the custom formatter.

Description

  • Added MAX_UNIX_TIMESTAMP (3000-01-01T00:00:00Z) as an upper bound for accepted Unix timestamps.
  • Introduced format_unix_timestamp_bounded(ts) -> Option<String> which returns None for timestamps above the bound and otherwise delegates to the existing format_unix_timestamp.
  • Updated format_hn_response() to render Time metadata only when the bounded formatter returns Some(String).
  • Added test_format_unix_timestamp_bounded unit test to verify valid timestamps are formatted and extreme values (e.g., u64::MAX) are rejected.

Testing

  • Ran formatting: cargo fmt --all which completed successfully.
  • Ran targeted unit tests: cargo test -p fetchkit hackernews -- --nocapture, and the Hacker News tests passed (all relevant tests, including the new bounded-timestamp test, succeeded).

Codex Task

@chaliy chaliy merged commit cf05874 into main May 17, 2026
11 checks passed
@chaliy chaliy deleted the 2026-05-17-fix-unbounded-timestamp-issue-in-hnitem branch May 17, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant