Skip to content

A platform for community discussion. Free, open, simple.

SECURITY: Store custom field values according to their registered type

Daniel Waterworth75c645453dc4
diff --git a/app/models/concerns/has_custom_fields.rb b/app/models/concerns/has_custom_fields.rb
index 690c976430f..02ab064cfa9 100644
--- a/app/models/concerns/has_custom_fields.rb
+++ b/app/models/concerns/has_custom_fields.rb
@@ -33,14 +33,28 @@ module HasCustomFields
end
def serialize(value)
- if value.is_a?(Hash) || type == :json || (array_type? && type[0] == :json)
+ base_type = Array === type ? type.first : type
+
+ case base_type
+ when :json
value.to_json
- elsif TrueClass === value
- "t"
- elsif FalseClass === value
- "f"
+ when :integer
+ value.to_i.to_s
+ when :boolean
+ value = !!Helpers::CUSTOM_FIELD_TRUE.include?(value) if String === value
+
+ value ? "t" : "f"
else
- value.to_s
+ case value
+ when Hash
+ value.to_json
+ when TrueClass
+ "t"
+ when FalseClass
+ "f"
+ else
+ value.to_s
+ end
end
end