Skip to content

xForwardedHeaders doesn't always forward x-forwarded-for #5292

@OliverJAsh

Description

@OliverJAsh

What version of Effect is running?

No response

What steps can reproduce the bug?

Currently the xForwardedHeaders middleware only applies when there's an x-forwarded-host header. However, there are some cases where we expect to receive headers like x-forwarded-for without x-forwarded-host.

For example, this is the behaviour I'm seeing in an AWS Lambda. Related docs.

For this reason I would like to suggest changing the xForwardedHeaders middleware so it always uses x-forwarded-for if there is one.

export const xForwardedHeaders = make((httpApp) =>
Effect.updateService(httpApp, ServerRequest.HttpServerRequest, (request) =>
request.headers["x-forwarded-host"]
? request.modify({
headers: Headers.set(
request.headers,
"host",
request.headers["x-forwarded-host"]
),
remoteAddress: request.headers["x-forwarded-for"]?.split(",")[0].trim()

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions