Repository navigation
Add request feature detection - #79
mattrobenolt merged 5 commits into
Conversation
* Add several tests for each request property available on the HTTP interface. * Add support for request abstractions such as Koa and Express. * Improve error handling for malformed or incomplete request objects. * Add support for `X-Forwarded-Port` for more robus HTTPS detection.
There was a problem hiding this comment.
X-Forwarded-Proto doesn't keep getting appended to like X-Forwarded-For, so there's no need to split apart.
There was a problem hiding this comment.
That's dumb. That 100% doesn't make sense why anything would do that.
What proxy out there appends these together? There's only one valid value, and that's https. There's no value whatsoever in setting it to http or appending a chain of them.
So what out there is appending these? I know of none.
There was a problem hiding this comment.
And I'd argue that if something were doing that, they're doing it wrong.
There was a problem hiding this comment.
I know this is irrelevant at this point, but I'm curious about your statement. Other searches point to the same logic - e.g., one of the most popular php frameworks also does it. Is it precaution, lack of standard or just incorrect? I'm not aware of any proxy doing this, but I'd like to know from your experience though.
|
Can you comment on where all the information is coming from? Especially when they're values coming from a framework and why we have to do the various fallbacks? I'll never remember and someone will ask me in the future. :) |
|
@mattrobenolt updated with all the suggestions you asked for. I think the only left for merging this PR is deciding whether the x-forwarded-stuff should be kept or not! Let me know how you'd like to proceed. |
There was a problem hiding this comment.
Do we really need to include this dependency? It's very trivial to check if something is an object.
Why can't we just do: if (''+req.cookies === '[object Object]') ?
There was a problem hiding this comment.
No. ''+(new function(){}).toString() === ''+({}) which is the reason why I've used the lodash function. Anyway, I've removed this and decided to only rely on the cookie parser instead.
This should be moved to the middleware layer instead, delegating `X-Forwarded-For` to `req.ip` and `X-Forwarded-Proto` to `req.secure`.
Instead of looking at `req.cookies`, the parser will only detect cookies set in headers because ultimately that is where middleware originally grabs the information from. This results in a much simplified logic.
koa uses `request.header` as an alias to `req.headers`, while express inherits `req.headers` from IncomingMessage.
|
@mattrobenolt do you think there is anything left to do before merging this? |
|
Any idea why this is erroring on 0.8? I'm tempted to just pull this and try to fix it on master. :/ |
|
|
|
Confirmed tests are passing in node 0.8 with |
|
I think I'd rather just pin |
Add request feature detection
|
Thank you for your time in reviewing this PR! Could you please tag a new release when you have a moment to spare? Cheers! |
|
Yep, I'm working on a couple things on master, but it'll be released today. |
|
@mattrobenolt are those changes complete? A version bump would be greatly appreciated :) sorry for pushing this issue again. |
|
I just pushed 0.7.0 to npm. :) |
|
Thank you! |
|
It looks like this reverted the changes made in #78. What's the desired way to set the user when running behind a proxy that sets /* @flow */
import Raven from 'raven';
import type {
$Request as Request,
$Response as Response,
NextFunction,
Middleware,
} from 'express';
export default function sentryContextMiddleware(): Middleware {
return (req: Request, res: Response, next: NextFunction) => {
const remoteIp =
(req.headers['x-forwarded-for'] || '').split(',')[0] ||
(req.connection && (req.connection: any).remoteAddress);
const user: { [string]: mixed } = {
ip_address: remoteIp, // eslint-disable-line camelcase
};
Raven.mergeContext({ user });
next();
};
}Should that (or is that) documented somewhere? |
interface.
X-Forwarded-Portfor more robus HTTPS detection.