sinatra 4.0.0 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sinatra might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -2
- data/Gemfile +6 -2
- data/README.md +30 -10
- data/VERSION +1 -1
- data/lib/sinatra/base.rb +37 -14
- data/lib/sinatra/indifferent_hash.rb +1 -1
- data/lib/sinatra/middleware/logger.rb +21 -0
- data/lib/sinatra/version.rb +1 -1
- data/sinatra.gemspec +2 -1
- metadata +32 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a487551e0b40831dadeffd669ae0a8fb408fc5880825f2257105beec8be727ec
|
4
|
+
data.tar.gz: f7999f252d7d1c2192a3c909911ff5879075a811a8c742c89a2d700bf1db8b82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 611bf8733959bae4110a357e22be091cd3c044a5f810d133a9833993c84e2ae7a3b2c3999fd13991338c44e72ac5ab6b9b3af8bc9d4667384fd97b7715c086d2
|
7
|
+
data.tar.gz: 824f4f37c5cc5fde671bdf286c63cd67672566c10fadcf80b841eddc9685f92b88a9032ee8b711a2b859a5529afc082fe11f09ac1204f8b04659501f13a03747
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
## 4.1.0 / 2024-11-18
|
2
|
+
|
3
|
+
* New: Add `host_authorization` setting ([#2053](https://github.com/sinatra/sinatra/pull/2053))
|
4
|
+
* Defaults to `.localhost`, `.test` and any IP address in development mode.
|
5
|
+
* Security: addresses [CVE-2018-11627](https://github.com/advisories/GHSA-hxx2-7vcw-mqr3).
|
6
|
+
* Fix: Return an instance of `Sinatra::IndifferentHash` when calling `#except` ([#2044](https://github.com/sinatra/sinatra/pull/2044))
|
7
|
+
* Fix: Address warning from `URI` for Ruby 3.4 ([#2060](https://github.com/sinatra/sinatra/pull/2060))
|
8
|
+
* Fix: `rackup` no longer depends on WEBrick, recommend Puma instead ([`4a558503`](https://github.com/sinatra/sinatra/commit/4a558503a0ee41f26d4ebc07b478340e8a8a5ed6))
|
9
|
+
* Fix: Zeitwerk 2.7.0+ compatibility ([#2050](https://github.com/sinatra/sinatra/pull/2050))
|
10
|
+
* Fix: Address warning about Hash construction for Ruby 3.4 ([#2028](https://github.com/sinatra/sinatra/pull/2028))
|
11
|
+
* Fix: Declare missing dependencies for Ruby 3.5 ([#2032](https://github.com/sinatra/sinatra/pull/2032))
|
12
|
+
* Fix: Compatibility with `--enable-frozen-string-literal` ([#2033](https://github.com/sinatra/sinatra/pull/2033))
|
13
|
+
* Fix: Rack 3.1 compatibility ([#2035](https://github.com/sinatra/sinatra/pull/2035))
|
14
|
+
* Don't depend on `Rack::Logger`
|
15
|
+
* Don't delete `content-length` header when `Rack::Files` is used
|
16
|
+
|
1
17
|
## 4.0.0. / 2024-01-19
|
2
18
|
|
3
19
|
* New: Add support for Rack 3 ([#1857])
|
@@ -243,7 +259,7 @@
|
|
243
259
|
|
244
260
|
* Fix issue with passed routes and provides Fixes [#1095](https://github.com/sinatra/sinatra/pull/1095) [#1606](https://github.com/sinatra/sinatra/pull/1606) by Mike Pastore, Jordan Owens
|
245
261
|
|
246
|
-
* Add QuietLogger that excludes
|
262
|
+
* Add QuietLogger that excludes paths from Rack::CommonLogger [1250](https://github.com/sinatra/sinatra/pull/1250) by Christoph Wagner
|
247
263
|
|
248
264
|
* Sinatra::Contrib dependency updates. Fixes [#1207](https://github.com/sinatra/sinatra/pull/1207) [#1411](https://github.com/sinatra/sinatra/pull/1411) by Mike Pastore
|
249
265
|
|
@@ -1609,7 +1625,7 @@ the 1.0 release:
|
|
1609
1625
|
Hash structure. e.g., "post[title]=Hello&post[body]=World" yields
|
1610
1626
|
params: {'post' => {'title' => 'Hello', 'body' => 'World'}}.
|
1611
1627
|
|
1612
|
-
* Regular expressions may now be used in route
|
1628
|
+
* Regular expressions may now be used in route patterns; captures are
|
1613
1629
|
available at "params[:captures]".
|
1614
1630
|
|
1615
1631
|
* New ":provides" route condition takes an array of mime types and
|
data/Gemfile
CHANGED
@@ -22,6 +22,10 @@ puma_version = nil if puma_version.empty? || (puma_version == 'stable')
|
|
22
22
|
puma_version = { github: 'puma/puma' } if puma_version == 'head'
|
23
23
|
gem 'puma', puma_version
|
24
24
|
|
25
|
+
zeitwerk_version = ENV['zeitwerk'].to_s
|
26
|
+
zeitwerk_version = nil if zeitwerk_version.empty? || (zeitwerk_version == 'stable')
|
27
|
+
gem 'zeitwerk', zeitwerk_version
|
28
|
+
|
25
29
|
gem 'minitest', '~> 5.0'
|
26
30
|
gem 'rack-test'
|
27
31
|
gem 'rubocop', '~> 1.32.0', require: false
|
@@ -42,15 +46,15 @@ gem 'kramdown'
|
|
42
46
|
gem 'liquid'
|
43
47
|
gem 'markaby'
|
44
48
|
gem 'nokogiri', '> 1.5.0'
|
49
|
+
gem 'ostruct'
|
45
50
|
gem 'pandoc-ruby', '~> 2.0.2'
|
46
51
|
gem 'rabl'
|
47
52
|
gem 'rdiscount', platforms: [:ruby]
|
48
53
|
gem 'rdoc'
|
49
54
|
gem 'redcarpet', platforms: [:ruby]
|
50
55
|
gem 'simplecov', require: false
|
51
|
-
gem 'slim', '~>
|
56
|
+
gem 'slim', '~> 5'
|
52
57
|
gem 'yajl-ruby', platforms: [:ruby]
|
53
|
-
gem 'zeitwerk'
|
54
58
|
|
55
59
|
# sass-embedded depends on google-protobuf
|
56
60
|
# which fails to be installed on JRuby and TruffleRuby under aarch64
|
data/README.md
CHANGED
@@ -15,11 +15,10 @@ get '/' do
|
|
15
15
|
end
|
16
16
|
```
|
17
17
|
|
18
|
-
Install the
|
18
|
+
Install the gems needed:
|
19
19
|
|
20
20
|
```shell
|
21
|
-
gem install sinatra
|
22
|
-
gem install puma # or any other server
|
21
|
+
gem install sinatra rackup puma
|
23
22
|
```
|
24
23
|
|
25
24
|
And run with:
|
@@ -1993,6 +1992,31 @@ set :protection, :session => true
|
|
1993
1992
|
<tt>"development"</tt> if not available.
|
1994
1993
|
</dd>
|
1995
1994
|
|
1995
|
+
<dt>host_authorization</dt>
|
1996
|
+
<dd>
|
1997
|
+
You can pass a hash of options to <tt>host_authorization</tt>,
|
1998
|
+
to be used by the <tt>Rack::Protection::HostAuthorization</tt> middleware.
|
1999
|
+
<dd>
|
2000
|
+
<dd>
|
2001
|
+
The middleware can block requests with unrecognized hostnames, to prevent DNS rebinding
|
2002
|
+
and other host header attacks. It checks the <tt>Host</tt>, <tt>X-Forwarded-Host</tt>
|
2003
|
+
and <tt>Forwarded</tt> headers.
|
2004
|
+
</dd>
|
2005
|
+
<dd>
|
2006
|
+
Useful options are:
|
2007
|
+
<ul>
|
2008
|
+
<li><tt>permitted_hosts</tt> – an array of hostnames (and <tt>IPAddr</tt> objects) your app recognizes
|
2009
|
+
<ul>
|
2010
|
+
<li>in the <tt>development</tt> environment, it is set to <tt>.localhost</tt>, <tt>.test</tt> and any IPv4/IPv6 address</li>
|
2011
|
+
<li>if empty, any hostname is permitted (the default for any other environment)</li>
|
2012
|
+
</ul>
|
2013
|
+
</li>
|
2014
|
+
<li><tt>status</tt> – the HTTP status code used in the response when a request is blocked (defaults to <tt>403</tt>)</li>
|
2015
|
+
<li><tt>message</tt> – the body used in the response when a request is blocked (defaults to <tt>Host not permitted</tt>)</li>
|
2016
|
+
<li><tt>allow_if</tt> – supply a <tt>Proc</tt> to use custom allow/deny logic, the proc is passed the request environment</li>
|
2017
|
+
</ul>
|
2018
|
+
</dd>
|
2019
|
+
|
1996
2020
|
<dt>logging</dt>
|
1997
2021
|
<dd>Use the logger.</dd>
|
1998
2022
|
|
@@ -2086,12 +2110,8 @@ set :protection, :session => true
|
|
2086
2110
|
|
2087
2111
|
<dt>server_settings</dt>
|
2088
2112
|
<dd>
|
2089
|
-
|
2090
|
-
|
2091
|
-
such as <tt>SSLEnable</tt> or <tt>SSLVerifyClient</tt>. However, web
|
2092
|
-
servers such as Puma do not support this, so you can set
|
2093
|
-
<tt>server_settings</tt> by defining it as a method when you call
|
2094
|
-
<tt>configure</tt>.
|
2113
|
+
You can pass a hash of options to <tt>server_settings</tt>,
|
2114
|
+
such as <tt>Host</tt> or <tt>Port</tt>.
|
2095
2115
|
</dd>
|
2096
2116
|
|
2097
2117
|
<dt>sessions</dt>
|
@@ -2812,7 +2832,7 @@ _Paraphrasing from
|
|
2812
2832
|
by Konstantin_
|
2813
2833
|
|
2814
2834
|
Sinatra doesn't impose any concurrency model but leaves that to the
|
2815
|
-
underlying Rack handler (server) like Puma or
|
2835
|
+
underlying Rack handler (server) like Puma or Falcon. Sinatra
|
2816
2836
|
itself is thread-safe, so there won't be any problem if the Rack handler
|
2817
2837
|
uses a threaded model of concurrency.
|
2818
2838
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
4.
|
1
|
+
4.1.0
|
data/lib/sinatra/base.rb
CHANGED
@@ -14,6 +14,7 @@ require 'mustermann/sinatra'
|
|
14
14
|
require 'mustermann/regular'
|
15
15
|
|
16
16
|
# stdlib dependencies
|
17
|
+
require 'ipaddr'
|
17
18
|
require 'time'
|
18
19
|
require 'uri'
|
19
20
|
|
@@ -22,6 +23,8 @@ require 'sinatra/indifferent_hash'
|
|
22
23
|
require 'sinatra/show_exceptions'
|
23
24
|
require 'sinatra/version'
|
24
25
|
|
26
|
+
require_relative 'middleware/logger'
|
27
|
+
|
25
28
|
module Sinatra
|
26
29
|
# The request object. See Rack::Request for more info:
|
27
30
|
# https://rubydoc.info/github/rack/rack/main/Rack/Request
|
@@ -61,7 +64,7 @@ module Sinatra
|
|
61
64
|
alias secure? ssl?
|
62
65
|
|
63
66
|
def forwarded?
|
64
|
-
|
67
|
+
!forwarded_authority.nil?
|
65
68
|
end
|
66
69
|
|
67
70
|
def safe?
|
@@ -294,7 +297,7 @@ module Sinatra
|
|
294
297
|
def block.each; yield(call) end
|
295
298
|
response.body = block
|
296
299
|
elsif value
|
297
|
-
unless request.head? || value.is_a?(Rack::Files::
|
300
|
+
unless request.head? || value.is_a?(Rack::Files::BaseIterator) || value.is_a?(Stream)
|
298
301
|
headers.delete 'content-length'
|
299
302
|
end
|
300
303
|
response.body = value
|
@@ -972,7 +975,7 @@ module Sinatra
|
|
972
975
|
include Helpers
|
973
976
|
include Templates
|
974
977
|
|
975
|
-
URI_INSTANCE = URI::
|
978
|
+
URI_INSTANCE = defined?(URI::RFC2396_PARSER) ? URI::RFC2396_PARSER : URI::RFC2396_Parser.new
|
976
979
|
|
977
980
|
attr_accessor :app, :env, :request, :response, :params
|
978
981
|
attr_reader :template_cache
|
@@ -1292,7 +1295,7 @@ module Sinatra
|
|
1292
1295
|
/active_support/, # active_support require hacks
|
1293
1296
|
%r{bundler(/(?:runtime|inline))?\.rb}, # bundler require hacks
|
1294
1297
|
/<internal:/, # internal in ruby >= 1.9.2
|
1295
|
-
%r{zeitwerk/kernel\.rb}
|
1298
|
+
%r{zeitwerk/(core_ext/)?kernel\.rb} # Zeitwerk kernel#require decorator
|
1296
1299
|
].freeze
|
1297
1300
|
|
1298
1301
|
attr_reader :routes, :filters, :templates, :errors, :on_start_callback, :on_stop_callback
|
@@ -1598,20 +1601,20 @@ module Sinatra
|
|
1598
1601
|
alias stop! quit!
|
1599
1602
|
|
1600
1603
|
# Run the Sinatra app as a self-hosted server using
|
1601
|
-
# Puma, Falcon
|
1604
|
+
# Puma, Falcon (in that order). If given a block, will call
|
1602
1605
|
# with the constructed handler once we have taken the stage.
|
1603
1606
|
def run!(options = {}, &block)
|
1604
1607
|
unless defined?(Rackup::Handler)
|
1605
1608
|
rackup_warning = <<~MISSING_RACKUP
|
1606
|
-
Sinatra could not start, the
|
1609
|
+
Sinatra could not start, the required gems weren't found!
|
1607
1610
|
|
1608
|
-
Add
|
1611
|
+
Add them to your bundle with:
|
1609
1612
|
|
1610
|
-
bundle add rackup
|
1613
|
+
bundle add rackup puma
|
1611
1614
|
|
1612
|
-
or install
|
1615
|
+
or install them with:
|
1613
1616
|
|
1614
|
-
gem install rackup
|
1617
|
+
gem install rackup puma
|
1615
1618
|
|
1616
1619
|
MISSING_RACKUP
|
1617
1620
|
warn rackup_warning
|
@@ -1819,6 +1822,7 @@ module Sinatra
|
|
1819
1822
|
setup_logging builder
|
1820
1823
|
setup_sessions builder
|
1821
1824
|
setup_protection builder
|
1825
|
+
setup_host_authorization builder
|
1822
1826
|
end
|
1823
1827
|
|
1824
1828
|
def setup_middleware(builder)
|
@@ -1835,7 +1839,7 @@ module Sinatra
|
|
1835
1839
|
end
|
1836
1840
|
|
1837
1841
|
def setup_null_logger(builder)
|
1838
|
-
builder.use
|
1842
|
+
builder.use Sinatra::Middleware::Logger, ::Logger::FATAL
|
1839
1843
|
end
|
1840
1844
|
|
1841
1845
|
def setup_common_logger(builder)
|
@@ -1844,9 +1848,9 @@ module Sinatra
|
|
1844
1848
|
|
1845
1849
|
def setup_custom_logger(builder)
|
1846
1850
|
if logging.respond_to? :to_int
|
1847
|
-
builder.use
|
1851
|
+
builder.use Sinatra::Middleware::Logger, logging
|
1848
1852
|
else
|
1849
|
-
builder.use
|
1853
|
+
builder.use Sinatra::Middleware::Logger
|
1850
1854
|
end
|
1851
1855
|
end
|
1852
1856
|
|
@@ -1867,6 +1871,10 @@ module Sinatra
|
|
1867
1871
|
builder.use Rack::Protection, options
|
1868
1872
|
end
|
1869
1873
|
|
1874
|
+
def setup_host_authorization(builder)
|
1875
|
+
builder.use Rack::Protection::HostAuthorization, host_authorization
|
1876
|
+
end
|
1877
|
+
|
1870
1878
|
def setup_sessions(builder)
|
1871
1879
|
return unless sessions?
|
1872
1880
|
|
@@ -1961,10 +1969,25 @@ module Sinatra
|
|
1961
1969
|
set :running_server, nil
|
1962
1970
|
set :handler_name, nil
|
1963
1971
|
set :traps, true
|
1964
|
-
set :server, %w[
|
1972
|
+
set :server, %w[]
|
1965
1973
|
set :bind, proc { development? ? 'localhost' : '0.0.0.0' }
|
1966
1974
|
set :port, Integer(ENV['PORT'] && !ENV['PORT'].empty? ? ENV['PORT'] : 4567)
|
1967
1975
|
set :quiet, false
|
1976
|
+
set :host_authorization, ->() do
|
1977
|
+
if development?
|
1978
|
+
{
|
1979
|
+
permitted_hosts: [
|
1980
|
+
"localhost",
|
1981
|
+
".localhost",
|
1982
|
+
".test",
|
1983
|
+
IPAddr.new("0.0.0.0/0"),
|
1984
|
+
IPAddr.new("::/0"),
|
1985
|
+
]
|
1986
|
+
}
|
1987
|
+
else
|
1988
|
+
{}
|
1989
|
+
end
|
1990
|
+
end
|
1968
1991
|
|
1969
1992
|
ruby_engine = defined?(RUBY_ENGINE) && RUBY_ENGINE
|
1970
1993
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
module Sinatra
|
6
|
+
module Middleware
|
7
|
+
class Logger
|
8
|
+
def initialize(app, level = ::Logger::INFO)
|
9
|
+
@app, @level = app, level
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
logger = ::Logger.new(env[Rack::RACK_ERRORS])
|
14
|
+
logger.level = @level
|
15
|
+
|
16
|
+
env[Rack::RACK_LOGGER] = logger
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/sinatra/version.rb
CHANGED
data/sinatra.gemspec
CHANGED
@@ -45,9 +45,10 @@ RubyGems 2.0 or newer is required to protect against public gem pushes. You can
|
|
45
45
|
|
46
46
|
s.required_ruby_version = '>= 2.7.8'
|
47
47
|
|
48
|
+
s.add_dependency 'logger', '>= 1.6.0'
|
48
49
|
s.add_dependency 'mustermann', '~> 3.0'
|
49
50
|
s.add_dependency 'rack', '>= 3.0.0', '< 4'
|
50
|
-
s.add_dependency 'rack-session', '>= 2.0.0', '< 3'
|
51
51
|
s.add_dependency 'rack-protection', version
|
52
|
+
s.add_dependency 'rack-session', '>= 2.0.0', '< 3'
|
52
53
|
s.add_dependency 'tilt', '~> 2.0'
|
53
54
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blake Mizerany
|
@@ -11,8 +11,22 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2024-
|
14
|
+
date: 2024-11-18 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: logger
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.6.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.6.0
|
16
30
|
- !ruby/object:Gem::Dependency
|
17
31
|
name: mustermann
|
18
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -47,6 +61,20 @@ dependencies:
|
|
47
61
|
- - "<"
|
48
62
|
- !ruby/object:Gem::Version
|
49
63
|
version: '4'
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
name: rack-protection
|
66
|
+
requirement: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 4.1.0
|
71
|
+
type: :runtime
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 4.1.0
|
50
78
|
- !ruby/object:Gem::Dependency
|
51
79
|
name: rack-session
|
52
80
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,20 +95,6 @@ dependencies:
|
|
67
95
|
- - "<"
|
68
96
|
- !ruby/object:Gem::Version
|
69
97
|
version: '3'
|
70
|
-
- !ruby/object:Gem::Dependency
|
71
|
-
name: rack-protection
|
72
|
-
requirement: !ruby/object:Gem::Requirement
|
73
|
-
requirements:
|
74
|
-
- - '='
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: 4.0.0
|
77
|
-
type: :runtime
|
78
|
-
prerelease: false
|
79
|
-
version_requirements: !ruby/object:Gem::Requirement
|
80
|
-
requirements:
|
81
|
-
- - '='
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version: 4.0.0
|
84
98
|
- !ruby/object:Gem::Dependency
|
85
99
|
name: tilt
|
86
100
|
requirement: !ruby/object:Gem::Requirement
|
@@ -125,6 +139,7 @@ files:
|
|
125
139
|
- lib/sinatra/images/500.png
|
126
140
|
- lib/sinatra/indifferent_hash.rb
|
127
141
|
- lib/sinatra/main.rb
|
142
|
+
- lib/sinatra/middleware/logger.rb
|
128
143
|
- lib/sinatra/show_exceptions.rb
|
129
144
|
- lib/sinatra/version.rb
|
130
145
|
- sinatra.gemspec
|
@@ -159,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
174
|
- !ruby/object:Gem::Version
|
160
175
|
version: '0'
|
161
176
|
requirements: []
|
162
|
-
rubygems_version: 3.5.
|
177
|
+
rubygems_version: 3.5.22
|
163
178
|
signing_key:
|
164
179
|
specification_version: 4
|
165
180
|
summary: Classy web-development dressed in a DSL
|