Skip to content

Commit bc47815

Browse files
committed
Privatize unneededly protected methods in Action Pack
1 parent 589da3c commit bc47815

File tree

15 files changed

+82
-83
lines changed

15 files changed

+82
-83
lines changed

actionpack/lib/abstract_controller/caching.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ def view_cache_dependencies
5252
self.class._view_cache_dependencies.map { |dep| instance_exec(&dep) }.compact
5353
end
5454

55-
protected
55+
private
5656
# Convenience accessor.
57-
def cache(key, options = {}, &block)
57+
def cache(key, options = {}, &block) # :doc:
5858
if cache_configured?
5959
cache_store.fetch(ActiveSupport::Cache.expand_cache_key(key, :controller), options, &block)
6060
else

actionpack/lib/abstract_controller/collector.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def #{sym}(*args, &block)
1919
generate_method_for_mime(mime) unless instance_methods.include?(mime.to_sym)
2020
end
2121

22-
protected
22+
private
2323

2424
def method_missing(symbol, &block)
2525
unless mime_constant = Mime[symbol]

actionpack/lib/action_controller/metal/data_streaming.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module DataStreaming
1111
DEFAULT_SEND_FILE_TYPE = "application/octet-stream".freeze #:nodoc:
1212
DEFAULT_SEND_FILE_DISPOSITION = "attachment".freeze #:nodoc:
1313

14-
protected
14+
private
1515
# Sends the file. This uses a server-appropriate method (such as X-Sendfile)
1616
# via the Rack::Sendfile middleware. The header to use is set via
1717
# +config.action_dispatch.x_sendfile_header+.
@@ -108,7 +108,6 @@ def send_data(data, options = {}) #:doc:
108108
render options.slice(:status, :content_type).merge(body: data)
109109
end
110110

111-
private
112111
def send_file_headers!(options)
113112
type_provided = options.has_key?(:type)
114113

actionpack/lib/action_controller/metal/flash.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def add_flash_types(*types)
4242
end
4343
end
4444

45-
protected
45+
private
4646
def redirect_to(options = {}, response_status_and_flash = {}) #:doc:
4747
self.class._flash_types.each do |flash_type|
4848
if type = response_status_and_flash.delete(flash_type)

actionpack/lib/action_controller/metal/http_authentication.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module HttpAuthentication
2828
# class ApplicationController < ActionController::Base
2929
# before_action :set_account, :authenticate
3030
#
31-
# protected
31+
# private
3232
# def set_account
3333
# @account = Account.find_by(url_name: request.subdomains.first)
3434
# end
@@ -363,7 +363,7 @@ def opaque(secret_key)
363363
# class ApplicationController < ActionController::Base
364364
# before_action :set_account, :authenticate
365365
#
366-
# protected
366+
# private
367367
# def set_account
368368
# @account = Account.find_by(url_name: request.subdomains.first)
369369
# end

actionpack/lib/action_controller/metal/request_forgery_protection.rb

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def handle_unverified_request
152152
request.cookie_jar = NullCookieJar.build(request, {})
153153
end
154154

155-
protected
155+
private
156156

157157
class NullSessionHash < Rack::Session::Abstract::SessionHash #:nodoc:
158158
def initialize(req)
@@ -197,7 +197,7 @@ def handle_unverified_request
197197
end
198198
end
199199

200-
protected
200+
private
201201
# The actual before_action that is used to verify the CSRF token.
202202
# Don't override this directly. Provide your own forgery protection
203203
# strategy instead. If you override, you'll disable same-origin
@@ -208,7 +208,7 @@ def handle_unverified_request
208208
# enabled on an action, this before_action flags its after_action to
209209
# verify that JavaScript responses are for XHR requests, ensuring they
210210
# follow the browser's same-origin policy.
211-
def verify_authenticity_token
211+
def verify_authenticity_token # :doc:
212212
mark_for_same_origin_verification!
213213

214214
if !verified_request?
@@ -219,7 +219,7 @@ def verify_authenticity_token
219219
end
220220
end
221221

222-
def handle_unverified_request
222+
def handle_unverified_request # :doc:
223223
forgery_protection_strategy.new(self).handle_unverified_request
224224
end
225225

@@ -233,7 +233,7 @@ def handle_unverified_request
233233
# If `verify_authenticity_token` was run (indicating that we have
234234
# forgery protection enabled for this request) then also verify that
235235
# we aren't serving an unauthorized cross-origin response.
236-
def verify_same_origin_request
236+
def verify_same_origin_request # :doc:
237237
if marked_for_same_origin_verification? && non_xhr_javascript_response?
238238
if logger && log_warning_on_csrf_failure
239239
logger.warn CROSS_ORIGIN_JAVASCRIPT_WARNING
@@ -243,18 +243,18 @@ def verify_same_origin_request
243243
end
244244

245245
# GET requests are checked for cross-origin JavaScript after rendering.
246-
def mark_for_same_origin_verification!
246+
def mark_for_same_origin_verification! # :doc:
247247
@marked_for_same_origin_verification = request.get?
248248
end
249249

250250
# If the `verify_authenticity_token` before_action ran, verify that
251251
# JavaScript responses are only served to same-origin GET requests.
252-
def marked_for_same_origin_verification?
252+
def marked_for_same_origin_verification? # :doc:
253253
@marked_for_same_origin_verification ||= false
254254
end
255255

256256
# Check for cross-origin JavaScript responses.
257-
def non_xhr_javascript_response?
257+
def non_xhr_javascript_response? # :doc:
258258
content_type =~ %r(\Atext/javascript) && !request.xhr?
259259
end
260260

@@ -265,20 +265,20 @@ def non_xhr_javascript_response?
265265
# * Is it a GET or HEAD request? Gets should be safe and idempotent
266266
# * Does the form_authenticity_token match the given token value from the params?
267267
# * Does the X-CSRF-Token header match the form_authenticity_token
268-
def verified_request?
268+
def verified_request? # :doc:
269269
!protect_against_forgery? || request.get? || request.head? ||
270270
(valid_request_origin? && any_authenticity_token_valid?)
271271
end
272272

273273
# Checks if any of the authenticity tokens from the request are valid.
274-
def any_authenticity_token_valid?
274+
def any_authenticity_token_valid? # :doc:
275275
request_authenticity_tokens.any? do |token|
276276
valid_authenticity_token?(session, token)
277277
end
278278
end
279279

280280
# Possible authenticity tokens sent in the request.
281-
def request_authenticity_tokens
281+
def request_authenticity_tokens # :doc:
282282
[form_authenticity_param, request.x_csrf_token]
283283
end
284284

@@ -290,7 +290,7 @@ def form_authenticity_token(form_options: {})
290290
# Creates a masked version of the authenticity token that varies
291291
# on each request. The masking is used to mitigate SSL attacks
292292
# like BREACH.
293-
def masked_authenticity_token(session, form_options: {})
293+
def masked_authenticity_token(session, form_options: {}) # :doc:
294294
action, method = form_options.values_at(:action, :method)
295295

296296
raw_token = if per_form_csrf_tokens && action && method
@@ -309,7 +309,7 @@ def masked_authenticity_token(session, form_options: {})
309309
# Checks the client's masked token to see if it matches the
310310
# session token. Essentially the inverse of
311311
# +masked_authenticity_token+.
312-
def valid_authenticity_token?(session, encoded_masked_token)
312+
def valid_authenticity_token?(session, encoded_masked_token) # :doc:
313313
if encoded_masked_token.nil? || encoded_masked_token.empty? || !encoded_masked_token.is_a?(String)
314314
return false
315315
end
@@ -340,19 +340,19 @@ def valid_authenticity_token?(session, encoded_masked_token)
340340
end
341341
end
342342

343-
def unmask_token(masked_token)
343+
def unmask_token(masked_token) # :doc:
344344
# Split the token into the one-time pad and the encrypted
345345
# value and decrypt it
346346
one_time_pad = masked_token[0...AUTHENTICITY_TOKEN_LENGTH]
347347
encrypted_csrf_token = masked_token[AUTHENTICITY_TOKEN_LENGTH..-1]
348348
xor_byte_strings(one_time_pad, encrypted_csrf_token)
349349
end
350350

351-
def compare_with_real_token(token, session)
351+
def compare_with_real_token(token, session) # :doc:
352352
ActiveSupport::SecurityUtils.secure_compare(token, real_csrf_token(session))
353353
end
354354

355-
def valid_per_form_csrf_token?(token, session)
355+
def valid_per_form_csrf_token?(token, session) # :doc:
356356
if per_form_csrf_tokens
357357
correct_token = per_form_csrf_token(
358358
session,
@@ -366,38 +366,38 @@ def valid_per_form_csrf_token?(token, session)
366366
end
367367
end
368368

369-
def real_csrf_token(session)
369+
def real_csrf_token(session) # :doc:
370370
session[:_csrf_token] ||= SecureRandom.base64(AUTHENTICITY_TOKEN_LENGTH)
371371
Base64.strict_decode64(session[:_csrf_token])
372372
end
373373

374-
def per_form_csrf_token(session, action_path, method)
374+
def per_form_csrf_token(session, action_path, method) # :doc:
375375
OpenSSL::HMAC.digest(
376376
OpenSSL::Digest::SHA256.new,
377377
real_csrf_token(session),
378378
[action_path, method.downcase].join("#")
379379
)
380380
end
381381

382-
def xor_byte_strings(s1, s2)
382+
def xor_byte_strings(s1, s2) # :doc:
383383
s2_bytes = s2.bytes
384384
s1.each_byte.with_index { |c1, i| s2_bytes[i] ^= c1 }
385385
s2_bytes.pack("C*")
386386
end
387387

388388
# The form's authenticity parameter. Override to provide your own.
389-
def form_authenticity_param
389+
def form_authenticity_param # :doc:
390390
params[request_forgery_protection_token]
391391
end
392392

393393
# Checks if the controller allows forgery protection.
394-
def protect_against_forgery?
394+
def protect_against_forgery? # :doc:
395395
allow_forgery_protection
396396
end
397397

398398
# Checks if the request originated from the same origin by looking at the
399399
# Origin header.
400-
def valid_request_origin?
400+
def valid_request_origin? # :doc:
401401
if forgery_protection_origin_check
402402
# We accept blank origin headers because some user agents don't send it.
403403
request.origin.nil? || request.origin == request.base_url
@@ -406,7 +406,7 @@ def valid_request_origin?
406406
end
407407
end
408408

409-
def normalize_action_path(action_path)
409+
def normalize_action_path(action_path) # :doc:
410410
uri = URI.parse(action_path)
411411
uri.path.chomp("/")
412412
end

actionpack/lib/action_controller/metal/streaming.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,10 @@ module ActionController #:nodoc:
193193
module Streaming
194194
extend ActiveSupport::Concern
195195

196-
protected
196+
private
197197

198198
# Set proper cache control and transfer encoding when streaming
199-
def _process_options(options) #:nodoc:
199+
def _process_options(options)
200200
super
201201
if options[:stream]
202202
if request.version == "HTTP/1.0"
@@ -210,7 +210,7 @@ def _process_options(options) #:nodoc:
210210
end
211211

212212
# Call render_body if we are streaming instead of usual +render+.
213-
def _render_template(options) #:nodoc:
213+
def _render_template(options)
214214
if options.delete(:stream)
215215
Rack::Chunked::Body.new view_renderer.render_body(view_context, options)
216216
else

actionpack/lib/action_dispatch/http/filter_parameters.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,28 @@ def filtered_path
5151
@filtered_path ||= query_string.empty? ? path : "#{path}?#{filtered_query_string}"
5252
end
5353

54-
protected
54+
private
5555

56-
def parameter_filter
56+
def parameter_filter # :doc:
5757
parameter_filter_for fetch_header("action_dispatch.parameter_filter") {
5858
return NULL_PARAM_FILTER
5959
}
6060
end
6161

62-
def env_filter
62+
def env_filter # :doc:
6363
user_key = fetch_header("action_dispatch.parameter_filter") {
6464
return NULL_ENV_FILTER
6565
}
6666
parameter_filter_for(Array(user_key) + ENV_MATCH)
6767
end
6868

69-
def parameter_filter_for(filters)
69+
def parameter_filter_for(filters) # :doc:
7070
ParameterFilter.new(filters)
7171
end
7272

7373
KV_RE = "[^&;=]+"
7474
PAIR_RE = %r{(#{KV_RE})=(#{KV_RE})}
75-
def filtered_query_string
75+
def filtered_query_string # :doc:
7676
query_string.gsub(PAIR_RE) do |_|
7777
parameter_filter.filter([[$1, $2]]).first.join("=")
7878
end

actionpack/lib/action_dispatch/http/mime_negotiation.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,20 +150,20 @@ def negotiate_mime(order)
150150
order.include?(Mime::ALL) ? format : nil
151151
end
152152

153-
protected
153+
private
154154

155155
BROWSER_LIKE_ACCEPTS = /,\s*\*\/\*|\*\/\*\s*,/
156156

157-
def valid_accept_header
157+
def valid_accept_header # :doc:
158158
(xhr? && (accept.present? || content_mime_type)) ||
159159
(accept.present? && accept !~ BROWSER_LIKE_ACCEPTS)
160160
end
161161

162-
def use_accept_header
162+
def use_accept_header # :doc:
163163
!self.class.ignore_accept_header
164164
end
165165

166-
def format_from_path_extension
166+
def format_from_path_extension # :doc:
167167
path = get_header("action_dispatch.original_path") || get_header("PATH_INFO")
168168
if match = path && path.match(/\.(\w+)\z/)
169169
Mime[match.captures.first]

actionpack/lib/action_dispatch/journey/router/utils.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ def unescape_uri(uri)
5858
uri.gsub(ESCAPED) { |match| [match[1, 2].hex].pack("C") }.force_encoding(encoding)
5959
end
6060

61-
protected
62-
def escape(component, pattern)
61+
private
62+
def escape(component, pattern) # :doc:
6363
component.gsub(pattern) { |unsafe| percent_encode(unsafe) }.force_encoding(US_ASCII)
6464
end
6565

66-
def percent_encode(unsafe)
66+
def percent_encode(unsafe) # :doc:
6767
safe = EMPTY.dup
6868
unsafe.each_byte { |b| safe << DEC2HEX[b] }
6969
safe

0 commit comments

Comments
 (0)