Documentation
¶
Overview ¶
Package clientip finds the address of the client that called an API Gateway API, looking past the proxies the application trusts: one rule for HTTP APIs (request.ClientIP) and REST APIs (the framework's REST path).
Index ¶
Constants ¶
const Unknown = "unknown"
Unknown is what Resolve answers when the request carries no address.
Variables ¶
This section is empty.
Functions ¶
func REST ¶
func REST(r *events.APIGatewayProxyRequest, trustedProxies int) string
REST returns the address of the client that called an API Gateway REST API (Lambda proxy integration, payload format 1.0): Resolve on requestContext.identity.sourceIp and X-Forwarded-For.
func Resolve ¶
Resolve returns the address of the client, from sourceIP, the peer API Gateway itself saw, and forwardedFor, the X-Forwarded-For header.
With trustedProxies 0 it is sourceIP, which the client cannot forge. The first entry of X-Forwarded-For is never used, since the client writes it.
When trustedProxies proxies of yours sit in front of API Gateway (CloudFront is one), sourceIP is the last of them and each of them appended to X-Forwarded-For the address it saw, so the client is the trustedProxies-th entry counting from the right (after dropping the sourceIP API Gateway may append itself). This holds only if API Gateway cannot be reached around those proxies: a caller that goes straight to it can still choose that entry.
Types ¶
This section is empty.