Bug 1138137 - Undefined req.headers.host when using SSL on node.js application
Summary: Undefined req.headers.host when using SSL on node.js application
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: OpenShift Online
Classification: Red Hat
Component: Security
Version: 1.x
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: ---
: ---
Assignee: Dan McPherson
QA Contact: Xiaoli Tian
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-09-04 07:09 UTC by JVerstry
Modified: 2014-09-11 14:32 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2014-09-11 14:32:20 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description JVerstry 2014-09-04 07:09:46 UTC
Description of problem:

In a node.js Express 4.0 application using https, including forwarding from http to https, the received requests are not populated correctly. Some are not received at all.

I have opened a SO question with details: http://stackoverflow.com/questions/25654796/creating-an-express-js-4-0-application-with-https-on-openshift-including-http-r/

Some Openshift documentation (https://help.openshift.com/hc/en-us/articles/202398810-How-to-redirect-traffic-to-HTTPS-) recommends using:

    function redirectSec(req, res, next) {
        if (req.headers['x-forwarded-proto'] == 'http') { 
            res.redirect('https://' + req.headers.host + req.path);
        } else {
            return next();
        }
    }

for redirect, but this code does not work. In my tests (see SO question, ligatures.net), some requests slip through unpopulated (req.headers.host is undefined for example).
 
Moreover, it uses req.path which will ignore query parameters.

I have noticed that node.js applications created from Openshift use an old version of Express (~3.4.4). Today, Express 4.0 has been completely 'refurbished'.

It would be great if OpenShift was up to date with Express and if secured communications were tested properly (SSL & HTTPS). An operational and tested https code example would be fantastic. It is much needed.

Version-Release number of selected component (if applicable):

Unknown

How reproducible:

Creating a simple Express 4.0 node.js application with http -> https redirection and loading the certificates in the console. 

Actual results:

Improperly populated user requests.

Expected results:

Properly populated user requests.

Comment 1 JVerstry 2014-09-04 13:09:58 UTC
Something I forgot to mention, I am using Cloudflare too. This may have an impact on this issue.


Note You need to log in before you can comment on or make changes to this bug.