homura-runtime 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -0
  3. data/exe/compile-assets +2 -2
  4. data/exe/compile-erb +5 -7
  5. data/lib/homura/runtime/build_support.rb +19 -2
  6. data/lib/homura/runtime/version.rb +1 -1
  7. data/vendor/rack/auth/abstract/handler.rb +41 -0
  8. data/vendor/rack/auth/abstract/request.rb +51 -0
  9. data/vendor/rack/auth/basic.rb +58 -0
  10. data/vendor/rack/bad_request.rb +8 -0
  11. data/vendor/rack/body_proxy.rb +63 -0
  12. data/vendor/rack/builder.rb +315 -0
  13. data/vendor/rack/cascade.rb +67 -0
  14. data/vendor/rack/common_logger.rb +94 -0
  15. data/vendor/rack/conditional_get.rb +87 -0
  16. data/vendor/rack/config.rb +22 -0
  17. data/vendor/rack/constants.rb +68 -0
  18. data/vendor/rack/content_length.rb +34 -0
  19. data/vendor/rack/content_type.rb +33 -0
  20. data/vendor/rack/deflater.rb +159 -0
  21. data/vendor/rack/directory.rb +210 -0
  22. data/vendor/rack/etag.rb +71 -0
  23. data/vendor/rack/events.rb +172 -0
  24. data/vendor/rack/files.rb +224 -0
  25. data/vendor/rack/head.rb +25 -0
  26. data/vendor/rack/headers.rb +238 -0
  27. data/vendor/rack/lint.rb +1000 -0
  28. data/vendor/rack/lock.rb +29 -0
  29. data/vendor/rack/media_type.rb +42 -0
  30. data/vendor/rack/method_override.rb +56 -0
  31. data/vendor/rack/mime.rb +694 -0
  32. data/vendor/rack/mock.rb +3 -0
  33. data/vendor/rack/mock_request.rb +161 -0
  34. data/vendor/rack/mock_response.rb +147 -0
  35. data/vendor/rack/multipart/generator.rb +99 -0
  36. data/vendor/rack/multipart/parser.rb +586 -0
  37. data/vendor/rack/multipart/uploaded_file.rb +82 -0
  38. data/vendor/rack/multipart.rb +77 -0
  39. data/vendor/rack/null_logger.rb +48 -0
  40. data/vendor/rack/protection/authenticity_token.rb +256 -0
  41. data/vendor/rack/protection/base.rb +140 -0
  42. data/vendor/rack/protection/content_security_policy.rb +80 -0
  43. data/vendor/rack/protection/cookie_tossing.rb +77 -0
  44. data/vendor/rack/protection/escaped_params.rb +93 -0
  45. data/vendor/rack/protection/form_token.rb +25 -0
  46. data/vendor/rack/protection/frame_options.rb +39 -0
  47. data/vendor/rack/protection/http_origin.rb +43 -0
  48. data/vendor/rack/protection/ip_spoofing.rb +27 -0
  49. data/vendor/rack/protection/json_csrf.rb +60 -0
  50. data/vendor/rack/protection/path_traversal.rb +45 -0
  51. data/vendor/rack/protection/referrer_policy.rb +27 -0
  52. data/vendor/rack/protection/remote_referrer.rb +22 -0
  53. data/vendor/rack/protection/remote_token.rb +24 -0
  54. data/vendor/rack/protection/session_hijacking.rb +37 -0
  55. data/vendor/rack/protection/strict_transport.rb +41 -0
  56. data/vendor/rack/protection/version.rb +7 -0
  57. data/vendor/rack/protection/xss_header.rb +27 -0
  58. data/vendor/rack/protection.rb +58 -0
  59. data/vendor/rack/query_parser.rb +261 -0
  60. data/vendor/rack/recursive.rb +66 -0
  61. data/vendor/rack/reloader.rb +112 -0
  62. data/vendor/rack/request.rb +818 -0
  63. data/vendor/rack/response.rb +403 -0
  64. data/vendor/rack/rewindable_input.rb +116 -0
  65. data/vendor/rack/runtime.rb +35 -0
  66. data/vendor/rack/sendfile.rb +197 -0
  67. data/vendor/rack/session/abstract/id.rb +533 -0
  68. data/vendor/rack/session/constants.rb +13 -0
  69. data/vendor/rack/session/cookie.rb +292 -0
  70. data/vendor/rack/session/encryptor.rb +415 -0
  71. data/vendor/rack/session/pool.rb +76 -0
  72. data/vendor/rack/session/version.rb +10 -0
  73. data/vendor/rack/session.rb +12 -0
  74. data/vendor/rack/show_exceptions.rb +433 -0
  75. data/vendor/rack/show_status.rb +121 -0
  76. data/vendor/rack/static.rb +188 -0
  77. data/vendor/rack/tempfile_reaper.rb +44 -0
  78. data/vendor/rack/urlmap.rb +99 -0
  79. data/vendor/rack/utils.rb +631 -0
  80. data/vendor/rack/version.rb +17 -0
  81. data/vendor/rack.rb +66 -0
  82. metadata +76 -1
@@ -0,0 +1,197 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'constants'
4
+ require_relative 'utils'
5
+ require_relative 'body_proxy'
6
+
7
+ module Rack
8
+
9
+ # = Sendfile
10
+ #
11
+ # The Sendfile middleware intercepts responses whose body is being
12
+ # served from a file and replaces it with a server specific x-sendfile
13
+ # header. The web server is then responsible for writing the file contents
14
+ # to the client. This can dramatically reduce the amount of work required
15
+ # by the Ruby backend and takes advantage of the web server's optimized file
16
+ # delivery code.
17
+ #
18
+ # In order to take advantage of this middleware, the response body must
19
+ # respond to +to_path+ and the request must include an `x-sendfile-type`
20
+ # header. Rack::Files and other components implement +to_path+ so there's
21
+ # rarely anything you need to do in your application. The `x-sendfile-type`
22
+ # header is typically set in your web servers configuration. The following
23
+ # sections attempt to document
24
+ #
25
+ # === Nginx
26
+ #
27
+ # Nginx supports the `x-accel-redirect` header. This is similar to `x-sendfile`
28
+ # but requires parts of the filesystem to be mapped into a private URL
29
+ # hierarchy.
30
+ #
31
+ # The following example shows the Nginx configuration required to create
32
+ # a private "/files/" area, enable `x-accel-redirect`, and pass the special
33
+ # `x-accel-mapping` header to the backend:
34
+ #
35
+ # location ~ /files/(.*) {
36
+ # internal;
37
+ # alias /var/www/$1;
38
+ # }
39
+ #
40
+ # location / {
41
+ # proxy_redirect off;
42
+ #
43
+ # proxy_set_header Host $host;
44
+ # proxy_set_header X-Real-IP $remote_addr;
45
+ # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
46
+ #
47
+ # proxy_set_header x-accel-mapping /var/www/=/files/;
48
+ #
49
+ # proxy_pass http://127.0.0.1:8080/;
50
+ # }
51
+ #
52
+ # The `x-accel-mapping` header should specify the location on the file system,
53
+ # followed by an equals sign (=), followed name of the private URL pattern
54
+ # that it maps to. The middleware performs a simple substitution on the
55
+ # resulting path.
56
+ #
57
+ # To enable `x-accel-redirect`, you must configure the middleware explicitly:
58
+ #
59
+ # use Rack::Sendfile, "x-accel-redirect"
60
+ #
61
+ # For security reasons, the `x-sendfile-type` header from requests is ignored.
62
+ # The sendfile variation must be set via the middleware constructor.
63
+ #
64
+ # See Also: https://www.nginx.com/resources/wiki/start/topics/examples/xsendfile
65
+ #
66
+ # === lighttpd
67
+ #
68
+ # Lighttpd has supported some variation of the `x-sendfile` header for some
69
+ # time, although only recent version support `x-sendfile` in a reverse proxy
70
+ # configuration.
71
+ #
72
+ # $HTTP["host"] == "example.com" {
73
+ # proxy-core.protocol = "http"
74
+ # proxy-core.balancer = "round-robin"
75
+ # proxy-core.backends = (
76
+ # "127.0.0.1:8000",
77
+ # "127.0.0.1:8001",
78
+ # ...
79
+ # )
80
+ #
81
+ # proxy-core.allow-x-sendfile = "enable"
82
+ # proxy-core.rewrite-request = (
83
+ # "x-sendfile-type" => (".*" => "x-sendfile")
84
+ # )
85
+ # }
86
+ #
87
+ # See Also: http://redmine.lighttpd.net/wiki/lighttpd/Docs:ModProxyCore
88
+ #
89
+ # === Apache
90
+ #
91
+ # `x-sendfile` is supported under Apache 2.x using a separate module:
92
+ #
93
+ # https://tn123.org/mod_xsendfile/
94
+ #
95
+ # Once the module is compiled and installed, you can enable it using
96
+ # XSendFile config directive:
97
+ #
98
+ # RequestHeader Set x-sendfile-type x-sendfile
99
+ # ProxyPassReverse / http://localhost:8001/
100
+ # XSendFile on
101
+ #
102
+ # === Mapping parameter
103
+ #
104
+ # The third parameter allows for an overriding extension of the
105
+ # `x-accel-mapping` header. Mappings should be provided in tuples of internal to
106
+ # external. The internal values may contain regular expression syntax, they
107
+ # will be matched with case indifference.
108
+ #
109
+ # When `x-accel-redirect` is explicitly enabled via the variation parameter,
110
+ # and no application-level mappings are provided, the middleware will read
111
+ # the `x-accel-mapping` header from the proxy. This allows nginx to control
112
+ # the path mapping without requiring application-level configuration.
113
+ #
114
+ # === Security
115
+ #
116
+ # For security reasons, the `x-sendfile-type` header from HTTP requests is
117
+ # ignored. The sendfile variation must be explicitly configured via the
118
+ # middleware constructor to prevent information disclosure vulnerabilities
119
+ # where attackers could bypass proxy restrictions.
120
+
121
+ class Sendfile
122
+ def initialize(app, variation = nil, mappings = [])
123
+ @app = app
124
+ @variation = variation
125
+ @mappings = mappings.map do |internal, external|
126
+ [/\A#{internal}/i, external]
127
+ end
128
+ end
129
+
130
+ def call(env)
131
+ _, headers, body = response = @app.call(env)
132
+
133
+ if body.respond_to?(:to_path)
134
+ case type = variation(env)
135
+ when /x-accel-redirect/i
136
+ path = ::File.expand_path(body.to_path)
137
+ if url = map_accel_path(env, path)
138
+ headers[CONTENT_LENGTH] = '0'
139
+ # '?' must be percent-encoded because it is not query string but a part of path
140
+ headers[type.downcase] = ::Rack::Utils.escape_path(url).gsub('?', '%3F')
141
+ obody = body
142
+ response[2] = Rack::BodyProxy.new([]) do
143
+ obody.close if obody.respond_to?(:close)
144
+ end
145
+ else
146
+ env[RACK_ERRORS].puts "x-accel-mapping header missing"
147
+ end
148
+ when /x-sendfile|x-lighttpd-send-file/i
149
+ path = ::File.expand_path(body.to_path)
150
+ headers[CONTENT_LENGTH] = '0'
151
+ headers[type.downcase] = path
152
+ obody = body
153
+ response[2] = Rack::BodyProxy.new([]) do
154
+ obody.close if obody.respond_to?(:close)
155
+ end
156
+ when '', nil
157
+ else
158
+ env[RACK_ERRORS].puts "Unknown x-sendfile variation: #{type.inspect}"
159
+ end
160
+ end
161
+ response
162
+ end
163
+
164
+ private
165
+
166
+ def variation(env)
167
+ # Note: HTTP_X_SENDFILE_TYPE is intentionally NOT read for security reasons.
168
+ # Attackers could use this header to enable x-accel-redirect and bypass proxy restrictions.
169
+ @variation || env['sendfile.type']
170
+ end
171
+
172
+ def x_accel_mapping(env)
173
+ # Only allow header when:
174
+ # 1. `x-accel-redirect` is explicitly enabled via constructor.
175
+ # 2. No application-level mappings are configured.
176
+ return nil unless @variation =~ /x-accel-redirect/i
177
+ return nil if @mappings.any?
178
+
179
+ env['HTTP_X_ACCEL_MAPPING']
180
+ end
181
+
182
+ def map_accel_path(env, path)
183
+ if mapping = @mappings.find { |internal, _| internal =~ path }
184
+ return path.sub(*mapping)
185
+ elsif mapping = x_accel_mapping(env)
186
+ # Safe to use header: explicit config + no app mappings:
187
+ mapping.split(',').map(&:strip).each do |m|
188
+ internal, external = m.split('=', 2).map(&:strip)
189
+ new_path = path.sub(/\A#{internal}/i, external)
190
+ return new_path unless path == new_path
191
+ end
192
+
193
+ return path
194
+ end
195
+ end
196
+ end
197
+ end