Skip to content

Commit 7a97355

Browse files
authored
Merge pull request #3030 from DigitalCurationCentre/remove_vulnerability_XSS_hack
Remove vulnerability xss hack
2 parents dab960f + 0b83ad3 commit 7a97355

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

app/models/application_record.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
1117
end

app/models/plan.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff 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|

app/models/user.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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?

0 commit comments

Comments
 (0)