Skip to content

Add HostAuthorization rack-protection middleware - #2053

Merged
dentarg merged 34 commits into
sinatra:mainfrom
dentarg:host_authorization
Nov 18, 2024
Merged

dentarg merged 34 commits into
sinatra:mainfrom
dentarg:host_authorization

Conversation

@dentarg

@dentarg dentarg commented Nov 5, 2024 •

Copy link
Copy Markdown
Member

The Sinatra project received a security report with the following details:

Title: Reliance on Untrusted Inputs in a Security Decision
CWE ID: CWE-807
CVE ID: CVE-2024-21510
Credit: t0rchwo0d
Description: The sinatra package is vulnerable to Reliance on Untrusted
Inputs in a Security Decision via the X-Forwarded-Host (XFH) header.
When making a request to a method with redirect applied, it is possible
to trigger an Open Redirect Attack by inserting an arbitrary address
into this header. If used for caching purposes, such as with servers
like Nginx, or as a reverse proxy, without handling the
X-Forwarded-Host header, attackers can potentially exploit Cache
Poisoning or Routing-based SSRF.

The vulnerable code was introduced in fae7c01. Sinatra can not know whether the header value can be trusted or not without input from the app creator. This change introduce the host_authorization settings for that.

It is implemented as a Rack middleware, bundled with rack-protection, but not exposed as a default nor opt-in protection. It is meant to be used by itself, as sharing reaction with other protections is not ideal (see #2012).

@dentarg dentarg mentioned this pull request Nov 5, 2024
@dentarg
dentarg force-pushed the host_authorization branch from 4b63d7d to 691a573 Compare November 8, 2024 07:39
The Sinatra project received a security report with the following
details:

> Title: Reliance on Untrusted Inputs in a Security Decision
> CWE ID: CWE-807
> CVE ID: CVE-2024-21510
> Credit: t0rchwo0d
> Description: The sinatra package is vulnerable to Reliance on Untrusted
> Inputs in a Security Decision via the `X-Forwarded-Host (XFH)` header.
> When making a request to a method with redirect applied, it is possible
> to trigger an Open Redirect Attack by inserting an arbitrary address
> into this header. If used for caching purposes, such as with servers
> like Nginx, or as a reverse proxy, without handling the
> `X-Forwarded-Host` header, attackers can potentially exploit Cache
> Poisoning or Routing-based SSRF.

The vulnerable code was introduced in fae7c01. Sinatra can not know
whether the header value can be trusted or not without input from the
app creator. This change introduce the `permitted_hosts` setting for
that.

It is implemented as a Rack middleware, bundled with rack-protection,
but not exposed as a default nor opt-in protection. It is meant to be
used by itself, as sharing reaction with other protections is not ideal,
see sinatra#2012.
@dentarg
dentarg force-pushed the host_authorization branch from 691a573 to fb2d76d Compare November 8, 2024 08:18
@dentarg dentarg changed the title Add permitted_hosts setting Add HostAuthorization protection Nov 8, 2024
@dentarg dentarg changed the title Add HostAuthorization protection Add HostAuthorization rack-protection middleware Nov 11, 2024
If a forwarded header is present, that's what Rack::Request#host
returns. Applications may be making decisions based on the Host header,
even when the forwarded header is present, so we should ensure both
headers are permitted.

Reference: rails/rails#33145 (comment)
I doubt this can happen for real, but better safe than sorry.
@dentarg
dentarg marked this pull request as ready for review November 14, 2024 10:59
Comment thread README.md Resolved
Comment thread README.md Resolved
YOU54F added a commit to pact-foundation/pact-ruby that referenced this pull request Nov 29, 2024
YOU54F added a commit to pact-foundation/pact-ruby that referenced this pull request Nov 29, 2024
TylerHelmuth added a commit to honeycombio/libhoney-rb that referenced this pull request Dec 2, 2024
## Which problem is this PR solving?

- [Sinatra 4.1.0 introduced a host authorization option to Sinatra
apps](sinatra/sinatra#2053). That authorization
check was failing requests made in tests.

## Short description of the changes

-  Update the Honeycomb test server stub to allow anybody to talk to it.

Co-authored-by: Tyler Helmuth <[email protected]>
robbkidd added a commit to honeycombio/beeline-ruby that referenced this pull request Dec 2, 2024
## Which problem is this PR solving?

- [Sinatra 4.1.0 introduced a host authorization option to Sinatra apps](sinatra/sinatra#2053). That authorization check was failing requests made in tests.

## Short description of the changes

-  Update the test Sinatra server to allow anybody to talk to it.

Co-authored-by: Tyler Helmuth <[email protected]>
robbkidd added a commit to honeycombio/beeline-ruby that referenced this pull request Dec 2, 2024
## Which problem is this PR solving?

- [Sinatra 4.1.0 introduced a host authorization option to Sinatra
apps](sinatra/sinatra#2053). That authorization
check was failing requests made in tests.

## Short description of the changes

-  Update the test Sinatra server to allow anybody to talk to it.

---------

Co-authored-by: Tyler Helmuth <[email protected]>
koetsier added a commit to GovWifi/govwifi-acceptance-tests that referenced this pull request Dec 16, 2024
….1.0

The acceptance tests failed because Sinatra 4.1.0 introduced `HostAuthorization` sinatra/sinatra#2053, which rejects connections from remote hosts by default unless explicitly allowed. This behavior affects environments where the app is accessed from remote addresses during tests.

Setting `APP_ENV` to `production` fixes that, allowing the tests to pass without further configuration. Updated the environment setup to include this fix.
koetsier added a commit to GovWifi/govwifi-acceptance-tests that referenced this pull request Dec 17, 2024
….10 (#165)

* Fix acceptance test failures caused by HostAuthorization in Sinatra 4.1.0

The acceptance tests failed because Sinatra 4.1.0 introduced `HostAuthorization` sinatra/sinatra#2053, which rejects connections from remote hosts by default unless explicitly allowed. This behavior affects environments where the app is accessed from remote addresses during tests.

Setting `APP_ENV` to `production` fixes that, allowing the tests to pass without further configuration. Updated the environment setup to include this fix.

* Replace docker-compose with docker compose

Updated to use `docker compose`, the newer and recommended way of managing multi-container Docker applications, replacing the deprecated `docker-compose` command.
mishina2228 added a commit to mishina2228/youtube-api-trial that referenced this pull request Dec 27, 2024
mishina2228 added a commit to mishina2228/youtube-api-trial that referenced this pull request Dec 27, 2024
smortex added a commit to riemann/riemann-tools that referenced this pull request Jan 15, 2025
Recent versions of Sinatra ensure the requested hostname is allowed and
return a 403 error if not.  This trigger in CI because we use custom
host names rather than localhost.

See:
sinatra/sinatra#2053

Allow any domain as this is used for testing and we are not concerned by
the security vulnerability this change upstream is meant to fix.
zzak pushed a commit to zzak/sinatra that referenced this pull request May 24, 2025
The Sinatra project received a security report with the following
details:

> Title: Reliance on Untrusted Inputs in a Security Decision
> CWE ID: CWE-807
> CVE ID: CVE-2024-21510
> Credit: t0rchwo0d
> Description: The sinatra package is vulnerable to Reliance on
Untrusted
> Inputs in a Security Decision via the `X-Forwarded-Host (XFH)` header.
> When making a request to a method with redirect applied, it is
possible
> to trigger an Open Redirect Attack by inserting an arbitrary address
> into this header. If used for caching purposes, such as with servers
> like Nginx, or as a reverse proxy, without handling the
> `X-Forwarded-Host` header, attackers can potentially exploit Cache
> Poisoning or Routing-based SSRF.

The vulnerable code was introduced in fae7c01. Sinatra can not know
whether the header value can be trusted or not without input from the
app creator. This change introduce the `host_authorization` settings for
that.

It is implemented as a Rack middleware, bundled with rack-protection,
but not exposed as a default nor opt-in protection. It is meant to be
used by itself, as sharing reaction with other protections is not ideal.
zzak pushed a commit to zzak/sinatra that referenced this pull request May 24, 2025
The Sinatra project received a security report with the following
details:

> Title: Reliance on Untrusted Inputs in a Security Decision
> CWE ID: CWE-807
> CVE ID: CVE-2024-21510
> Credit: t0rchwo0d
> Description: The sinatra package is vulnerable to Reliance on
Untrusted
> Inputs in a Security Decision via the `X-Forwarded-Host (XFH)` header.
> When making a request to a method with redirect applied, it is
possible
> to trigger an Open Redirect Attack by inserting an arbitrary address
> into this header. If used for caching purposes, such as with servers
> like Nginx, or as a reverse proxy, without handling the
> `X-Forwarded-Host` header, attackers can potentially exploit Cache
> Poisoning or Routing-based SSRF.

The vulnerable code was introduced in fae7c01. Sinatra can not know
whether the header value can be trusted or not without input from the
app creator. This change introduce the `host_authorization` settings for
that.

It is implemented as a Rack middleware, bundled with rack-protection,
but not exposed as a default nor opt-in protection. It is meant to be
used by itself, as sharing reaction with other protections is not ideal.
voxik added a commit to voxik/capybara that referenced this pull request Jun 19, 2025
Rack::Protection 4.1.0 has introduced new
`Rack::Protection::HostAuthorization` [[1]]]. This makes `www.example.com`
host to be rejected. The easiest solution is to disable this check for
the TestApp.

[1]: sinatra/sinatra#2053
voxik added a commit to voxik/capybara that referenced this pull request Jun 19, 2025
Rack::Protection 4.1.0 has introduced new
`Rack::Protection::HostAuthorization` [[1]]. This makes `www.example.com`
host to be rejected. The easiest solution is to disable this check for
the TestApp.

[1]: sinatra/sinatra#2053
simi pushed a commit to teamcapybara/capybara that referenced this pull request Jun 19, 2025
Rack::Protection 4.1.0 has introduced new
`Rack::Protection::HostAuthorization` [[1]]. This makes `www.example.com`
host to be rejected. The easiest solution is to disable this check for
the TestApp.

[1]: sinatra/sinatra#2053
twalpole pushed a commit to teamcapybara/capybara that referenced this pull request Aug 8, 2025
Rack::Protection 4.1.0 has introduced new
`Rack::Protection::HostAuthorization` [[1]]. This makes `www.example.com`
host to be rejected. The easiest solution is to disable this check for
the TestApp.

[1]: sinatra/sinatra#2053
benoittgt added a commit to benoittgt/webmock that referenced this pull request Oct 7, 2025
While working on this sinatra/sinatra#2053 in
our project. I noticed than when using Webmock, sinatra logs and
especially the enforced rack-protection were showing this kind of logs:

```
D, [2024-11-22T13:05:16.798156 #26673] DEBUG -- : Rack::Protection::HostAuthorization @all_permitted_hosts=[".company.com"] @permitted_hosts=["company.com"] @domain_hosts=[/\A(?-mix:[a-z0-9\-.]+)company\.com\z/i] @ip_hosts=[] origin_host="" forwarded_host=nil
```

As you can see, `origin_host` is empty, because the header is missing.

When not using webmock, we fallback on `net/http` host header setup.
https://github.com/ruby/net-http/blob/cfbbb50c931a78fc2b5c731b9abeda161e1dfdd1/lib/net/http.rb#L2482
GCorbel pushed a commit to GCorbel/sinatra that referenced this pull request Dec 17, 2025
The Sinatra project received a security report with the following
details:

> Title: Reliance on Untrusted Inputs in a Security Decision
> CWE ID: CWE-807
> CVE ID: CVE-2024-21510
> Credit: t0rchwo0d
> Description: The sinatra package is vulnerable to Reliance on
Untrusted
> Inputs in a Security Decision via the `X-Forwarded-Host (XFH)` header.
> When making a request to a method with redirect applied, it is
possible
> to trigger an Open Redirect Attack by inserting an arbitrary address
> into this header. If used for caching purposes, such as with servers
> like Nginx, or as a reverse proxy, without handling the
> `X-Forwarded-Host` header, attackers can potentially exploit Cache
> Poisoning or Routing-based SSRF.

The vulnerable code was introduced in fae7c01. Sinatra can not know
whether the header value can be trusted or not without input from the
app creator. This change introduce the `host_authorization` settings for
that.

It is implemented as a Rack middleware, bundled with rack-protection,
but not exposed as a default nor opt-in protection. It is meant to be
used by itself, as sharing reaction with other protections is not ideal.
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.

5 participants