Skip to content

Commit

Permalink
Provide a configuration option to control automatic option responses
Browse files Browse the repository at this point in the history
By default Flask will provide responses to OPTIONS requests that are
automatically generated. These responses list the valid methods in the
response headers. Whilst this is useful, it can be frowned on by
auditors hence an ability to disable it wholesale is useful.
  • Loading branch information
pgjones committed Jun 5, 2024
1 parent 0ce2727 commit 4ecd11c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Version 3.1.0
-------------

Unreleased
- Provide a configuration option to control automatic option
responses. :pr:`5496`


Version 3.0.3
Expand Down
10 changes: 10 additions & 0 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ The following configuration values are used internally by Flask:
``4093``. Larger cookies may be silently ignored by browsers. Set to
``0`` to disable the warning.

.. py:data:: PROVIDE_AUTOMATIC_OPTIONS
Set to ``False`` to disable the automatic addition of OPTIONS
responses. This can be overridden per route by altering the
``provide_automatic_options`` attribute.

.. versionadded:: 0.4
``LOGGER_NAME``

Expand Down Expand Up @@ -331,6 +337,10 @@ The following configuration values are used internally by Flask:
.. versionchanged:: 2.3
``ENV`` was removed.

.. versionadded:: 3.10
Added :data:`PROVIDE_AUTOMATIC_OPTIONS` to control the default
addition of autogenerated OPTIONS responses.


Configuring from Python Files
-----------------------------
Expand Down
1 change: 1 addition & 0 deletions src/flask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ class Flask(App):
"PREFERRED_URL_SCHEME": "http",
"TEMPLATES_AUTO_RELOAD": None,
"MAX_COOKIE_SIZE": 4093,
"PROVIDE_AUTOMATIC_OPTIONS": True,
}
)

Expand Down
2 changes: 1 addition & 1 deletion src/flask/sansio/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ def add_url_rule(
)

if provide_automatic_options is None:
if "OPTIONS" not in methods:
if "OPTIONS" not in methods and self.config["PROVIDE_AUTOMATIC_OPTIONS"]:
provide_automatic_options = True
required_methods.add("OPTIONS")
else:
Expand Down

0 comments on commit 4ecd11c

Please sign in to comment.