Skip to content

curl_easy_setopt(handle, CURLOPT_COOKIEFILE, NULL) doesn't disable cookies #6889

Closed

Description

@StefanKarpinski

If one enables the cookie engine by doing curl_easy_setopt(handle, CURLOPT_COOKIEFILE,"") or some such, one would expect that subsequently doing curl_easy_setopt(handle, CURLOPT_COOKIEFILE, NULL) would disable it again — indeed, this is how most curl options work. Not sure if this is a bug report or a feature request.

Activity

  1. bagder commented on Apr 13, 2021

    @bagder
    Member

    I don't think it can be seen as anything else than an oversight that we cannot switch off the cookie engine for an easy handle once it has been turned on.

    But if we are to introduce such a way - and I think we should - maybe it would make more sense to follow the previous pattern of "cookie commands" that we support with CURLOPT_COOKIELIST and add a switch off command there? Maybe just call it OFF ?

  2. jay commented on Apr 13, 2021

    @jay
    Member

    maybe it would make more sense to follow the previous pattern of "cookie commands" that we support

    the fix would probably be simple, however CURLOPT_COOKIEJAR I don't see a good way to do the same because data->cookies may be used by a share handle i think

    diff --git a/lib/setopt.c b/lib/setopt.c
    index 022dd38..4612c03 100644
    --- a/lib/setopt.c
    +++ b/lib/setopt.c
    @@ -752,6 +752,10 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
           }
           data->state.cookielist = cl; /* store the list for later use */
         }
    +    else {
    +      curl_slist_free_all(data->state.cookielist);
    +      data->state.cookielist = NULL;
    +    }
         break;
     
       case CURLOPT_COOKIEJAR:
  3. bagder commented on Apr 13, 2021

    @bagder
    Member

    the fix would probably be simple

    This just clears the list of files to read cookies from. It would also need to clear all the cookies from memory and switch off further cookie handling.

  4. jay commented on Apr 13, 2021

    @jay
    Member

    IIRC the cookie engine isn't turned on by CURLOPT_COOKIEFILE until the transfer is started

  5. bagder commented on Apr 13, 2021

    @bagder
    Member

    Right, but what if the handle was already used for one or more transfers with cookies and then you switch it off...

  6. jay commented on Apr 13, 2021

    @jay
    Member

    I see what you're saying. I don't think the cookie engine should explicitly be shut off by CURLOPT_COOKIEFILE, NULL, but it probably should clear the filenames. The doc doesn't say NULL shuts it off.

  7. StefanKarpinski commented on Apr 14, 2021

    @StefanKarpinski
    Author

    For what it's worth, I would expect setting it to NULL to turn it off and here's my reasoning: the default is documented as NULL and if all I do is set CURLOPT_COOKIEFILE to some path and then set it back to NULL without doing anything else, I would expect the easy handle to behave the way it would if I had left things in the default configuration.

  8. bagder commented on Apr 14, 2021

    @bagder
    Member

    I think there's a lot of sense in that reasoning...

  9. added a commit that references this issue on Apr 14, 2021
    f9f9c4a
  10. bagder commented on Apr 14, 2021

    @bagder
    Member

    Proposed approach in #6891

  11. self-assigned this
    on Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions