File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed
Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -8,4 +8,10 @@ class ApplicationRecord < ActiveRecord::Base
88
99 self . abstract_class = true
1010
11+ def sanitize_fields ( *attrs )
12+ attrs . each do |attr |
13+ send ( "#{ attr } =" , ActionController ::Base . helpers . sanitize ( send ( attr ) ) )
14+ end
15+ end
16+
1117end
Original file line number Diff line number Diff line change @@ -203,6 +203,15 @@ class Plan < ApplicationRecord
203203 end
204204 alias super_settings settings
205205
206+ # =============
207+ # = Callbacks =
208+ # =============
209+
210+ # sanitise html tags e.g remove unwanted 'script'
211+ before_validation lambda { |data |
212+ data . sanitize_fields ( :title , :identifier , :description )
213+ }
214+
206215 # =================
207216 # = Class methods =
208217 # =================
@@ -227,7 +236,7 @@ def self.load_for_phase(plan_id, phase_id)
227236 # Returns Plan
228237 def self . deep_copy ( plan )
229238 plan_copy = plan . dup
230- plan_copy . title = "Copy of " + plan . title
239+ plan_copy . title = "Copy of #{ plan . title } "
231240 plan_copy . feedback_requested = false
232241 plan_copy . save!
233242 plan . answers . each do |answer |
Original file line number Diff line number Diff line change @@ -160,6 +160,9 @@ class User < ApplicationRecord
160160 # = Callbacks =
161161 # =============
162162
163+ # sanitise html tags from fields
164+ before_validation -> ( data ) { data . sanitize_fields ( :firstname , :surname ) }
165+
163166 after_update :clear_department_id , if : :saved_change_to_org_id?
164167
165168 after_update :delete_perms! , if : :saved_change_to_org_id? , unless : :can_change_org?
You can’t perform that action at this time.
0 commit comments