Core: Request.secure() behind http proxy?

Created on 2 Nov 2017  路  5Comments  路  Source: adonisjs/core

Request.secure() doesn't work behind a proxy that forwards as http.

Something like this would work maybe?

class Request {
   function secure() {
     return nodeReq.secure(this.request)  || this.header('X-Forwarded-Proto')=='https'
   }
}

Most helpful comment

Yeah it will be better to implement this in nodeReq. I will do that

All 5 comments

Yeah it will be better to implement this in nodeReq. I will do that

Looking the code and it seems that it does takes the X-Forwarded-Proto header for the proxy server into consideration when fetching the protocol.

https://github.com/poppinss/node-req/blob/develop/src/Request/index.js#L291

Can u please make sure that value of trustProxy is set to true inside config/app.js

This was not my issue, so I don't have an immediate test case. Shall we add something to the docs and then close this?

I have added a recipe that shows the minimal/ideal config of nginx and also stated that the of trustProxy should be true. I believe that will be enough to educate the end-user.

I personally tested all of the following methods behind nginx and they all work fine.

  1. secure
  2. protocol
  3. ip

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aligoren picture aligoren  路  4Comments

milosdakic picture milosdakic  路  3Comments

imperez picture imperez  路  4Comments

itsg2jakhmola picture itsg2jakhmola  路  3Comments

amrayoub picture amrayoub  路  4Comments