Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MOTO_DISABLE_GLOBAL_CORS for disabling wildcard CORS #8409

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/docs/configuration/environment_variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ The following is a non-exhaustive list of the environment variables that can be
+-------------------------------+----------+-----------+-------------------------------------------------------------------------------------------------+
| MOTO_PRETTIFY_RESPONSES | bool | False | Prettify responses from Moto, making it easier to read and debug. |
+-------------------------------+----------+-----------+-------------------------------------------------------------------------------------------------+
| MOTO_DISABLE_GLOBAL_CORS | bool | False | Disable configuring global wildcard CORS. |
+-------------------------------+----------+-----------+-------------------------------------------------------------------------------------------------+

5 changes: 5 additions & 0 deletions docs/docs/services/s3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ s3
- [X] put_bucket_acl
- [ ] put_bucket_analytics_configuration
- [X] put_bucket_cors

Note that the moto server configures global wildcard CORS settings by default. To avoid this from overriding empty bucket CORS, disable global CORS with an environment variable:

MOTO_DISABLE_GLOBAL_CORS=true

- [X] put_bucket_encryption
- [ ] put_bucket_intelligent_tiering_configuration
- [ ] put_bucket_inventory_configuration
Expand Down
5 changes: 4 additions & 1 deletion moto/moto_server/werkzeug_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from moto.core import DEFAULT_ACCOUNT_ID
from moto.core.base_backend import BackendDict
from moto.core.utils import convert_to_flask_response
from moto.settings import DISABLE_GLOBAL_CORS

from .utilities import AWSTestHelper, RegexConverter

Expand Down Expand Up @@ -272,7 +273,9 @@ def create_backend_app(service: backends.SERVICE_NAMES) -> Flask:
backend_app = Flask("moto", template_folder=template_dir)
backend_app.debug = True
backend_app.service = service # type: ignore[attr-defined]
CORS(backend_app)

if not DISABLE_GLOBAL_CORS:
CORS(backend_app)

# Reset view functions to reset the app
backend_app.view_functions = {}
Expand Down
2 changes: 2 additions & 0 deletions moto/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def is_test_proxy_mode() -> bool:

PRETTIFY_RESPONSES = bool(os.environ.get("MOTO_PRETTIFY_RESPONSES", False))

DISABLE_GLOBAL_CORS = bool(os.environ.get("MOTO_DISABLE_GLOBAL_CORS", False))

# Fully skip test that require docker
SKIP_REQUIRES_DOCKER = bool(os.environ.get("TESTS_SKIP_REQUIRES_DOCKER", False))

Expand Down