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

Add HTTPS detection via X-Forwarded-Proto - #78

Merged
mattrobenolt merged 1 commit into
getsentry:masterfrom
seegno-forks:feature/x-forwarded-proto-support
May 26, 2014
Merged

mattrobenolt merged 1 commit into
getsentry:masterfrom
seegno-forks:feature/x-forwarded-proto-support

Conversation

@ruimarinho

Copy link
Copy Markdown
Contributor

Similarly to X-Forwarded-For, X-Forwarded-Proto should also be taken into account when parsing the request object. One thing that stands out is that there is no whitelist support for filtering out spoofed values for X-Forwarded-For. Would you be open to integration with a more robust implementation such as forwarded-for?

@mattrobenolt

Copy link
Copy Markdown
Contributor

I don't see a security issue with just trusting the header, in this case. Since we don't actually use it to do anything that could harm the user, if somebody says they're X-Forwarded-Proto: https and it's not... the worst that'll happen is it shows up in Sentry as an https url.

Also, I don't feel that this behavior should happen from within raven. I feel like it should happen upstream, either in the web server, or within a middleware. Or do people not do that for node stuff?

@mattrobenolt

Copy link
Copy Markdown
Contributor

Also note, it's common to use X-Forwarded-Port: 443 to detect https. Which is why I'd be more comfortable if this logic was wrapped up into a generic connect middleware if it doesn't exist already. And then raven can leverage that information if it's present.

@ruimarinho

Copy link
Copy Markdown
Contributor Author

I was mentioning the spoof issue regarding X-Forwarded-For, not X-Forwarded-Proto since, like you said, there is no actual security issue in trusting the latter header if only for presentational purposes.

The reason I've added support for this particular header (and perhaps the missing X-Forwarded-Port too) is that parseRequest does not offer a simple way of extending the http object that is constructed there. I'm not sure how connect handles the request, but Koa, for instance, deals with some of this logic but exposes its own subset of the original node request object with a specific API.

There are certainly several ways of working around this, but not without refactoring some code. What do you suggest?

@mattrobenolt

Copy link
Copy Markdown
Contributor

I'm ok with this for now. I don't have an answer for a better solution at the moment since I don't have much experience with any of these frameworks, so I'm open to ideas for improvements. :)

mattrobenolt added a commit that referenced this pull request May 26, 2014
Add HTTPS detection via X-Forwarded-Proto
@mattrobenolt
mattrobenolt merged commit 64f9124 into getsentry:master May 26, 2014
@ruimarinho

Copy link
Copy Markdown
Contributor Author

@mattrobenolt thanks, appreciated. What do you think about adding framework-specific parse methods, such as parseKoaRequest and parseExpressRequest? Another option would be checking certain object properties that these abstractions usually have (e.g. req.host, req.protocol, etc.).

@ruimarinho
ruimarinho deleted the feature/x-forwarded-proto-support branch May 27, 2014 00:48
@mattrobenolt

Copy link
Copy Markdown
Contributor

I'd rather just feature detect and do it automatically. For example, attempt to use information that libraries shove onto req first, then fall back.

@ruimarinho

Copy link
Copy Markdown
Contributor Author

Working on it for Koa (should match an express request too).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants