このコミットが含まれているのは:
@@ -6,7 +6,7 @@ module CountsListing
|
||||
resource = is_a?(CountsPostsController) ? 'posts' : 'tags'
|
||||
query = CountsQuery.new(version_scope, resource, request.query_parameters.except('locale')
|
||||
.merge('locale' => locale.code))
|
||||
result = { count: query.count, page: query.page, limit: query.limit,
|
||||
result = { population_count_scope: 'all_recorded_versions', population_count: HistoryAccess.population_count(query.relation.klass), count: query.count, page: query.page, limit: query.limit,
|
||||
at: request.query_parameters['at'].presence || Time.current.utc.iso8601(6) }
|
||||
if query.mode == 'summary'
|
||||
result.merge!(query.summary)
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
# Permanent storage URLs must not bypass a resource's later discard boundary.
|
||||
module HistoryStorageAccess
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
include RequestAccess
|
||||
prepend_before_action :authorise_history_storage!
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def authorise_history_storage!
|
||||
response.headers['Cache-Control'] = 'private, no-store'
|
||||
return unless request.get? || request.head?
|
||||
|
||||
reject_banned_ip_address!
|
||||
return if performed?
|
||||
|
||||
authenticate_user
|
||||
reject_banned_user!
|
||||
return if performed?
|
||||
|
||||
signed = params[:signed_blob_id] || params[:signed_id]
|
||||
blob = if signed
|
||||
ActiveStorage::Blob.find_signed(signed)
|
||||
elsif params[:encoded_key]
|
||||
payload = ActiveStorage.verifier.verified(params[:encoded_key], purpose: :blob_key)
|
||||
key = payload && (payload[:key] || payload['key'])
|
||||
if key
|
||||
original = key.start_with?('variants/') ? key.split('/')[1] : key
|
||||
ActiveStorage::Blob.find_by(key: original)
|
||||
end
|
||||
end
|
||||
return head :not_found unless blob
|
||||
|
||||
allowed = HistoryAccess.set(user: current_user) { HistoryAccess.blob_visible?(blob) }
|
||||
head :not_found unless allowed
|
||||
rescue ActiveSupport::MessageVerifier::InvalidSignature
|
||||
head :not_found
|
||||
end
|
||||
|
||||
# Override the engine's public-forever caching before a streaming response commits.
|
||||
def http_cache_forever(**_options)
|
||||
response.headers['Cache-Control'] = 'private, no-store'
|
||||
yield
|
||||
end
|
||||
|
||||
def expires_in(*arguments, **options)
|
||||
super
|
||||
response.headers['Cache-Control'] = 'private, no-store'
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,28 @@
|
||||
# Canonical read-side session and BAN boundary, shared by API and storage controllers.
|
||||
module RequestAccess
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def current_user = @current_user
|
||||
|
||||
private
|
||||
|
||||
def authenticate_user
|
||||
code = session[:inheritance_code]
|
||||
return if code.blank?
|
||||
|
||||
@current_user = User.find_by(inheritance_code: code)
|
||||
end
|
||||
|
||||
def reject_banned_ip_address!
|
||||
ip_address = IpAddress.find_by(ip_address: IPAddr.new(request.remote_ip).hton)
|
||||
return unless ip_address&.banned?
|
||||
|
||||
head :forbidden
|
||||
end
|
||||
|
||||
def reject_banned_user!
|
||||
return unless current_user&.banned?
|
||||
|
||||
head :forbidden
|
||||
end
|
||||
end
|
||||
新しいイシューから参照
ユーザーをブロックする