Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returned Rest response URL does not include port number #330

Open
lsafelix75 opened this issue Feb 13, 2021 · 3 comments
Open

Returned Rest response URL does not include port number #330

lsafelix75 opened this issue Feb 13, 2021 · 3 comments

Comments

@lsafelix75
Copy link

lsafelix75 commented Feb 13, 2021

Hi,

The following is the log of remoteopenhab binding. As you can see, the replied rest response's url reference truncate port number. This could be a problem if openhabcloud private instance doesn't use standard port.

14:53:52.951 [OH-safeCall-1] DEBUG o.o.b.r.i.h.RemoteopenhabBridgeHandler:127 - Initializing remote openHAB handler for bridge remoteopenhab:server:oh 14:53:52.954 [OH-safeCall-1] DEBUG o.o.b.r.i.h.RemoteopenhabBridgeHandler:153 - REST URL = https://myopenhab.org:443/rest/ 14:53:52.957 [-thingHandler-1] DEBUG o.o.b.r.i.h.RemoteopenhabBridgeHandler:334 - Try the root REST API... 14:53:52.963 [-thingHandler-1] DEBUG o.o.b.r.i.r.RemoteopenhabRestClient:521 - Request GET https://myopenhab.org/rest/ (provided url https://myopenhab.org:443/rest/ 14:53:53.707 [-thingHandler-1] DEBUG o.o.b.r.i.r.RemoteopenhabRestClient:153 - REST API version = 4 14:53:53.708 [-thingHandler-1] DEBUG o.o.b.r.i.r.RemoteopenhabRestClient:158 - REST API items = https://myopenhab.org/rest/items 14:53:53.708 [-thingHandler-1] DEBUG o.o.b.r.i.r.RemoteopenhabRestClient:159 - REST API things = https://myopenhab.org/rest/things 14:53:53.708 [-thingHandler-1] DEBUG o.o.b.r.i.r.RemoteopenhabRestClient:160 - REST API events = https://myopenhab.org/rest/events

@lsafelix75
Copy link
Author

lsafelix75 commented Feb 14, 2021

I found the culprit. Please review this line and possible replace it with X-Forward-Host in routes/index.js line 380. This line may cause issue if the openhabcloud's serving port is not on standard HTTP/80 and HTTPS/443 ports

 var requestId = this.requestTracker.acquireRequestId();
    // make a local copy of request headers to modify
    var requestHeaders = req.headers;
    // We need to remove and modify some headers here
    delete requestHeaders['cookie'];
    delete requestHeaders['cookie2'];
    delete requestHeaders['authorization'];
    delete requestHeaders['x-real-ip'];
    delete requestHeaders['x-forwarded-for'];
    delete requestHeaders['x-forwarded-proto'];
    delete requestHeaders['connection'];
    requestHeaders['host'] = /*req.headers["host"]*/ req.headers["x-forwarded-host"] || system.getHost() + ':' + system.getPort();
    requestHeaders['user-agent'] = 'openhab-cloud/0.0.1';

@lsafelix75
Copy link
Author

#331

@pavkamlc
Copy link

pavkamlc commented Jan 7, 2022

I found the culprit. Please review this line and possible replace it with X-Forward-Host in routes/index.js line 380. This line may cause issue if the openhabcloud's serving port is not on standard HTTP/80 and HTTPS/443 ports

 var requestId = this.requestTracker.acquireRequestId();
    // make a local copy of request headers to modify
    var requestHeaders = req.headers;
    // We need to remove and modify some headers here
    delete requestHeaders['cookie'];
    delete requestHeaders['cookie2'];
    delete requestHeaders['authorization'];
    delete requestHeaders['x-real-ip'];
    delete requestHeaders['x-forwarded-for'];
    delete requestHeaders['x-forwarded-proto'];
    delete requestHeaders['connection'];
    requestHeaders['host'] = /*req.headers["host"]*/ req.headers["x-forwarded-host"] || system.getHost() + ':' + system.getPort();
    requestHeaders['user-agent'] = 'openhab-cloud/0.0.1';

This is not good solution. When I tried, URL is changed to url of OH3 destination port instead of client using port.
I use: OH3 tcp/8443, openhabcloud tcp/3000, nginx-proxy tcp/9443 and rest query to 9443 returns urls with 8443

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants