Skip to content

hsts: make the HSTS read callback handle name dupes#21201

Closed
bagder wants to merge 3 commits intomasterfrom
bagder/hsts-callback
Closed

hsts: make the HSTS read callback handle name dupes#21201
bagder wants to merge 3 commits intomasterfrom
bagder/hsts-callback

Conversation

@bagder
Copy link
Copy Markdown
Member

@bagder bagder commented Apr 2, 2026

Now the logic for handling name duplicates and picking the longest expiry and strictest subdomain is the same for the callback as for when reading from file.

Also strip trailing dots from the hostname added by the callback.

A minor side-effect is that the hostname provided by the callback can now enable subdomains by starting the name with a dot, but we discourage using such hostnames in documentation.

Amended test 1915 to verify.

@github-actions github-actions bot added the tests label Apr 2, 2026
@bagder bagder marked this pull request as ready for review April 2, 2026 07:36
@testclutch

This comment was marked as off-topic.

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 aligns HSTS entry de-duplication behavior between HSTS file loading and the CURLOPT_HSTSREADFUNCTION callback path, ensuring consistent selection of the longest expiry and strictest includeSubDomains policy, while normalizing hostnames from the callback.

Changes:

  • Refactors shared “add HSTS host + expiry” logic into a helper used by both file parsing and callback ingestion.
  • Normalizes callback-provided hostnames by stripping trailing dots and interpreting a leading dot as enabling includeSubDomains.
  • Updates test 1915 to validate duplicate handling, subdomain strictness, and trailing-dot stripping.

Reviewed changes

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

File Description
lib/hsts.c Introduces shared add/update helper and uses it for both file parsing and callback loading, including hostname normalization and duplicate merge rules.
tests/libtest/lib1915.c Extends callback-fed preload list to include dupes/trailing-dot/leading-dot cases and prints includeSubDomains in output.
tests/data/test1915 Updates expected stdout to reflect merged entries (strictest subdomain + longest expiry).
docs/libcurl/opts/CURLOPT_HSTSREADFUNCTION.md Clarifies guidance around leading/trailing dots in callback-provided hostnames.

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

Comment thread docs/libcurl/opts/CURLOPT_HSTSREADFUNCTION.md
Comment thread lib/hsts.c
bagder added 2 commits April 2, 2026 13:06
Now the logic for handling name duplicates and picking the longest
expiry and strictest subdomain is the same for the callback as for when
reading from file.

Also strip trailing dots from the hostname added by the callback.

A minor side-effect is that the hostname provided by the callback can
now enable subdomains by starting the name with a dot, but we discourage
using such hostnames in documentation.

Amended test 1915 to verify.

Closes #21201
@bagder bagder force-pushed the bagder/hsts-callback branch from 2c5afdd to 862ae98 Compare April 2, 2026 11:07
@aisle-research-bot
Copy link
Copy Markdown

aisle-research-bot bot commented Apr 2, 2026

🔒 Aisle Security Analysis

✅ We scanned this PR and did not find any security vulnerabilities.

Aisle supplements but does not replace security review.


Analyzed PR: #21201 at commit 862ae98

Last updated on: 2026-04-02T11:37:13Z

@aisle-research-bot
Copy link
Copy Markdown

aisle-research-bot bot commented Apr 2, 2026

🤖 We're reviewing this PR with Aisle

We're running a security check on the changes in this PR now. This usually takes a few minutes. ⌛
We'll post the results here as soon as they're ready.

Progress:

  • Analysis
  • Finalization

Latest run failed. Keeping previous successful results. Trace ID: 019d4dfa7c3a3cee7725e41a0172bb2b.

Last updated on: 2026-04-02T12:33:10Z

@bagder bagder closed this in e65ba1b Apr 2, 2026
@bagder bagder deleted the bagder/hsts-callback branch April 2, 2026 16:01
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.

3 participants