active_scaffold 4.4.8 → 4.4.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93a50bab634923deec74bb0777798bbdb11e6a1892d2aecd85602defb7b6352e
4
- data.tar.gz: 8efd5a4229407e194fbc0f7e901d4467ea1fcd1500c991ecc50d66c5911f9061
3
+ metadata.gz: b13a771c5fb245d7667dff89246184834a35ba6a26b989f66c99ef56ff54d178
4
+ data.tar.gz: fad0f981ddf6a6da05246f7c54cf1d9a88cd18d338a3ed6e591ed9c7fd248e78
5
5
  SHA512:
6
- metadata.gz: bb56102fc32fa3e594d666eec2446b553ed82ad8ad302d055fd8e5b4e6e1305fda0b54017f4f87ce86069a04a436e219423701831d9977b023f27ed08c444d96
7
- data.tar.gz: 9072cd0c201e25156e01b9d757acca94f91bc365a8d5d6cb03492f6309b63063bc7f9259bdba491cdfa48ca1454dc31554ffca28add6aec9336cf1e959bacec3
6
+ metadata.gz: 0b085fbe9ae5662e2fc19eaa037efc5ba071d350aad59d45afb3d605ff95f3d69c419decea0994b404a1a800459339ff5080e0525be79e74be3a59af2bd6e19e
7
+ data.tar.gz: 233eb12a8cfbb0294285a27125d09b7faf14642ce24b1bf22c385ef0def4bb14595ed06233a6a28bff2bd36c35c3fb6bd258893ffda2f1d8a31984bc96ca774e
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,8 @@
1
+ = 4.4.9
2
+ - Fix opening +field_search+ after a text search when both +search+ and +field_search+ actions are enabled.
3
+ - Ensure generated IDs are always clean, so they are safe to use in JS views
4
+ - Warn once per controller when URL parameters implicitly filter database columns and both +conditions_from_params_allowed_columns+ and +conditions_from_params_excluded_columns+ are nil. Unrestricted filtering can reveal hidden or unauthorized values through matching records or counts. Exclusions now default to nil so an explicit empty exclusion list can retain legacy filtering without warnings. In 4.5 the allowed list will default to +[]+, disabling implicit parameter filters unless applications opt in.
5
+
1
6
  = 4.4.8
2
7
  - Add authorized API association exports containing the primary key and +to_label+, with an overridable +api_association_options+ controller method. Associated record read authorization is checked automatically; applications can return Rails serialization options, including explicit nested +include:+ options, and must authorize the additional fields and nested records they request. In 4.4, +unsafe_api_associations = nil+ preserves legacy full-attribute exports with a deprecation warning, +true+ preserves them without warning, and +false+ enables safe exports. The unsafe behavior and compatibility setting will be removed in 4.5.
3
8
  - Authenticate embedded scaffold parameters with a signature in +eid+, bound to the target controller. Reject unsigned or modified conditions and constraints before using them to query or assign records.
@@ -526,12 +526,12 @@ module ActiveScaffold::Actions
526
526
  @conditions_from_params ||= begin
527
527
  conditions = [{}]
528
528
  allowed_columns = active_scaffold_config.conditions_from_params_allowed_columns&.map(&:to_s)
529
- excluded_columns = active_scaffold_config.conditions_from_params_excluded_columns.map(&:to_s)
529
+ excluded_columns = active_scaffold_config.conditions_from_params_excluded_columns&.map(&:to_s)
530
530
  params.except(:controller, :action, :page, :sort, :sort_direction, :format, :id).each do |key, value|
531
531
  distinct = key.match?(/!$/)
532
532
  column_name = key.to_s[0..(distinct ? -2 : -1)]
533
533
  next if allowed_columns&.exclude?(column_name)
534
- next if excluded_columns.include?(column_name)
534
+ next if excluded_columns&.include?(column_name)
535
535
 
536
536
  column = active_scaffold_config._columns_hash[column_name]
537
537
  next unless column
@@ -540,6 +540,7 @@ module ActiveScaffold::Actions
540
540
  next if active_scaffold_constraints[key]
541
541
  next if nested? && nested.param_name == key
542
542
 
543
+ ActiveScaffold::ParameterFilterWarning.warn_once(self.class) if allowed_columns.nil? && excluded_columns.nil?
543
544
  value = condition_value_from_param(value, column, active_scaffold_config.model)
544
545
  if distinct
545
546
  conditions << distinct_condition(key, value)
