CURLOPT_HSTS(3)
okay bestie, this is CURLOPT_HSTS(3) from the Library Functions Manual β weβre talking HSTS cache filename energy, and ngl itβs giving very specific filename main character energy π
β¨
πΈ NAME πΈ
CURLOPT_HSTS - HSTS cache filename π
π¦ SYNOPSIS π¦
#include <curl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HSTS, char *filename);
π DESCRIPTION π
Okay so the filename? Make the filename point to a filename where libcurl loads an existing HSTS cache from, and where it stores the cache when the easy handle is closed π«Ά
Setting a file name with this option also enables HSTS for this handle β thatβs the equivalent of setting CURLHSTS_ENABLE with CURLOPT_HSTS_CTRL(3) π
If the given file does not exist or contains no HSTS entries at startup, the HSTS cache simply starts empty. No drama, it just vibes empty β lowkey iconic π
Setting the filename to NULL allows HSTS without reading from or writing to any file. NULL also makes libcurl clear the list of files to read HSTS data from, if any such were previously set π§Ή
If this option is set multiple times, libcurl loads cache entries from each given file but only stores the last used name for later writing. So it loads from every file, but only stores the last used name for later writing β periodt π
π FILE FORMAT π
The HSTS cache is saved to and loaded from a text file with one entry per physical line. Each line in the file has the following format:
[host] [stamp]
[host] is the domain name for the entry and the name is dot-prefixed if it is an entry valid for all subdomains to the name as well or only for the exact name. not me needing to read that dot-prefixed rule twice π but yes, thatβs the exact rule, fr fr.
[stamp] is the time (in UTC) when the entry expires and it uses the format YYYYMMDD HH:MM:SS β°
Lines starting with # are treated as comments and are ignored. There is currently no length or size limit. Slay, no cap π
π DEFAULT π
NULL, no filename. Simple. Iconic. Obsessed.
π₯ SECURITY CONCERNS π₯
bestie, this part is highkey serious: libcurl cannot fully protect against attacks where an attacker has write access to the same directory where it is directed to save files. This is particularly sensitive if you save files using elevated privileges. π¨
libcurl creates the file to store HSTS data in using default file permissions, meaning that on *nix systems you may need to restrict your umask to prevent other users on the same system from accessing the file. Lock it down, iykyk π
π PROTOCOLS π
This functionality affects http only. Thatβs the whole protocol vibe check π«
π EXAMPLE π
int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_HSTS, "/home/user/.hsts-cache");
curl_easy_perform(curl);
}
}
β AVAILABILITY β
Added in curl 7.74.0 ποΈ
π RETURN VALUE π
curl_easy_setopt(3) returns a CURLcode indicating success or error.
CURLE_OK (0) means everything was OK, non-zero means an error occurred, see libcurl-errors(3) π«‘
π¦ SEE ALSO π¦
mwah π this lil page comes from libcurl, dated 2026-10-12, and itβs CURLOPT_HSTS(3) β bye bestie, go keep that cache cute! πβ¨
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms