Skip to content

Commit

Permalink
add header: Feature-Policy
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyguitar committed Sep 13, 2018
1 parent 8497340 commit a57b63f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ def find_key(token):
sslify = SSLify(app, skips=[".well-known"])


@app.after_request
def add_feature_policy(response):
"""Add feature policy."""
response.headers["Feature-Policy"] = "geolocation 'none'"
return response


@app.route("/<path:path>")
def static_proxy(path):
"""Find static files."""
Expand Down
11 changes: 10 additions & 1 deletion app_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
from werkzeug.exceptions import NotFound
from flask_testing import LiveServerTestCase

from app import acme, find_key, static_proxy, index_redirection
from app import (
acme,
find_key,
static_proxy,
index_redirection,
add_feature_policy,
)

from app import ROOT
from app import app
Expand Down Expand Up @@ -41,6 +47,7 @@ def check_security_headers(self, resp):
self.assertTrue("X-XSS-Protection" in headers)
self.assertTrue("X-Content-Type-Options" in headers)
self.assertTrue("Content-Security-Policy" in headers)
self.assertTrue("Feature-Policy" in headers)
self.assertEqual(headers["X-Frame-Options"], "SAMEORIGIN")

def test_index_redirection_req(self):
Expand Down Expand Up @@ -109,6 +116,7 @@ def test_acme(self):
def test_index_redirection(self):
"""Test index page redirection."""
resp = index_redirection()
add_feature_policy(resp)
self.assertEqual(resp.status_code, 200)
resp.close()

Expand All @@ -119,6 +127,7 @@ def test_static_proxy(self):
for h in htmls:
u = "notes/" + h
resp = static_proxy(u)
add_feature_policy(resp)
self.assertEqual(resp.status_code, 200)
resp.close()

Expand Down

0 comments on commit a57b63f

Please sign in to comment.