Skip to content

Commit d718ecf

Browse files
committed
Provide a configuration option to control automatic option responses
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.
1 parent 0ce2727 commit d718ecf

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

CHANGES.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
Version 3.1.0
22
-------------
33

4-
Unreleased
4+
- Provide a configuration option to control automatic option
5+
responses. :pr:`5496`
56

67

78
Version 3.0.3

docs/config.rst

+10
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@ The following configuration values are used internally by Flask:
280280
``4093``. Larger cookies may be silently ignored by browsers. Set to
281281
``0`` to disable the warning.
282282

283+
.. py:data:: PROVIDE_AUTOMATIC_OPTIONS
284+
285+
Set to ``False`` to disable the automatic addition of OPTIONS
286+
responses. This can be overridden per route by altering the
287+
``provide_automatic_options`` attribute.
288+
283289
.. versionadded:: 0.4
284290
``LOGGER_NAME``
285291

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

340+
.. versionadded:: 3.10
341+
Added :data:`PROVIDE_AUTOMATIC_OPTIONS` to control the default
342+
addition of autogenerated OPTIONS responses.
343+
334344

335345
Configuring from Python Files
336346
-----------------------------

src/flask/app.py

+1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ class Flask(App):
198198
"PREFERRED_URL_SCHEME": "http",
199199
"TEMPLATES_AUTO_RELOAD": None,
200200
"MAX_COOKIE_SIZE": 4093,
201+
"PROVIDE_AUTOMATIC_OPTIONS": True,
201202
}
202203
)
203204

src/flask/sansio/app.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ def add_url_rule(
638638
)
639639

640640
if provide_automatic_options is None:
641-
if "OPTIONS" not in methods:
641+
if "OPTIONS" not in methods and self.config["PROVIDE_AUTOMATIC_OPTIONS"]:
642642
provide_automatic_options = True
643643
required_methods.add("OPTIONS")
644644
else:

0 commit comments

Comments
 (0)