Skip to content

Support Forwarded header in Rack::Protection::IPSpoofing #2011

Open

Description

@dentarg

See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded

Since Rack 3 (rack/rack#1834) the Forwarded is supported (and preferred).

Sinatra does not make use of this:

def forwarded?
@env.include? 'HTTP_X_FORWARDED_HOST'
end

Which one to prefer should probably be exposed to the end-user.

Activity

  1. dentarg commented on May 29, 2024

    @dentarg
    MemberAuthor

    Here too

    def accepts?(env)
    return true unless env.include? 'HTTP_X_FORWARDED_FOR'
    ips = env['HTTP_X_FORWARDED_FOR'].split(',').map(&:strip)
    return false if env.include?('HTTP_CLIENT_IP') && (!ips.include? env['HTTP_CLIENT_IP'])
    return false if env.include?('HTTP_X_REAL_IP') && (!ips.include? env['HTTP_X_REAL_IP'])
    true
    end

  2. self-assigned this
    on Nov 11, 2024
  3. changed the title [-]Support `Forwarded` header[/-] [+]Support `Forwarded` header in `Rack::Protection::IPSpoofing`[/+] on Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions