Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add requestContext.sourceIp fallback for missing x-forwarded-for #85

Closed
nickmeldrum opened this issue Dec 12, 2018 · 4 comments
Closed
Milestone

Comments

@nickmeldrum
Copy link

The REQUEST.ip property is mapped from the x-forwarded-for header instead of the sourceIp property on the event.requestContext property.

Can you give me the info about why?

The problem I have is when running this in serverless-local to emulate a lambda locally for my testing, the ip comes through as undefined.

@jeremydaly
Copy link
Owner

jeremydaly commented Dec 12, 2018

Hi @nickmeldrum,

The x-forwarded-for is the standard way to extract IP addresses from a proxy so it was implemented that way. This also works with the new ALB routing (which doesn't have an IP address as part of the request context).

However, I can see the issue with your local use case, so I can add a fallback if the x-forwarded-for is undefined or null.

Thanks for the report,
Jeremy

@jeremydaly jeremydaly changed the title QUESTION about how/why IP is mapped Add requestContext.sourceIp fallback for missing x-forwarded-for Dec 12, 2018
@jeremydaly jeremydaly added this to the v0.10 milestone Dec 12, 2018
@nickmeldrum
Copy link
Author

interesting thanks - is it right for you to add a fallback or for the serverless-local package to correctly set the x-forwarded-for header i wonder?

@jeremydaly
Copy link
Owner

Good question, probably the latter. However, I'm adding support for Lambda@Edge functions as well, and according to this documentation (https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html#lambda-event-structure-request), those events don't contain x-forwarded-for either.

There may need to be a number of fallbacks to normalize the client IP address, so I think it would be worth adding.

@nickmeldrum
Copy link
Author

good info cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants