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

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

Open
dentarg opened this issue May 29, 2024 · 1 comment
Open

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

dentarg opened this issue May 29, 2024 · 1 comment
Assignees
Labels

Comments

@dentarg
Copy link
Member

dentarg commented May 29, 2024

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.

@dentarg
Copy link
Member Author

dentarg commented May 29, 2024

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

@dentarg dentarg self-assigned this Nov 11, 2024
@dentarg dentarg changed the title Support Forwarded header Support Forwarded header in Rack::Protection::IPSpoofing Nov 12, 2024
dentarg added a commit to dentarg/sinatra that referenced this issue Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant