serialization - Ensuring genuine parameters doesn't trigger "You tried to assign already serialized content to value. This is disabled due to security issues." -


i've created form builder in rails allows users construct own forms. many of form inputs supply straight strings rails (e.g. text field). provide arrays of values (like date choosers). right i'm storing values these in serialised column. works well, , lets me re-display custom forms when error occurs minimal effort. problem entered:

--------

into text field , activerecord raised error saying: you tried assign serialized content value. disabled due security issues.

i string looks yaml, i'm wondering if there's more graceful way around user entering bunch of dashes indicate had no phone number. i'd fail gracefully , perhaps drop value or store serialised string if there such thing.

in rails 3.0.20 lts they've patched code check yaml strings being sent serialised columns. i've overridden assignment method on model fix string instead of raising error:

module activerecord   module attributemethods     module write       extend activesupport::concern        included         attribute_method_suffix "="       end        module classmethods         protected           def define_method_attribute=(attr_name)             if self.serialized_attributes[attr_name]               generated_attribute_methods.send(:define_method, "#{attr_name}=") |new_value|                 if new_value.is_a?(string) , new_value =~ /^---/                   raise activerecorderror, "you tried assign serialized content #{attr_name}. disabled due security issues."                 end                 write_attribute(attr_name, new_value)               end             elsif attr_name =~ /^[a-za-z_]\w*[!?=]?$/               generated_attribute_methods.module_eval("def #{attr_name}=(new_value); write_attribute('#{attr_name}', new_value); end", __file__, __line__)             else               generated_attribute_methods.send(:define_method, "#{attr_name}=") |new_value|                 write_attribute(attr_name, new_value)               end             end           end       end        ... 

i wanted use super(new_value) here allow original method make assignment unfortunately seemed bypassing check (thus bypassing security measure too).

  def value=(new_value)     if new_value.is_a?(string) , new_value =~ /^---/       new_value.gsub!(/^-+/, '-')     end     write_attribute(:value, new_value)   end 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -