Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Bug in RPCManager::_getHostAndPort(url)

    I'm using SmartClient_SC_SNAPSHOT-2010-08-25 and there is issue with fetching datasource data. In my case there is a proxy which modifies every url and makes them not relative. This triggers checking if this address is "local" so no XSS browser warnings arise or if the communication is in fact possible.

    This check is done in function RPCManager::sendProxied, uses result of function RPCManager::isLocalURL(url) and shows warning "SmartClient can't directly contact URL XXXX due to browser same-origin policy....".

    Further checking lead me to function RPCManager::_getHostAndPort(url) which should return array with hostname and port separated. Those values are then comared in isLocalURL function with current page values (window.location.hostname and window.location.port).

    Unfortunately when port is not specified (ie. default 80) function _getHostAndPort returns undefined value for port, but window.localtion.port returns empty string.
    This causes the check to return false (meaning "this is not local address"), when in fact it is. The message is shown, but when you clik "ok" the request is done and you get proper data in return, so application works fine. The only problem is the message is shown on EVERY request made to server...

    This behaviour I can reproduce on Chrome and FF, so it is important to remove this bug.

    My solution - initiate "port" variable with empty string in function _getHostAndPort:

    Code:
    _getHostAndPort : function (url) {
        var protocol = isc.Page.getProtocol(url),
            // first slash after the protocol
            endHostSlash = url.indexOf("/", protocol.length),
            host = url.substring(protocol.length, endHostSlash),
            port = ''
        ;
        var colIndex = host.indexOf(":");
        if (colIndex != -1) {
           port = host.substring(colIndex+1);
           host = host.substring(0, colIndex);
        }
           
        return [host, port];
    },
Working...
X