Add Content Security Policy headers

Bug #822950 reported by François Marier
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Libravatar (obsolete)
Fix Released
Low
François Marier

Bug Description

To help limit the damage that content injection (e.g. XSS) could cause, Libravatar could expose the X-Content-Security-Policy headers and explicitly name the hosts where external content can come from (i.e. just *.libravatar.org on most pages and Identica and Gravatar on the photo import page).

It's built into Firefox 4 and later.

  https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html
  https://developer.mozilla.org/en/Introducing_Content_Security_Policy
  https://github.com/mozilla/django-csp

Also see bug #769738 for a similar type of browser-enforced security checks.

Tags: csp security
description: updated
Revision history for this message
François Marier (fmarier) wrote :

This looks like a reasonable default policy:

  X-Content-Security-Policy: "allow 'self'; options inline-script; img-src 'self' http://cdn.libravatar.org https://seccdn.libravatar.org data:"

(see https://developer.mozilla.org/en/Security/CSP/CSP_policy_directives for the details)

However, these pages need exceptions:

- tools/check: needs to allow any third-party images
- account/import_photo: needs to allow Gravatar and Identi.ca images

Revision history for this message
François Marier (fmarier) wrote :

Ideally, it would be nice to have Apache add a default CSP header if there isn't one already in the response (i.e. Django hasn't returned one).

That way, we could override the default value of that header within Django by doing this:

  response = render_to_response('tools/check.html', {'form': form, 'data' : data}, context_instance=RequestContext(request))
  response['X-Content-Security-Policy'] = 'something else'
  return response

The problem however is that Apache mod_headers doesn't have an action that adds a header only if it didn't exist already:

  https://httpd.apache.org/docs/2.2/mod/mod_headers.html#header

and we can't use the 'merge' or 'add' actions because they use commas as separators whereas CSP requires semicolons :(

Changed in libravatar:
assignee: nobody → François Marier (fmarier)
status: Triaged → In Progress
Changed in libravatar:
status: In Progress → Fix Committed
Revision history for this message
François Marier (fmarier) wrote :
Changed in libravatar:
status: Fix Committed → Fix Released
tags: added: csp
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.