canvas-lms/gems
Jacob Fugal 371ec30967 refactor CSRF handling for clarity and rails3+
closes CNVS-18870

CNVS-18870 as described in the ticket description is not a bug. see
comments on the ticket for more details. but while investigating and
confirming that, it became obvious that the odd structure and scattered
implementation of the CSRF protection was both making it hard to reason
about and easy to introduce new bugs. after the refactor, we still:

* don't perform CSRF validation on GET requests
* don't perform it on token-authenticated API requests
* do perform it on session-authenticated API requests
* do perform it on non-API requests regardless of authentication method

additionally, we now:

* don't perform CSRF validation on HEAD requests

finally, we _don't_ support a csrf_token in the session anymore. that's
been deprecated forever; we can remove the code now.

test-plan:
 - should not perform CSRF validation for:
   - GET requests
   - token-authenticated POST requests to API endpoints (path prefixed
     by /api/) without an authenticity_token parameter or X-CSRF-Token
     header
   - token-authenticated POST requests to API endpoints even with an
     authenticity_token parameter
   - token-authenticated POST requests to API endpoints even with an
     X-CSRF-Token header

 - should perform CSRF validation for:
   - POST requests to non-API endpoints
   - session-authenticated POST requests to API endpoints

 - when CSRF validation should occur, but the user has cookies off:
   - POST requests to non-API endpoints should redirect to a "need
     cookies" page
   - XHR POST requests to non-API endpoints should not redirect
   - POST requests to API endpoints should not redirect

Change-Id: I3dbb3a68623bc9d03a3e744a9d4e1f038a32709c
Reviewed-on: https://gerrit.instructure.com/65103
Reviewed-by: Simon Williams <simon@instructure.com>
Tested-by: Jenkins
QA-Review: August Thornton <august@instructure.com>
Product-Review: Jacob Fugal <jacob@instructure.com>
2016-01-11 23:31:47 +00:00
..
activesupport-suspend_callbacks rails 4.2: fix suspend_callbacks 2016-01-05 13:52:00 +00:00
acts_as_list rails 4.2: use AR#connection on class instead of model 2016-01-05 13:53:41 +00:00
adheres_to_policy remove rails 3 support 2015-12-23 21:36:43 +00:00
attachment_fu rails 4.2: remove attachment_fu callbacks hackery 2016-01-05 20:33:18 +00:00
autoextend some vendored gem test fixes 2016-01-07 05:33:25 +00:00
bookmarked_collection remove rails 3 support 2015-12-23 21:36:43 +00:00
broadcast_policy rails 4.2: use AR#connection on class instead of model 2016-01-05 13:53:41 +00:00
canvas_breach_mitigation refactor CSRF handling for clarity and rails3+ 2016-01-11 23:31:47 +00:00
canvas_cassandra some vendored gem test fixes 2016-01-07 05:33:25 +00:00
canvas_color fix Style/EmptyLineBetweenDefs issue 2015-04-29 16:28:39 +00:00
canvas_crummy remove rails 2 support 2014-08-06 18:16:19 +00:00
canvas_ext remove rails 3 support 2015-12-23 21:36:43 +00:00
canvas_http fix attachment downloading from url 2016-01-10 04:00:09 +00:00
canvas_i18nliner explicit jsdom and qunit dependencies for npm v3 2015-09-21 22:27:02 +00:00
canvas_kaltura Revert "handle nil responses from kaltura client" 2015-11-10 20:50:37 +00:00
canvas_mimetype_fu spec: simple_cov tweaks 2014-11-24 17:39:14 +00:00
canvas_panda_pub fix Performance/ReverseEach issue 2015-04-27 20:53:43 +00:00
canvas_partman rails 4.2: s/destroy!/destroy_permanently! 2016-01-07 14:00:13 +00:00
canvas_quiz_statistics Fix 500 error around Numerical precision answers in Quiz Stats 2015-12-21 17:10:10 +00:00
canvas_sanitize Adding HTML5 video capability. 2015-09-11 16:50:30 -04:00
canvas_slug clarify Slug vs. UUID and fix event stream 2014-07-11 16:58:42 +00:00
canvas_sort bundle check before bundle install for gem tests 2014-06-03 20:09:10 +00:00
canvas_stringex remove syck from the canvas_stringex gemfile 2016-01-08 20:35:53 +00:00
canvas_text_helper spec: simple_cov tweaks 2014-11-24 17:39:14 +00:00
canvas_time remove rails 3 support 2015-12-23 21:36:43 +00:00
canvas_unzip ensure zip filenames are UTF-8 2015-06-26 22:01:26 +00:00
csv_diff csv_diff gem 2015-02-26 15:52:58 +00:00
diigo bump nokogiri to latest 2015-02-19 19:15:29 +00:00
event_stream rails4.2: Fixnum#ago is deprecated 2015-12-29 21:14:11 +00:00
google_docs Refactor google drive trashed filter to use api parameter 2015-12-21 23:28:21 +00:00
google_drive send login_hint as a users google doc email if available 2015-04-16 18:24:44 +00:00
handlebars_tasks replace handlebars_spec 2016-01-06 22:30:19 +00:00
html_text_helper some vendored gem test fixes 2016-01-07 05:33:25 +00:00
i18n_extraction remove rails 3 support 2015-12-23 21:36:43 +00:00
i18n_tasks remove rails 3 support 2015-12-23 21:36:43 +00:00
incoming_mail_processor remove rails 3 support 2015-12-23 21:36:43 +00:00
json_token bump json to 1.8.2 2015-01-22 16:42:50 +00:00
linked_in Fix linkedin initialization 2015-06-25 20:03:49 +00:00
live_events move canvas_statsd and related to external gem 2015-05-18 15:53:19 +00:00
lti_outbound create ext_outcomes_tool_placement_url api for turnitin 2015-07-28 22:46:54 +00:00
multipart align rspec version in gems with parent 2014-08-12 22:27:39 +00:00
paginated_collection update will_paginate gem 2015-07-27 21:41:20 +00:00
plugins rip out more polymorphic shims 2016-01-11 17:40:03 +00:00
rubocop-canvas don't try and eager load in a data fixup 2015-09-24 17:05:16 +00:00
selinimum spec: don't improperly selinimize changes to the tinymce bundle 2016-01-07 21:39:48 +00:00
turnitin_api modified gemspec to comply with RubyGems v2.5.0 2015-11-05 21:44:02 +00:00
twitter Fix twitter migration for settings 2015-06-24 20:22:11 +00:00
utf8_cleaner some vendored gem test fixes 2016-01-07 05:33:25 +00:00
workflow remove rails 3 support 2015-12-23 21:36:43 +00:00
test_all_gems.sh fix reporting of all gem tests 2016-01-06 19:06:41 +00:00