@@ -55,9 +55,9 @@ module ActiveScaffold::Config
55
55
  cattr_accessor :conditions_from_params_allowed_columns, instance_accessor: false
56
56
  @@conditions_from_params_allowed_columns = nil
57
57
 
58
- # columns excluded from parameter filtering, even when explicitly allowed
58
+ # nil leaves exclusions unspecified; [] explicitly accepts unrestricted filtering when the allowed list is nil
59
59
  cattr_accessor :conditions_from_params_excluded_columns, instance_accessor: false
60
- @@conditions_from_params_excluded_columns = []
60
+ @@conditions_from_params_excluded_columns = nil
61
61
 
62
62
  # action links are used by actions to tie together. you can use them, too! this is a collection of ActiveScaffold::DataStructures::ActionLink objects.
63
63
  cattr_reader :action_links, instance_reader: false
@@ -221,7 +221,7 @@ module ActiveScaffold::Config
221
221
  @default_formats = self.class.default_formats.dup
222
222
  @unsafe_api_associations = self.class.unsafe_api_associations
223
223
  @conditions_from_params_allowed_columns = self.class.conditions_from_params_allowed_columns&.dup
224
- @conditions_from_params_excluded_columns = self.class.conditions_from_params_excluded_columns.dup
224
+ @conditions_from_params_excluded_columns = self.class.conditions_from_params_excluded_columns&.dup
225
225
  @sti_create_links = self.class.sti_create_links
226
226
 
227
227
  # inherit from the global set of action links
@@ -522,7 +522,7 @@ module ActiveScaffold
522
522
  action_link_id("#{controller_id}#{link.action}", '--ID--')
523
523
  end
524
524
  end
525
- action_link_id.sub('--ID--', id)
525
+ action_link_id.sub('--ID--', clean_id(id))
526
526
  end
527
527
 
528
528
  def action_link_html(link, url, html_options, record)
@@ -130,7 +130,7 @@ module ActiveScaffold
130
130
  @params_for.delete(:id) if @params_for[:id].nil?
131
131
  end
132
132
 
133
- url_options = @params_for.merge(options)
133
+ url_options = @params_for.merge(options.slice(:controller))
134
134
  if !active_scaffold_config.store_user_settings && controller_requested(url_options[:controller]) == controller_path
135
135
  url_options[:search] ||= copy_param search_params if respond_to?(:search_params, true) && search_params.present?
136
136
  url_options[:page] ||= params[:page]
@@ -140,6 +140,7 @@ module ActiveScaffold
140
140
  url_options[:sort_direction] ||= direction
141
141
  end
142
142
  end
143
+ url_options.merge!(options)
143
144
  url_options.delete(:return_to_signature) unless url_options[:return_to]
144
145
  url_options
145
146
  end
@@ -130,6 +130,7 @@ module ActiveScaffold
130
130
  # Fix for keeping unique IDs in subform
131
131
  id_control = "record_#{column.name}_#{[params[:eid], params[:parent_id] || params[:id]].compact.join '_'}"
132
132
  id_control += scope_id(scope) if scope
133
+ id_control = clean_id(id_control)
133
134
 
134
135
  classes = "#{column.name}-input"
135
136
  classes += ' numeric-input' if column.number?
@@ -353,7 +354,7 @@ module ActiveScaffold
353
354
  hidden_field_tag options[:name], '', options
354
355
  else
355
356
  fields = value.map do |r|
356
- hidden_field_tag options[:name], r.id, options.merge(id: options[:id] + "_#{r.id}")
357
+ hidden_field_tag options[:name], r.id, options.merge(id: options[:id] + "_#{clean_id r.id.to_s}")
357
358
  end
358
359
  safe_join fields, ''
359
360
  end
@@ -5,7 +5,7 @@ module ActiveScaffold
5
5
  # A bunch of helper methods to produce the common view ids
6
6
  module IdHelpers
7
7
  def id_from_controller(controller)
8
- ERB::Util.h controller.to_s.gsub('/', '__')
8
+ clean_id ERB::Util.h(controller.to_s.gsub('/', '__'))
9
9
  end
10
10
 
11
11
  def controller_id(controller = params[:eid] || nested_id || params[:parent_controller] || params[:controller])
@@ -57,7 +57,7 @@ module ActiveScaffold
57
57
  end
58
58
 
59
59
  def action_link_id(link_action, link_id)
60
- "#{controller_id}-#{link_action}-#{link_id}-link"
60
+ clean_id "#{controller_id}-#{link_action}-#{link_id}-link"
61
61
  end
62
62
 
63
63
  def active_scaffold_column_header_id(column)
@@ -125,7 +125,7 @@ module ActiveScaffold
125
125
  end
126
126
 
127
127
  def action_iframe_id(options)
128
- "#{controller_id}-#{options[:action]}-#{options[:id]}-iframe"
128
+ clean_id "#{controller_id}-#{options[:action]}-#{options[:id]}-iframe"
129
129
  end
130
130
 
131
131
  def scope_id(scope)
@@ -376,7 +376,7 @@ module ActiveScaffold
376
376
  cell_id = ActiveScaffold::Registry.cache :inplace_edit_id, column.cache_key do
377
377
  element_cell_id(id: '--ID--', action: 'update_column', name: column.name.to_s)
378
378
  end
379
- tag_options = {id: cell_id.sub('--ID--', record.id.to_s), class: 'in_place_editor_field',
379
+ tag_options = {id: cell_id.sub('--ID--', clean_id(record.id.to_s)), class: 'in_place_editor_field',
380
380
  title: @_inplace_edit_title, data: {ie_id: record.to_param}}
381
381
  tag_options[:data][:ie_update] = column.inplace_edit if column.inplace_edit != true
382
382
  tag_options
@@ -53,7 +53,7 @@ module ActiveScaffold
53
53
  attributes = {
54
54
  name: "search[#{column.name}]",
55
55
  class: "#{column.name}-input",
56
- id: "search_#{column.name}",
56
+ id: clean_id("search_#{column.name}"),
57
57
  value: field_search_params[column.name.to_s]
58
58
  }
59
59
  as_element_attributes(:search_control, proc_options: {column: column, search_ui: column.search_ui}, **attributes)
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'concurrent/map'
4
+
5
+ module ActiveScaffold
6
+ module ParameterFilterWarning
7
+ @warned_controllers = Concurrent::Map.new
8
+
9
+ def self.warn_once(controller)
10
+ key = controller.name || controller
11
+ return unless @warned_controllers.put_if_absent(key, true).nil?
12
+
13
+ ActiveScaffold.deprecator.warn(
14
+ "#{controller}: conditions_from_params implicitly allows filtering on all database columns, " \
15
+ 'including hidden or unauthorized values that can be inferred from matching records or counts. ' \
16
+ 'In ActiveScaffold 4.5, conditions_from_params_allowed_columns will default to [], disabling ' \
17
+ 'these filters. Configure conditions_from_params_allowed_columns or ' \
18
+ 'conditions_from_params_excluded_columns explicitly. To retain unrestricted legacy filtering ' \
19
+ 'without this warning, set conditions_from_params_allowed_columns = nil and ' \
20
+ 'conditions_from_params_excluded_columns = []; this does not prevent inference of hidden values.'
21
+ )
22
+ end
23
+ end
24
+ end
@@ -4,7 +4,7 @@ module ActiveScaffold
4
4
  module Version
5
5
  MAJOR = 4
6
6
  MINOR = 4
7
- PATCH = 8
7
+ PATCH = 9
8
8
  FIX = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, FIX].compact.join('.')
@@ -15,6 +15,7 @@ module ActiveScaffold
15
15
  autoload :MarkedModel, 'active_scaffold/marked_model'
16
16
  autoload :OrmChecks, 'active_scaffold/orm_checks'
17
17
  autoload :ParameterSigning, 'active_scaffold/parameter_signing'
18
+ autoload :ParameterFilterWarning, 'active_scaffold/parameter_filter_warning'
18
19
  autoload :Registry, 'active_scaffold/registry'
19
20
  autoload :RespondsToParent, 'active_scaffold/responds_to_parent'
20
21
  autoload :Routing, 'active_scaffold/extensions/routing_mapper'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.8
4
+ version: 4.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Many, see README
@@ -358,6 +358,7 @@ files:
358
358
  - lib/active_scaffold/marked_model.rb
359
359
  - lib/active_scaffold/orm_checks.rb
360
360
  - lib/active_scaffold/paginator.rb
361
+ - lib/active_scaffold/parameter_filter_warning.rb
361
362
  - lib/active_scaffold/parameter_signing.rb
362
363
  - lib/active_scaffold/railties/tasks.rake
363
364
  - lib/active_scaffold/registry.rb