Discussion:
Obtain cookies from IBindCtx
(too old to reply)
Alexander Dyagilev
2009-11-01 22:35:26 UTC
Permalink
Hello!

How? I have pointers to IMoniker and IBindCtx interfaces.
Igor Tandetnik
2009-11-02 04:02:32 UTC
Permalink
How [to obtain cookies from IBindCtx]? I have pointers to IMoniker and IBindCtx interfaces.
Would InternetGetCookie[Ex] work for you?

Alternatively, you can query IBinding (which you get in your implementation of IBindStatusCallback) for IWinInetHttpInfo and call QueryInfo(HTTP_QUERY_SET_COOKIE). That should give you raw Set-Cookie: headers that came with the response.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
Alexander Dyagilev
2009-11-02 12:25:21 UTC
Permalink
Hello, Igor!

InternetGetCookie does not help.
And I can't use IBindStatusCallback because this will allow to get
cookies only after the connection to a server. But it's required for
me to not connect to server twice. A small experiment shown me that
cookies are stored in IBindCtx, not in IMoniker.
Alexander Dyagilev
2009-11-02 12:49:29 UTC
Permalink
OK, it seems the request is made already, but.... I implement my own
IDownloadManager. The problem is that some servers does not allow
connect twice. I use cURL in a separate process for downloading, not
standard Windows API. So I just can't download from such servers and
would like to ignore them. My users can click "Cancel" and skip the
download by my program so IE will download itself. When I use
IBindStatusCallback to get the cookies IE fails to download then I
return a error from my IDownloadManager::Download. Its download window
disappears in a second and IE does nothing to download the file.
Igor Tandetnik
2009-11-02 14:06:26 UTC
Permalink
Post by Alexander Dyagilev
InternetGetCookie does not help.
Have you tried? What makes you believe so?
Post by Alexander Dyagilev
And I can't use IBindStatusCallback because this will allow to get
cookies only after the connection to a server.
Where exactly do you expect cookies to come from, if not from the server? Or are you talking about cookies sent to the server as part of the request?
Post by Alexander Dyagilev
But it's required for
me to not connect to server twice. A small experiment shown me that
cookies are stored in IBindCtx, not in IMoniker.
Neither. Cookies are handled transparently by WinInet, which maintains a machine-wide (for persistent cookies) and a process-wide (for session cookies) cookie stores, and automatically saves the cookies from responses and attaches them to requests. InternetGetCookie[Ex] reads from these stores.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
Alexander Dyagilev
2009-11-02 16:39:03 UTC
Permalink
Post by Igor Tandetnik
Post by Alexander Dyagilev
InternetGetCookie does not help.
Have you tried?
Unfortunately, yes.
Post by Igor Tandetnik
What makes you believe so?
It does not return all the cookies for the specified URL. Really
Internet Explorer sends more cookies as InternetGetCookie returns.
InternetGetCookie seems to not return the cookies valid for the
current session only. E.g. downloading an attachment from a web mail.
With the cookies I get from InternetGetCookie I can download an
login.php page only instead of the real file.
Post by Igor Tandetnik
Post by Alexander Dyagilev
And I can't use IBindStatusCallback because this will allow to get
cookies only after the connection to a server.
Or are you talking about cookies sent to the server as part of the request?
Yes, I am talking about the request cookies.
Post by Igor Tandetnik
Neither. Cookies are handled transparently by WinInet, which maintains a machine-wide (for persistent cookies) and a process-wide (for session cookies) cookie
stores, and automatically saves the cookies from responses and attaches them to requests. InternetGetCookie[Ex] reads from these stores.
Unfortunately this does not help. It seems the cookies are not known
for WinInet at the moment I trying to get them.
Igor Tandetnik
2009-11-02 17:34:27 UTC
Permalink
Post by Alexander Dyagilev
Post by Alexander Dyagilev
InternetGetCookie does not help.
It does not return all the cookies for the specified URL. Really
Internet Explorer sends more cookies as InternetGetCookie returns.
InternetGetCookie seems to not return the cookies valid for the
current session only.
Are you calling it from a different process, by any chance? Session cookies are maintained per-process. GetInternetCookie does retrieve session cookies, in my experience (in fact, I've just checked it again - it does work), but you have to call it from the same process where the session is.
Post by Alexander Dyagilev
Unfortunately this does not help. It seems the cookies are not known
for WinInet at the moment I trying to get them.
Request cookies came from some earlier response. They must be in WinInet's cookie jar - there's no other place to keep them.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
Alexander Dyagilev
2009-11-02 18:53:54 UTC
Permalink
Post by Igor Tandetnik
Are you calling it from a different process, by any chance? Session cookies are maintained per-process. GetInternetCookie does retrieve session cookies, in my experience (in fact, I've just checked it again - it does work), but you have to call it from the same process where the session is.
I call it from the Internet Explorer process, in
IDownloadManager::Download. But it does not retrieve all cookies. E.g.
GMail account. It gets all cookies except GX=SOME_LONG_TEXT_VALUE(i
think it's for authorization purposes). Where can I get this GX cookie
from? Without it my program downloads servicelogin page only. I tried
to get cookies for the domain and for the referrer's URL - did not
help.
Post by Igor Tandetnik
Request cookies came from some earlier response.
Yes, I think so too. But how can I get them? The other my version is
that cookies may be set for URL by the script of a page when I click
on download link?
Post by Igor Tandetnik
They must be in WinInet's cookie jar - there's no other place to keep them.
Alexander Dyagilev
2009-11-02 19:35:43 UTC
Permalink
I've just discovered by a sniffer that this GX cookie has 'HttpOnly'
attribute.
Igor Tandetnik
2009-11-02 19:43:00 UTC
Permalink
Post by Alexander Dyagilev
I call it from the Internet Explorer process, in
IDownloadManager::Download. But it does not retrieve all cookies. E.g.
GMail account. It gets all cookies except GX=SOME_LONG_TEXT_VALUE
Ah. It should have occured to me earlier. This cookie is marked httpOnly - see

http://msdn.microsoft.com/en-us/library/aa384321.aspx

I don't know of any way to programmatically access HttpOnly cookies. Well, I suppose in principle you could watch all requests and responses passing through, like a network sniffer does, and maintain your own cookie jar.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
Alexander Dyagilev
2009-11-02 19:55:48 UTC
Permalink
Post by Igor Tandetnik
I don't know of any way to programmatically access HttpOnly cookies.
They can be accessed via IBindStatusCallbak - as I do now. But this is
not suitable for me due to the reasons I've described above.
Alexander Dyagilev
2009-11-02 20:39:36 UTC
Permalink
All the information about a request is stored in IBindCtx. I think so
due the following experiment:

IMoniker *pmk2;
CreateURLMoniker (NULL, L"http://127.0.0.1/fakeurl.tmp", &pmk2);
pmk2->BindToStorage (pbc, NULL, IID_IStream, (void**)&spStream);

The request is still made to the original valid URL. So IMoniker's
info is ignored and I even do not know for what it's provided in
IDownloadManager::Download.

Loading...