Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

IP address lost when using express behind a proxy and 'trust proxy' is enabled #360

@rwky

Description

@rwky

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

When app.enable('trust proxy') is enabled req.ip is undefined here https://github.com/getsentry/raven-node/blob/master/lib/parsers.js#L154 this results in req.connection.remoteAddress being used.

What is the expected behavior?

req.ip shouldn't be undefined and used.

I've created a test case:

  1. In an empty folder run npm install express raven

  2. Create index.js with the following:

var http = require('http')
var express = require('express')
var app = express()
app.enable('trust proxy')

var raven = require('raven')

var dsn = '';
raven.config(dsn, {
  autoBreadcrumbs: true
}).install();

app.use(raven.requestHandler());

app.get('/', function(req, res) {
    res.send('hello world ' + req.ip)
})

app.get('/err', function(req, res) { 
    throw new Error('test')
})

app.use(raven.errorHandler());
http.createServer(app).listen(8888);
  1. Set up a proxy to forward to the node app, I used nginx with the following config:
 location / {
                proxy_pass http://172.17.0.1:8888;
                proxy_set_header  X-Forwarded-For $remote_addr;
               proxy_set_header  X-Real-IP       $remote_addr;
        }
  1. Visit / via the proxy and you'll see hello world and the IP printed

  2. Visit /err via the proxy, it'll throw an error, check this in sentry it won't show the IP. I checked that the line mentioned above is resulting in req.ip undefined.

I've not had time to debug why req.ip is undefined but since it's not undefined when accessed outside raven I'm assuming it's a bug in raven.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions