Skip to content

hsts: duplicate live hsts data in curl_easy_duphandle().#21809

Closed
whatchamacallem wants to merge 1 commit into
curl:masterfrom
whatchamacallem:hsts_bypass_easy_duphandle
Closed

hsts: duplicate live hsts data in curl_easy_duphandle().#21809
whatchamacallem wants to merge 1 commit into
curl:masterfrom
whatchamacallem:hsts_bypass_easy_duphandle

Conversation

@whatchamacallem

Copy link
Copy Markdown
Contributor

curl_easy_duphandle() now copies live HSTS entries (aquired from Strict-Transport-Security response headers) into the cloned handle. Previously only file-based entries were duplicated. Adds Curl_hsts_copy() to handle the transfer. Expired entries are skipped.

@whatchamacallem whatchamacallem force-pushed the hsts_bypass_easy_duphandle branch 4 times, most recently from 08b3020 to 2836c07 Compare May 29, 2026 22:09
Comment thread lib/easy.c Outdated
@whatchamacallem

Copy link
Copy Markdown
Contributor Author

This looks ready to merge. I'll let you handle it from here. (I ended up rebasing the commit to merge your fix to a flakey test and a couple times more to pass the linter.)

@bagder

bagder commented May 31, 2026

Copy link
Copy Markdown
Member

How about adding a libtest that verifies this?

@whatchamacallem whatchamacallem force-pushed the hsts_bypass_easy_duphandle branch from 6f36190 to e489d59 Compare May 31, 2026 19:31
@github-actions github-actions Bot added the tests label May 31, 2026
@whatchamacallem whatchamacallem force-pushed the hsts_bypass_easy_duphandle branch 2 times, most recently from 98c293c to e4448a6 Compare May 31, 2026 19:37
Comment thread tests/libtest/lib1922.c Outdated
Comment on lines +30 to +31
static CURLSTScode hstsread1922(CURL *curl, struct curl_hstsentry *e,
void *userp)

@vszakats vszakats May 31, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
static CURLSTScode hstsread1922(CURL *curl, struct curl_hstsentry *e,
void *userp)
static CURLSTScode t1922_hstsread(CURL *curl, struct curl_hstsentry *e,
void *userp)

minor indent nit, and also the naming scheme as in most other tests.

Comment thread tests/libtest/lib1922.c Outdated
};

static const struct entry preload_hosts[] = {
#if (SIZEOF_TIME_T < 5)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
#if (SIZEOF_TIME_T < 5)
#if SIZEOF_TIME_T < 5

drop parents, to make it like most of the code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was in the middle to dorking with this PR when you made suggestions. I have applied all your suggestions to the latest commit.

Comment thread tests/libtest/lib1922.c Outdated
***************************************************************************/
#include "first.h"

struct state1922 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
struct state1922 {
struct t1922_state {

sync with naming scheme used in most tests.

Comment thread tests/libtest/lib1922.c Outdated
Comment on lines +69 to +70
static CURLSTScode hstswrite1922(CURL *curl, struct curl_hstsentry *e,
struct curl_index *i, void *userp)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
static CURLSTScode hstswrite1922(CURL *curl, struct curl_hstsentry *e,
struct curl_index *i, void *userp)
static CURLSTScode t1922_hstswrite(CURL *curl, struct curl_hstsentry *e,
struct curl_index *i, void *userp)

fix indent, and use common naming scheme.

Comment thread tests/libtest/lib1922.c Outdated
/*
* Verify that curl_easy_duphandle() copies live HSTS entries to the clone.
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change

drop empty line.

Comment thread tests/data/test1922
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="US-ASCII"?>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This file needs to be added to the local Makefile.inc to add it to dist and pass CI.

@whatchamacallem whatchamacallem force-pushed the hsts_bypass_easy_duphandle branch 4 times, most recently from d6bb7b1 to d5839d0 Compare May 31, 2026 20:33
@whatchamacallem

Copy link
Copy Markdown
Contributor Author

@vszakats @bagder

I don't know what to do about this one CI issue.

https://github.com/curl/curl/actions/runs/26723735880/job/78755299214?pr=21809

Pseudo-terminal will not be allocated because stdin is not a terminal.
/bin/sh: cmake: not found
Error: Process completed with exit code 127.

@whatchamacallem

Copy link
Copy Markdown
Contributor Author

This looks ready to merge. Let me know if you want it rebased onto master again. The midnightbsd failure was also failing on master. The other two failures look like overloaded CI servers timing out and running out of resources.

Comment thread tests/data/Makefile.am Outdated
Comment thread lib/hsts.c Outdated
@bagder

bagder commented Jun 1, 2026

Copy link
Copy Markdown
Member

Shouldn't the test also use the duplicated handle to "prove" that the HSTS data is actually copied over? Otherwise the test doesn't really verify that.

@whatchamacallem whatchamacallem force-pushed the hsts_bypass_easy_duphandle branch from f71ed1b to d830fcc Compare June 1, 2026 21:14
@whatchamacallem whatchamacallem force-pushed the hsts_bypass_easy_duphandle branch from d830fcc to 8d61a0e Compare June 1, 2026 21:52
@whatchamacallem

Copy link
Copy Markdown
Contributor Author

@bagder @vszakats All tests pass. I didn't rebase because master had a failing test.

(I swear just using file globs is easier than maintaining lists of files. We have git for tracking the contents of directories. Fixing the whitespace in a list of files feels like masochism after you have experienced freedom.)

@whatchamacallem

Copy link
Copy Markdown
Contributor Author

@bagder @vszakats Let me know if there is anything else for this HSTS patch to land. The next step would be to emulate TLS somehow, I'm hoping this is good enough.

@bagder bagder closed this in 084ceb6 Jun 9, 2026
@bagder

bagder commented Jun 9, 2026

Copy link
Copy Markdown
Member

Thanks!

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

Development

Successfully merging this pull request may close these issues.

3 participants