Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

$http.get() hangs for certain URL input #13998

Closed
worzella opened this issue Feb 10, 2016 · 2 comments
Closed

$http.get() hangs for certain URL input #13998

worzella opened this issue Feb 10, 2016 · 2 comments

Comments

@worzella
Copy link

Overview of the Issue - When providing some URL inputs that contain a colon, the $http.get() invocation hangs and the promise chain is never completed.

Motivation for or Use Case - Our device management app requires the user to input an IP address and during input validation testing we realized several input strings that contain a colon cause the hang. We could just filter out the colon, except that colons are critical to IPv6 addresses.

Angular Version(s) - This is an Ionic app, so we use the angular level in the ionic.bundle.js. window.ionic.version
"1.2.4-nightly-1917"

Browsers and Operating System - "Mozilla/5.0 (Linux; Android 5.1.1; SM-G920F Build/LMY47X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Crosswalk/16.45.421.19 Mobile Safari/537.36"

Reproduce the Error - Our app has an initial GET to the server to determine the server appliance level, as such:

vm.getVersion = function(address, userid, password) {
  return $http.get('https://' + address + '/aicc', {
    timeout: 10000,
    headers: {
      'Authorization': vm.basicAuth(userid, password)
    }
  }).then(function(response) {
    return response.data.appliance.version;
  }, function(error) {
    return $q.reject(error);
  });
};

The text input by the user is the 'address' field. Although not valid addresses, inputs like the following cause the hang:

6::5
:d
abcx:d

However, very oddly, these inputs do not cause the hang:

http:
abc:
6:7

Also, regardless of the specifics of our app, I tried a very simple Fiddle and was shocked to see the same failures in this simple environment.

fiddle

If you run the Fiddle with the console network trace, you will see the /aicc GET sent over the network for the good cases, but for the failing cases, that GET never flows to the server.

Related Issues - None that I could find

Suggested fix - I did do some debugging in the $createHttpBackend() method in the XHR path and determined a couple of things. The xhr.onerror and xhr.onabort event handlers are init'd with a requestError() routine that when run, invokes a callback to complete the promise chain. In the cases where all is good, I see this requestError running and the callback triggered. And as I mentioned in the good cases the GET packet flows to the server.

For the failing case, the packet never flows when the xhr.send() is invoked and neither the onerror or onabort handlers execute. However, the timeoutRequest() runs, at least in my investigation. In this function I see that they execute this:

xhr&&xhr.abort()

I can fix my problem with one of two tweaks in this timeoutRequest() function, but I am not sure they are kosher fixes. I can either invoke this:

xhr&&xhr.onabort()

or I can simply invoke this:

completeRequest(callback, -1, null, null, '');

In both cases, the callback is run and the promise chain is resolved and my app is happy.

@gkalpak
Copy link
Member

gkalpak commented Feb 10, 2016

I'm not sure what browser/OS you tried this on, but I can't reproduce any "hanging" on Chrome/Win10.
What I see though, is that for the three address you say don't work, there are indeed no requests sent (thus nothing shows up in the Network panel), because they are blocked by the browser with the error message:
Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

My guess is that the browser gets confused by the colons and idntifies the protocol incorreclty, so it blocks the request. (E.g. in https://6::5/aicc, it probably recognizes the protocol as https://6::.)

In all cases, I do see the rejection callbacks being called though. If you are experiencing something different, it's most probably a browser quirk.

That said, I don't believe this is Angular related, as I can reproduce the exact same behavior with a raw XMLHttpRequest.

@worzella, could you:

  1. Specify the exact browser and OS make and version ?
  2. Try to reproduce the issue using raw XMLHttpRequest.
  3. Post a link to the fiddle you mention, where the issue can be reproduced ?

@Narretz
Copy link
Contributor

Narretz commented Feb 28, 2016

Closing due to lack of feedback.

@Narretz Narretz closed this as completed Feb 28, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants