Skip to content

Commit

Permalink
Merge pull request #3030 from DigitalCurationCentre/remove_vulnerabil…
Browse files Browse the repository at this point in the history
…ity_XSS_hack

Remove vulnerability xss hack
  • Loading branch information
briri committed Sep 27, 2021
2 parents dab960f + 0b83ad3 commit 7a97355
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/models/application_record.rb
Expand Up @@ -8,4 +8,10 @@ class ApplicationRecord < ActiveRecord::Base

self.abstract_class = true

def sanitize_fields(*attrs)
attrs.each do |attr|
send("#{attr}=", ActionController::Base.helpers.sanitize(send(attr)))
end
end

end
11 changes: 10 additions & 1 deletion app/models/plan.rb
Expand Up @@ -203,6 +203,15 @@ class Plan < ApplicationRecord
end
alias super_settings settings

# =============
# = Callbacks =
# =============

# sanitise html tags e.g remove unwanted 'script'
before_validation lambda { |data|
data.sanitize_fields(:title, :identifier, :description)
}

# =================
# = Class methods =
# =================
Expand All @@ -227,7 +236,7 @@ def self.load_for_phase(plan_id, phase_id)
# Returns Plan
def self.deep_copy(plan)
plan_copy = plan.dup
plan_copy.title = "Copy of " + plan.title
plan_copy.title = "Copy of #{plan.title}"
plan_copy.feedback_requested = false
plan_copy.save!
plan.answers.each do |answer|
Expand Down
3 changes: 3 additions & 0 deletions app/models/user.rb
Expand Up @@ -160,6 +160,9 @@ class User < ApplicationRecord
# = Callbacks =
# =============

# sanitise html tags from fields
before_validation ->(data) { data.sanitize_fields(:firstname, :surname) }

after_update :clear_department_id, if: :saved_change_to_org_id?

after_update :delete_perms!, if: :saved_change_to_org_id?, unless: :can_change_org?
Expand Down

0 comments on commit 7a97355

Please sign in to comment.