Skip to content

Commit

Permalink
Merge 12a3327 into 7435b91
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad-Wahid committed Dec 7, 2023
2 parents 7435b91 + 12a3327 commit 52ee493
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions documentation/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ FLEXMEASURES_JS_VERSIONS

Default: ``{"vega": "5.22.1", "vegaembed": "6.20.8", "vegalite": "5.2.0"}``

FLEXMEASURES_ENFORCE_SECURE_CONTENT_POLICY
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

When ``FLEXMEASURES_ENFORCE_SECURE_CONTENT_POLICY`` is set to ``true``, insecure ``http`` connections are automatically upgraded to secure ``https``.

Default: ``False``

Timing
------
Expand Down
3 changes: 3 additions & 0 deletions flexmeasures/ui/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
</title>
{% endblock head %}
<meta charset="windows-1252">
{% if FLEXMEASURES_ENFORCE_SECURE_CONTENT_POLICY == true %}
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
{% endif %}
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
Expand Down
3 changes: 3 additions & 0 deletions flexmeasures/ui/utils/view_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
def render_flexmeasures_template(html_filename: str, **variables):
"""Render template and add all expected template variables, plus the ones given as **variables."""
variables["flask_env"] = current_app.env
variables["FLEXMEASURES_ENFORCE_SECURE_CONTENT_POLICY"] = current_app.config.get(
"FLEXMEASURES_ENFORCE_SECURE_CONTENT_POLICY"
)
variables["documentation_exists"] = False
if os.path.exists(
"%s/static/documentation/html/index.html" % flexmeasures_ui.root_path
Expand Down
3 changes: 3 additions & 0 deletions flexmeasures/utils/config_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ class Config(object):
FLEXMEASURES_API_SUNSET_DATE: str | None = None # e.g. 2023-05-01
FLEXMEASURES_API_SUNSET_LINK: str | None = None # e.g. https://flexmeasures.readthedocs.io/en/latest/api/introduction.html#deprecation-and-sunset

# if True, the content could be accessed via HTTPS.
FLEXMEASURES_ENFORCE_SECURE_CONTENT_POLICY: bool = False


# names of settings which cannot be None
# SECRET_KEY is also required but utils.app_utils.set_secret_key takes care of this better.
Expand Down

0 comments on commit 52ee493

Please sign in to comment.