OnBeforeBrowse CefRequest object has wrong URL on redirect

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

OnBeforeBrowse CefRequest object has wrong URL on redirect

Postby kbiskar » Tue Feb 03, 2015 3:00 pm

I found a strange difference between Cef1 and Cef3 in RequestHandler::OnBeforeBrowse. In Cef1, the CefRequest object passed in will return the redirected URL when GetURL is called on it. In Cef3, the CefRequest returns the original URL. Is this deliberate? Is there another way to get the redirected URL in OnBeforeBrowse?
kbiskar
Techie
 
Posts: 25
Joined: Mon May 12, 2014 1:02 pm

Re: OnBeforeBrowse CefRequest object has wrong URL on redire

Postby magreenblatt » Tue Feb 03, 2015 3:06 pm

What OS and CEF3 version? How is the redirect being performed (e.g. via Location HTTP header or META refresh)? Are you sure OnBeforeBrowse is being called in CEF3 for the redirect, and not just for the original browse request? OnResourceRedirect should be called for redirects.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: OnBeforeBrowse CefRequest object has wrong URL on redire

Postby kbiskar » Tue Feb 03, 2015 5:05 pm

This is with Windows 7 x64 and Cef 3.2062.1902. The redirect is being triggered from a Location HTTP header. Also, OnBeforeBrowse is getting called on the redirect (the "isRedirect" flag is set to true the second time it's called).
kbiskar
Techie
 
Posts: 25
Joined: Mon May 12, 2014 1:02 pm

Re: OnBeforeBrowse CefRequest object has wrong URL on redire

Postby magreenblatt » Tue Feb 03, 2015 5:41 pm

I'm reluctant to change the behavior of OnBeforeBrowse in CEF3 at this time since there may be applications already depending on the current behavior. Is OnResourceRedirect called between the calls to OnBeforeBrowse in your case? If so, you can use that call to track the URL change in your handler implementation.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: OnBeforeBrowse CefRequest object has wrong URL on redire

Postby kbiskar » Tue Feb 03, 2015 6:00 pm

OnResourceRedirect does get triggered during this process (after the intial OnBeforeBrowse) however, I really wnat to modify the request once I find that it's a redirect.

To put this in context, we add special headers to requests for resources in specific domains. However, if one of those redirects from an approved domain to a non-approved domain, I want to remove the added headers so that we don't leak data to un-trusted sources. OnResourceResponse would work (if we check for a 302) except that by the time it hits, we've already leaked the data. OnResouceRedirect occurs at the right time, but there's no request object to work with. OnBeforeBrowse would work but there are issues. One is that the request is immutable, so we can't remove the headers. The workaround for that we cancel the request and call LoadUrl() on the new url which creates a new request where we don't add the headers in the first place. But without the new url in CEF3, I'll have to find another workaround.

I admit that this logic is more convoluted than it probably needs to be, so if you know an alternative, please let know. In general though, thanks for the quick updates and help.
kbiskar
Techie
 
Posts: 25
Joined: Mon May 12, 2014 1:02 pm

Re: OnBeforeBrowse CefRequest object has wrong URL on redire

Postby magreenblatt » Tue Feb 03, 2015 6:12 pm

Where are you setting the request headers currently? You can modify the request in OnBeforeResourceLoad which should be called after OnBeforeBrowse.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: OnBeforeBrowse CefRequest object has wrong URL on redire

Postby kbiskar » Tue Feb 03, 2015 7:14 pm

Currently we do set the headers in OnBeforeResourceLoad. However, I use Fiddler2 to examine these requests and, for CEF1, the leak happens before we hit OnBeforeResourceLoad() for the redirect. But after checking our CEF3 version, I see that we do hit this in time for it. I think my best bet is to patch CEF1 to include the Request in OnResourceRedirect and use OnBeforeResourceLoad() for CEF3.
kbiskar
Techie
 
Posts: 25
Joined: Mon May 12, 2014 1:02 pm

Re: OnBeforeBrowse CefRequest object has wrong URL on redire

Postby LeMoussel » Tue May 05, 2015 1:43 pm

I seem to have same problem with CEF 3.

I nitiate request with CefUrlRequest, it is walk by redirect chains.
But in CefRequestHandler::OnBeforeResourceLoad(...) it's to the original url, in CefRequestHandler::OnBeforeBrowse(...) isRedirect is False, CefRequestHandler::OnResourceRedirect(...) is never call
How to get the target Url, not the the original Url ?

For example : http://httpbin.org/redirect/1 redirection to http://httpbin.org/get
LeMoussel
Newbie
 
Posts: 2
Joined: Tue May 05, 2015 1:26 pm

Re: OnBeforeBrowse CefRequest object has wrong URL on redire

Postby kbiskar » Fri May 08, 2015 6:10 pm

LeMoussel it seems like you're not getting an actual redirect. When cef detects a redirect, you'll get a second call for the same request where the isRedirect flag will be true. Have you tried changing the "location" field instead of the "url" field? Something like that might trigger a full redirect.
kbiskar
Techie
 
Posts: 25
Joined: Mon May 12, 2014 1:02 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 100 guests