Skip to content

Commit 4f58220

Browse files
committed
http.c: cookie file tightening
The http.cookiefile configuration variable is used to call curl_easy_setopt() to set CURLOPT_COOKIEFILE and if http.savecookies is set, the same value is used for CURLOPT_COOKIEJAR. The former is used only to read cookies at startup, the latter is used to write cookies at the end. The manual pages https://curl.se/libcurl/c/CURLOPT_COOKIEFILE.html and https://curl.se/libcurl/c/CURLOPT_COOKIEJAR.html talk about two interesting special values. * "" (an empty string) given to CURLOPT_COOKIEFILE means not to read cookies from any file upon startup. * It is not specified what "" (an empty string) given to CURLOPT_COOKIEJAR does; presumably open a file whose name is an empty string and write cookies to it? In any case, that is not what we want to see happen, ever. * "-" (a dash) given to CURLOPT_COOKIEFILE makes cURL read cookies from the standard input, and given to CURLOPT_COOKIEJAR makes cURL write cookies to the standard output. Neither of which we want ever to happen. So, let's make sure we avoid these nonsense cases. Specifically, when http.cookies is set to "-", ignore it with a warning, and when it is set to "" and http.savecookies is set, ignore http.savecookies with a warning. Signed-off-by: Junio C Hamano <[email protected]>
1 parent dbecc61 commit 4f58220

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

http.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,16 @@ struct active_request_slot *get_active_slot(void)
13161316
slot->finished = NULL;
13171317
slot->callback_data = NULL;
13181318
slot->callback_func = NULL;
1319+
1320+
if (curl_cookie_file && !strcmp(curl_cookie_file, "-")) {
1321+
warning(_("refusing to read cookies from http.cookiefile '-'"));
1322+
FREE_AND_NULL(curl_cookie_file);
1323+
}
13191324
curl_easy_setopt(slot->curl, CURLOPT_COOKIEFILE, curl_cookie_file);
1325+
if (curl_save_cookies && (!curl_cookie_file || !curl_cookie_file[0])) {
1326+
curl_save_cookies = 0;
1327+
warning(_("ignoring http.savecookies for empty http.cookiefile"));
1328+
}
13201329
if (curl_save_cookies)
13211330
curl_easy_setopt(slot->curl, CURLOPT_COOKIEJAR, curl_cookie_file);
13221331
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, pragma_header);

0 commit comments

Comments
 (0)