Skip to content

Commit dfa7b26

Browse files
XD-DENGFokko Driesprong
authored andcommitted
[AIRFLOW-2809] Fix security issue regarding Flask SECRET_KEY
It's recommended by Falsk community to use random SECRET_KEY for security reason. However, in Airflow there is a default value for secret_key and most users will ignore to change it. This may cause security concern. Closes #3651 from XD-DENG/patch-2
1 parent fcd51f3 commit dfa7b26

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

airflow/www/app.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# under the License.
1919
#
2020
import six
21+
import os
2122

2223
from flask import Flask
2324
from flask_admin import Admin, base
@@ -43,9 +44,18 @@
4344

4445

4546
def create_app(config=None, testing=False):
47+
48+
log = LoggingMixin().log
49+
4650
app = Flask(__name__)
4751
app.wsgi_app = ProxyFix(app.wsgi_app)
48-
app.secret_key = configuration.conf.get('webserver', 'SECRET_KEY')
52+
53+
if configuration.conf.get('webserver', 'SECRET_KEY') == "temporary_key":
54+
log.info("SECRET_KEY for Flask App is not specified. Using a random one.")
55+
app.secret_key = os.urandom(16)
56+
else:
57+
app.secret_key = configuration.conf.get('webserver', 'SECRET_KEY')
58+
4959
app.config['LOGIN_DISABLED'] = not configuration.conf.getboolean(
5060
'webserver', 'AUTHENTICATE')
5161

@@ -127,7 +137,6 @@ def create_app(config=None, testing=False):
127137

128138
def integrate_plugins():
129139
"""Integrate plugins to the context"""
130-
log = LoggingMixin().log
131140
from airflow.plugins_manager import (
132141
admin_views, flask_blueprints, menu_links)
133142
for v in admin_views:

0 commit comments

Comments
 (0)