Skip to content

Commit

Permalink
Merge pull request #530 from freedomofpress/515-referrer-policy
Browse files Browse the repository at this point in the history
Add support for the Referrer-Policy header in the scanner
  • Loading branch information
conorsch authored Aug 30, 2018
2 parents dc0e23b + ed8d91e commit dab6415
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
8 changes: 8 additions & 0 deletions directory/management/commands/createresultgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,12 @@ def handle(self, *args, **options):
result_group=local_storage,
sort_order=1
),
ResultState(
name='referrer_policy_set_to_no_referrer',
success_text='<a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy">Referrer-Policy</a> no-referrer header set properly.',
failure_text='<a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy">Referrer-Policy</a> no-referrer header not set properly.',
is_warning=True,
result_group=server_security,
sort_order=9
),
])
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.11 on 2018-08-29 17:13
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

replaces = [('directory', '0006_scanresult_no_referrer_policy_set'), ('directory', '0007_auto_20180828_2158')]

dependencies = [
('directory', '0005_directoryentry_delisted'),
]

operations = [
migrations.AddField(
model_name='scanresult',
name='referrer_policy_set_to_no_referrer',
field=models.NullBooleanField(),
),
]
2 changes: 2 additions & 0 deletions directory/models/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ class ScanResult(models.Model):
cache_control_nostore_set = models.NullBooleanField()
cache_control_private_set = models.NullBooleanField()
expires_set = models.NullBooleanField()
referrer_policy_set_to_no_referrer = models.NullBooleanField()

# Page content
safe_onion_address = models.NullBooleanField()
Expand Down Expand Up @@ -308,6 +309,7 @@ class ScanResult(models.Model):
ReadOnlyPanel("cache_control_nostore_set"),
ReadOnlyPanel("cache_control_private_set"),
ReadOnlyPanel("expires_set"),
ReadOnlyPanel("referrer_policy_set_to_no_referrer"),
ReadOnlyPanel("safe_onion_address"),
ReadOnlyPanel("no_cdn"),
ReadOnlyPanel("no_analytics"),
Expand Down
5 changes: 5 additions & 0 deletions scanner/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def pshtt_data_to_result(securedrop: DirectoryEntry, pshtt_results: Dict) -> Sca
cache_control_notransform_set=validate_notransform(page),
cache_control_nostore_set=validate_nostore(page),
cache_control_private_set=validate_private(page),
referrer_policy_set_to_no_referrer=validate_no_referrer_policy(page),
)


Expand Down Expand Up @@ -349,6 +350,10 @@ def validate_private(page):
return validate_security_header(page, "Cache-Control", "private")


def validate_no_referrer_policy(page):
return validate_security_header(page, "Referrer-Policy", "no-referrer")


def validate_no_cookies(page):
if len(page.cookies.keys()) > 0:
return False
Expand Down
10 changes: 10 additions & 0 deletions scanner/tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,13 @@ def test_cache_control_validate_private_not_set(self):
page = mock.Mock()
page.headers = {'Cache-Control': 'public'}
self.assertFalse(scanner.validate_private(page))

def test_referrer_policy_no_referrer_set(self):
page = mock.Mock()
page.headers = {'Referrer-Policy': 'no-referrer'}
self.assertTrue(scanner.validate_no_referrer_policy(page))

def test_referrer_policy_no_referrer_not_set(self):
page = mock.Mock()
page.headers = {'Referrer-Policy': 'origin'}
self.assertFalse(scanner.validate_no_referrer_policy(page))

0 comments on commit dab6415

Please sign in to comment.