canvas-lms/gems/canvas_sanitize
Brent Burgoyne e942742d8e fix stored xss vulnerability in rce html editor
fixes CORE-2311

test plan:
- create/edit any rce content (page, discussion, assignment, etc)
- click "HTML Editor"
- add this html:
  <a data-url="javascript:alert('fail')" data-method="GET">Link</a>
- save
- the alert should not show

Change-Id: Ib6bd4aca4ae69c772f37e3d0b7d73e3241bb939c
Reviewed-on: https://gerrit.instructure.com/176818
Tested-by: Jenkins
Product-Review: Brent Burgoyne <bburgoyne@instructure.com>
Reviewed-by: Clay Diffrient <cdiffrient@instructure.com>
QA-Review: Clay Diffrient <cdiffrient@instructure.com>
2019-01-04 22:26:23 +00:00
..
lib fix stored xss vulnerability in rce html editor 2019-01-04 22:26:23 +00:00
spec fix stored xss vulnerability in rce html editor 2019-01-04 22:26:23 +00:00
Gemfile bump simplecov, fixes SD-2056 2017-04-04 18:06:25 +00:00
README.md da licença part 53 2017-05-01 21:06:11 +00:00
Rakefile convert sanitize field plugin into proper gem: CanvasSanitize 2014-01-28 22:36:18 +00:00
canvas_sanitize.gemspec bump sanitize 2018-10-05 21:16:54 +00:00
test.sh simplify gem test harnesses 2016-01-19 17:52:58 +00:00

README.md

SanitizeField

We want to be able to mix model fields with Sanitize configuration and implement a sanitization in a before_save callback.

An alternative to this plugin might be using a Rails whitelist. This isn't developed, but is an idea on http://wonko.com/post/sanitize

Rails::Initializer.run do |config| config.action_view.white_list_sanitizer = Sanitizer.new config.action_view.sanitized_allowed_tags = table, tr, td config.action_view.sanitized_allowed_attributes = id, class, style end

Our approach is finer-grained, and should work better for now at least. There is also talk about an alternative 1.9/nokogiri approach to the Sanitizer gem for more optimal performance. Keeping our eyes open about these issues.

Example

class BasicExample < ActiveRecord::Base sanitize :body, Sanitize::Config::RELAXED end

class Whatever < ActiveRecord::Base sanitize :body, :title, :elements => ['a', 'span'], :attributes => {'a' => ['href', 'title'], 'span' => ['class']}, :protocols => {'a' => {'href' => ['http', 'https', 'mailto']}} end

License

Copyright (C) 2011 - present Instructure, Inc.

This file is part of Canvas.

Canvas is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License.

Canvas is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see http://www.gnu.org/licenses/.