Skip to content

Commit fb86989

Browse files
authored
Merge pull request #15 from kclapper/headers
Security Headers Added and FLASK_ENV Added Closes #11 and closes #14
2 parents 2fc9a34 + f045311 commit fb86989

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

badstats/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ def create_app(test_config=None):
1313
app.config.from_mapping(
1414
SECRET_KEY=os.environ["FLASK_SECRET"],
1515
DATABASE=database,
16+
SESSION_COOKIE_SECURE=True,
17+
SESSION_COOKIE_SAMESITE='Strict'
1618
)
1719

1820
if test_config is None:
@@ -41,6 +43,22 @@ def create_app(test_config=None):
4143
app.register_blueprint(stats.bp)
4244
app.add_url_rule('/', endpoint='index')
4345

46+
@app.after_request
47+
def setSecureHeaders(response):
48+
headers = {
49+
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
50+
'Content-Security-Policy': "default-src 'self'; script-src 'self';\
51+
img-src 'self' https://*.scdn.co data: ;",
52+
'X-Content-Type-Options': 'nosniff',
53+
'X-Frame-Options': 'SAMEORIGIN',
54+
55+
56+
}
57+
58+
response.headers.update(headers)
59+
60+
return response
61+
4462
return app
4563

4664
def getHostname():

k8s-manifests/badstats.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ spec:
5252
secretKeyRef:
5353
name: badstats
5454
key: flask_secret
55+
- name: FLASK_ENV
56+
value: "production"
5557
volumeMounts:
5658
- mountPath: /usr/src/app/instance
5759
name: data

0 commit comments

Comments
 (0)