Skip to content

slight improvements in Rack::Protection::HostAuthorization docs#2097

Open
davetron5000 wants to merge 1 commit intosinatra:mainfrom
davetron5000:improve-host-authorization-docs
Open

slight improvements in Rack::Protection::HostAuthorization docs#2097
davetron5000 wants to merge 1 commit intosinatra:mainfrom
davetron5000:improve-host-authorization-docs

Conversation

@davetron5000
Copy link

Problem

Rack::Protection::HostAuthorization's options and behaviors could be better documented.

Solution

  • Change options header to match other classes
  • Detailed explanation of permitted hosts
  • Document behavior of allow_if
  • References to how the host is determined
  • Examples

# Blocks HTTP requests with an unrecognized hostname in any of the following
# HTTP headers: Host, X-Forwarded-Host, Forwarded
# HTTP headers: Host, X-Forwarded-Host, Forwarded, based on
# {<tt>Request#forwarded_authority</tt>}[https://rubydoc.info/github/rack/rack/Rack/Request/Helpers#forwarded_authority-instance_method] and
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the ultimate user of this is likely someone working at the Rack or Sinatra level, I figured it would be helpful to include these specifics about how the hosts are determined beyond just the headers that are used.

# If you want to permit a specific hostname, you can pass in as the `:permitted_hosts` option:
# == Options
#
# [<tt>:permitted_hosts</tt>] an Array of hosts to allow. Elements can be as follows:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this accepts a single value, the docs were getting complicated trying to explain that you can have an array or a value, etc. So I kept it as just an array in the docs

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant