sinatra 4.0.0 → 4.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71d0bb379c736d6c251ceb424cac84dbe3a8b22d80a54473a0af1085b93b7dbf
4
- data.tar.gz: 489d48a5e4f934127e04cdafa2d0d582c5143cc2a8f476239ea5b5b0f0e492c9
3
+ metadata.gz: 491154a9e29e4c218d9245fd73024818e7dfa6c75ba1d74220e46498841bb54e
4
+ data.tar.gz: 42259b9becde7268d9b95abc783d896c864a6c84b3e1dd6d40d7f351a350f626
5
5
  SHA512:
6
- metadata.gz: fbe92c1867d3ebe8ddc3f707c4e9f9cf2b68bddf2556164b85083ac635650725d63f8c847b4c70d0ad2abf6793b5f1054918b0b7c4e04d303119867be84c3253
7
- data.tar.gz: 0727d88e9f5574c304dd3f31c6107a2b3e1cde96914e258c86fee529a1e922b0ff1d023f109fcc3b232f010ae21d9bdb4c365001dc7c3f658c0bd75b95e8d24d
6
+ metadata.gz: 43a69c7f07afab191eacc80d7837d9bdbd81701a51973309395b47e9efacb010234a0a66e27503b6edc213f5f8321e426f2f8ad9f7cc7e247e908613d14081c6
7
+ data.tar.gz: f2fb4deeb5f8e44a5a6a59663080f143c2a1dac1d21a5ca8301728b265a8ba2fcf3e0815c692af0791230289d4ddaf548a317e2f4295cf24b45e5cdec47dc86e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ ## 4.1.1 / 2024-11-20
2
+
3
+ * Fix: Restore WEBrick support ([#2067](https://github.com/sinatra/sinatra/pull/2067))
4
+
5
+ ## 4.1.0 / 2024-11-18
6
+
7
+ * New: Add `host_authorization` setting ([#2053](https://github.com/sinatra/sinatra/pull/2053))
8
+ * Defaults to `.localhost`, `.test` and any IP address in development mode.
9
+ * Security: addresses [CVE-2024-21510](https://github.com/advisories/GHSA-hxx2-7vcw-mqr3).
10
+ * Fix: Return an instance of `Sinatra::IndifferentHash` when calling `#except` ([#2044](https://github.com/sinatra/sinatra/pull/2044))
11
+ * Fix: Address warning from `URI` for Ruby 3.4 ([#2060](https://github.com/sinatra/sinatra/pull/2060))
12
+ * Fix: `rackup` no longer depends on WEBrick, recommend Puma instead ([`4a558503`](https://github.com/sinatra/sinatra/commit/4a558503a0ee41f26d4ebc07b478340e8a8a5ed6))
13
+ * Fix: Zeitwerk 2.7.0+ compatibility ([#2050](https://github.com/sinatra/sinatra/pull/2050))
14
+ * Fix: Address warning about Hash construction for Ruby 3.4 ([#2028](https://github.com/sinatra/sinatra/pull/2028))
15
+ * Fix: Declare missing dependencies for Ruby 3.5 ([#2032](https://github.com/sinatra/sinatra/pull/2032))
16
+ * Fix: Compatibility with `--enable-frozen-string-literal` ([#2033](https://github.com/sinatra/sinatra/pull/2033))
17
+ * Fix: Rack 3.1 compatibility ([#2035](https://github.com/sinatra/sinatra/pull/2035))
18
+ * Don't depend on `Rack::Logger`
19
+ * Don't delete `content-length` header when `Rack::Files` is used
20
+
1
21
  ## 4.0.0. / 2024-01-19
2
22
 
3
23
  * New: Add support for Rack 3 ([#1857])
@@ -243,7 +263,7 @@
243
263
 
244
264
  * 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
265
 
246
- * Add QuietLogger that excludes pathes from Rack::CommonLogger [1250](https://github.com/sinatra/sinatra/pull/1250) by Christoph Wagner
266
+ * Add QuietLogger that excludes paths from Rack::CommonLogger [1250](https://github.com/sinatra/sinatra/pull/1250) by Christoph Wagner
247
267
 
248
268
  * 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
269
 
@@ -1609,7 +1629,7 @@ the 1.0 release:
1609
1629
  Hash structure. e.g., "post[title]=Hello&post[body]=World" yields
1610
1630
  params: {'post' => {'title' => 'Hello', 'body' => 'World'}}.
1611
1631
 
1612
- * Regular expressions may now be used in route pattens; captures are
1632
+ * Regular expressions may now be used in route patterns; captures are
1613
1633
  available at "params[:captures]".
1614
1634
 
1615
1635
  * 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,16 @@ 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', '~> 4'
56
+ gem 'slim', '~> 5'
52
57
  gem 'yajl-ruby', platforms: [:ruby]
53
- gem 'zeitwerk'
58
+ gem 'webrick'
54
59
 
55
60
  # sass-embedded depends on google-protobuf
56
61
  # 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 gem:
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,33 @@ 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
+ <p>
1998
+ You can pass a hash of options to <tt>host_authorization</tt>,
1999
+ to be used by the <tt>Rack::Protection::HostAuthorization</tt> middleware.
2000
+ </p>
2001
+ <p>
2002
+ The middleware can block requests with unrecognized hostnames, to prevent DNS rebinding
2003
+ and other host header attacks. It checks the <tt>Host</tt>, <tt>X-Forwarded-Host</tt>
2004
+ and <tt>Forwarded</tt> headers.
2005
+ </p>
2006
+ <p>
2007
+ Useful options are:
2008
+ <ul>
2009
+ <li><tt>permitted_hosts</tt> – an array of hostnames (and <tt>IPAddr</tt> objects) your app recognizes
2010
+ <ul>
2011
+ <li>in the <tt>development</tt> environment, it is set to <tt>.localhost</tt>, <tt>.test</tt> and any IPv4/IPv6 address</li>
2012
+ <li>if empty, any hostname is permitted (the default for any other environment)</li>
2013
+ </ul>
2014
+ </li>
2015
+ <li><tt>status</tt> – the HTTP status code used in the response when a request is blocked (defaults to <tt>403</tt>)</li>
2016
+ <li><tt>message</tt> – the body used in the response when a request is blocked (defaults to <tt>Host not permitted</tt>)</li>
2017
+ <li><tt>allow_if</tt> – supply a <tt>Proc</tt> to use custom allow/deny logic, the proc is passed the request environment</li>
2018
+ </ul>
2019
+ </p>
2020
+ </dd>
2021
+
1996
2022
  <dt>logging</dt>
1997
2023
  <dd>Use the logger.</dd>
1998
2024
 
@@ -2086,12 +2112,8 @@ set :protection, :session => true
2086
2112
 
2087
2113
  <dt>server_settings</dt>
2088
2114
  <dd>
2089
- If you are using a WEBrick web server, presumably for your development
2090
- environment, you can pass a hash of options to <tt>server_settings</tt>,
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>.
2115
+ You can pass a hash of options to <tt>server_settings</tt>,
2116
+ such as <tt>Host</tt> or <tt>Port</tt>.
2095
2117
  </dd>
2096
2118
 
2097
2119
  <dt>sessions</dt>
@@ -2812,7 +2834,7 @@ _Paraphrasing from
2812
2834
  by Konstantin_
2813
2835
 
2814
2836
  Sinatra doesn't impose any concurrency model but leaves that to the
2815
- underlying Rack handler (server) like Puma or WEBrick. Sinatra
2837
+ underlying Rack handler (server) like Puma or Falcon. Sinatra
2816
2838
  itself is thread-safe, so there won't be any problem if the Rack handler
2817
2839
  uses a threaded model of concurrency.
2818
2840
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.0.0
1
+ 4.1.1
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
- @env.include? 'HTTP_X_FORWARDED_HOST'
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::Iterator) || value.is_a?(Stream)
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::Parser.new
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} # Zeitwerk kernel#require decorator
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, or WEBrick (in that order). If given a block, will call
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 "rackup" gem was not found!
1609
+ Sinatra could not start, the required gems weren't found!
1607
1610
 
1608
- Add it to your bundle with:
1611
+ Add them to your bundle with:
1609
1612
 
1610
- bundle add rackup
1613
+ bundle add rackup puma
1611
1614
 
1612
- or install it with:
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 Rack::NullLogger
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 Rack::Logger, logging
1851
+ builder.use Sinatra::Middleware::Logger, logging
1848
1852
  else
1849
- builder.use Rack::Logger
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[HTTP webrick]
1972
+ set :server, %w[webrick]
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
 
@@ -185,7 +185,7 @@ module Sinatra
185
185
  def except(*keys)
186
186
  keys.map!(&method(:convert_key))
187
187
 
188
- super(*keys)
188
+ self.class[super(*keys)]
189
189
  end if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.0")
190
190
 
191
191
  private
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sinatra
4
- VERSION = '4.0.0'
4
+ VERSION = '4.1.1'
5
5
  end
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.0.0
4
+ version: 4.1.1
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-01-19 00:00:00.000000000 Z
14
+ date: 2024-11-20 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.1
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.1
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.3
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