Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

[WIP] Adds secure_headers & Content-Security-Policy to Classroom #1166

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

anglinb
Copy link

@anglinb anglinb commented Sep 24, 2017

馃憢 I was taking a look at Classroom as part of the appsec-review process and, while this PR does not address a specific known vulnerability, adding the secureheaders gem and configuring Content-Security-Policy (CSP) Headers will help mitigate any available client-side attacks and those which may occur in the future.


This is a WIP PR b/c I have a few concerns on the best way to integrate secureheaders and handle some issues that came up:

Questions:

  • Should we have the CSP config inline in config/application.rb file or should it get broken out into it's own file?
  • Are we ok with pinning a fork of the jquery-datetimepicker-rails gem?
    • The latest released version of jquery-datepicker-rails is v2.4.1.0 and it contains an outdated version of jQuery DateTimePicker plugin. This outdated version relies on eval which it's newest release v2.5.4 does not.
    • Options:
      • Explicitly allow unsafe-eval
      • Use a forked version of jquery-datepicker-rails
      • Move to rails-assest.org for management of JS dependencies
  • Should we refactor JS inclusion to remove the YouTube script from being included on every page?
    • Right now, the application.js file includes = require_tree ., which pulls in the https://www.youtube.com/iframe_api.
    • This has a minimal performance hit by pulling in all these assets on page load but after the initial load they should be cached. However, from a CSP perspective, whitelisting a very minimal set of resources is ideal and for that reason, I have only added the YouTube sources to the CSP Definition on the unauthed home page.
    • Options:
      • Add YouTube sources to the global CSP definition
      • Refactor application.js to not include all the scripts all the time.
      • Use a nonce or sha256 CSP directive to inline the pages.js file on the homepage.

Next Steps:

If ya'll have a sec to answer these questions, I would be happy to fix up this PR. 馃憤

/cc @gregose

@tarebyte
Copy link
Member

I would like it to be in it's own file

Yes, using the forked version is the easiest path ATM so let's go with that one.

  • Should we refactor JS inclusion to remove the YouTube script from being included on every page?

Absolutely 馃槃

@anglinb
Copy link
Author

anglinb commented Sep 27, 2017

/cc @oreoshake

@oreoshake
Copy link

The csp changes look great 馃憤 but I can't speak to the rubocop changes or whether anything will break 馃槃.

@anglinb
Copy link
Author

anglinb commented Sep 27, 2017

@oreoshake Thanks for taking a look! Good catch on the rubocop changes--I think those should match. It was complaining about the quotes for self in %w['self'] so I tried to disable PercentStringArray

@@ -0,0 +1,20 @@
# Setup Secure Headers with default values

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing magic comment # frozen_string_literal: true.

Copy link
Member

@tarebyte tarebyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @anglinb!!

@anglinb
Copy link
Author

anglinb commented Sep 27, 2017

@tarebyte np! Just a heads up: There is a CSP error on pretty much every page b/c the pages.js file gets included by the application.js file's require_tree . directive. This will spam the console but otherwise has no effect.

banners_and_alerts_and_github_classroom

I punted a bit on refactoring js importing b/c its kinda out of scope of just adding CSP so if you're cool with having this error around in the console, then feel free to merge. If not I can try and add a workaround for now. Lmk 馃槃

@stale
Copy link

stale bot commented Nov 26, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 26, 2017
@anglinb
Copy link
Author

anglinb commented Nov 27, 2017

馃憢 Friendly bump

@stale stale bot removed the stale label Nov 27, 2017
@stale
Copy link

stale bot commented Jan 26, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 26, 2018
@stale stale bot closed this Feb 2, 2018
@tarebyte tarebyte reopened this Feb 2, 2018
@stale stale bot removed the stale label Feb 2, 2018
@stale
Copy link

stale bot commented Sep 25, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 25, 2018
@stale stale bot closed this Oct 2, 2018
@BenEmdon BenEmdon reopened this Oct 2, 2018
@stale stale bot removed the stale label Oct 2, 2018
@BenEmdon
Copy link
Contributor

BenEmdon commented Oct 2, 2018

@srinjoym this sounds right up your alley

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants