Skip to content

HSTS: cap the list at 1,000 entries#21190

Closed
bagder wants to merge 2 commits intomasterfrom
bagder/hsts-max
Closed

HSTS: cap the list at 1,000 entries#21190
bagder wants to merge 2 commits intomasterfrom
bagder/hsts-max

Conversation

@bagder
Copy link
Copy Markdown
Member

@bagder bagder commented Apr 1, 2026

Avoid never-ending growth.

When adding more entries, it now deletes the first entry in the list, which is the oldest added entry still held in memory. I decided to avoid a Least Recently Used concept as I suspect with a list with this many entries most entries have not been used, and we don't save the timestamp of recent use anyway.

The net effect might (no matter what) be that the removed entry might feel a bit "random" in the eyes of the user.

Verify with test 1674

Ref #21183

@github-actions github-actions bot added the tests label Apr 1, 2026
@bagder bagder requested a review from Copilot April 1, 2026 09:14
@bagder bagder marked this pull request as ready for review April 1, 2026 09:14
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a hard cap on the in-memory HSTS cache size to prevent unbounded growth, and adds a new unit/integration test to verify the cap behavior when loading from a file.

Changes:

  • Add MAX_HSTS_ENTRIES (1,000) and enforce it by evicting the oldest entry on insert.
  • Add unit test unit1674 and test definition test1674 to validate the cache is capped at 1,000 entries when loading more.
  • Register the new test in the unit and data makefiles.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lib/hsts.h Introduces MAX_HSTS_ENTRIES to define the HSTS cache cap.
lib/hsts.c Adds capped append helper that evicts the oldest entry before appending when at limit.
tests/unit/unit1674.c New unit test that renders an over-limit HSTS file, loads it, and prints resulting entry count.
tests/unit/Makefile.inc Registers unit1674.c in the unit test build list.
tests/data/test1674 Adds a runtests.pl test case that validates stdout reports 1,000 entries.
tests/data/Makefile.am Registers test1674 in the test data list.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

bagder added 2 commits April 1, 2026 12:09
Avoid never-ending growth.

When adding more entries, it now deletes the first entry in the list,
which is the oldest added entry still held in memory. I decided to avoid
a Least Recently Used concept as I suspect with a list with this many
entries most entries have not been used, and we don't save the timestamp
of recent use anyway.

The net effect might (no matter what) be that the removed entry might
feel a bit "random" in the eyes of the user.

Verify with test 1674

Ref #21183
@bagder bagder force-pushed the bagder/hsts-max branch from e161f7e to d4c77b6 Compare April 1, 2026 10:10
@bagder
Copy link
Copy Markdown
Member Author

bagder commented Apr 1, 2026

augment review

@augmentcode
Copy link
Copy Markdown

augmentcode bot commented Apr 1, 2026

🤖 Augment PR Summary

Summary: Prevent unbounded growth of the in-memory HSTS cache by enforcing a hard cap.

Changes:

  • Add MAX_HSTS_ENTRIES (1000) and a helper that evicts the oldest entry before appending when the cache is full
  • Route HSTS entry creation through the new capped-append path
  • Add unit test 1674 that generates an HSTS file with >1000 hosts and verifies the cache is capped at 1000 entries
Technical Notes: Eviction is FIFO by insertion order (not LRU).

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

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

Review completed. 3 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

@bagder bagder closed this in 03a792b Apr 1, 2026
@bagder bagder deleted the bagder/hsts-max branch April 1, 2026 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants