Skip to content

curl: apply --hsts to ipfs:// and ipns:// gateway requests - #23454

Closed
c8dhjp4tyv-bit wants to merge 3 commits into
curl:masterfrom
c8dhjp4tyv-bit:hsts-ipfs-gateway
Closed

c8dhjp4tyv-bit wants to merge 3 commits into
curl:masterfrom
c8dhjp4tyv-bit:hsts-ipfs-gateway

Conversation

@c8dhjp4tyv-bit

Copy link
Copy Markdown
Contributor

When an ipfs:// or ipns:// URL is rewritten to an http:// gateway, --hsts is not applied, so the request goes over plain HTTP even when the gateway host has an HSTS entry. A direct http:// request to the same host is upgraded.

This changed in 8.14.0, when the HSTS setup moved into http_setopts(), which returns early for anything that is not HTTP or HTTPS. The rewritten request keeps the ipfs/ipns protocol, so it never gets the HSTS cache. 8.13.0 upgrades these requests.

The fix sets CURLOPT_HSTS before that check. While testing I also found that the IPFS rewrite adds the default port to the URL even when the gateway URL has none, so the upgraded request went to port 80 instead of 443. It now only keeps a port the gateway URL sets.

The --hsts docs now say it also applies to IPFS gateway requests.

Test 465 covers it, and the existing IPFS, HSTS, source and documentation tests pass.

When an ipfs:// or ipns:// URL is rewritten to an http:// gateway URL,
the transfer keeps the ipfs/ipns protocol token, and http_setopts()
returned before CURLOPT_HSTS was set. The gateway request was then
never upgraded to HTTPS, even when the gateway host had an HSTS entry.
This has been the case since 8.14.0, when the HSTS setup moved into
http_setopts().

Set CURLOPT_HSTS before the protocol check. Also stop adding the
default port to the rewritten URL when the gateway URL has none, as
the explicit :80 made the upgraded request go to port 80 instead of
443.

Document that --hsts applies to IPFS gateway requests.

Add test 465 to verify.
@c8dhjp4tyv-bit

Copy link
Copy Markdown
Contributor Author

The CI failures look unrelated to this change:

  • pyspelling: flags "CDNs" in docs/INSTALL.md, which this PR doesn't touch. The same check fails on master since "docs: encourage verifying tarball before unpacking".
  • AM awslc: test_32_04_download_10_parallel (FTPS) fails on time_queue being 0.0; the transfers themselves succeed.
  • AM mbedtls clang: test_02_34_max_total_conns[h2] exits with 55.
  • AM openssl: test_60_12_quic_session_resumption (HTTP/3 proxy).
  • freebsd 15.1 riscv64: test 776 (NTLM) keeps resending the request. It's known to be flaky on slow runs (test776: NTLM test flaky in valgrind tests #19235), and this job is emulated.

This PR only touches the ipfs:// and ipns:// URL rewrite and the --hsts setup in the tool, and none of these tests use IPFS or HSTS. I can rebase once master is fixed if that helps.

@c8dhjp4tyv-bit
c8dhjp4tyv-bit marked this pull request as ready for review October 17, 2026 19:06
@testclutch

Copy link
Copy Markdown

Analysis of PR #23454 at ae205e3c:

Test ../../tests/http/test_60_h3_proxy.py::TestH3Proxy::test_60_12_quic_session_resumption failed, but it has been permanently failing lately, so it's probably NOT a fault of the PR. Note that this test has failed in 2 different CI jobs (the link just goes to one of them). Note that this CI job has had a number of other flaky tests recently (4, to be specific) so it may be that this failure is rather a systemic issue with this job and not with this specific PR.

Test ../../tests/http/test_32_ftps_vsftpd.py::TestFtpsVsFTPD::test_32_04_download_10_parallel[data-1m] failed, but it has been 0.3% flaky lately, so it's probably NOT a fault of the PR. Note that this test has failed in 2 different CI jobs (the link just goes to one of them). Note that this CI job has had a number of other flaky tests recently (4, to be specific) so it may be that this failure is rather a systemic issue with this job and not with this specific PR.

Test ../../tests/http/test_02_download.py::TestDownload::test_02_34_max_total_conns[False-0-h2] failed, but it has been 0.6% flaky lately, so it's probably NOT a fault of the PR. Note that this test has failed in 2 different CI jobs (the link just goes to one of them). Note that this CI job has had a number of other flaky tests recently (2, to be specific) so it may be that this failure is rather a systemic issue with this job and not with this specific PR.

Generated by Testclutch

Comment thread src/tool_ipfs.c Resolved
Co-authored-by: Daniel Stenberg <daniel@haxx.se>
Comment thread tests/data/test465 Resolved
@bagder bagder closed this in aae3b55 Oct 19, 2026
@bagder

bagder commented Oct 19, 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.

4 participants