Skip to content

Commit a00231a

Browse files
authored
fix: LEAP-1997: make CORS configurable via env (#7448)
1 parent 59feca7 commit a00231a

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

deploy/default.conf

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ http {
4040
'"content_type":"$content_type",'
4141
'"useragent":"$http_user_agent",'
4242
'"referrer":"$http_referer",'
43+
'"origin":"$http_origin",'
4344
'"x_forwarded_for":"$http_x_forwarded_for",'
4445
'"url":"$request_uri",'
4546
'"version":"$server_protocol",'

label_studio/core/settings/base.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,15 @@
275275
'127.0.0.1',
276276
'localhost',
277277
]
278-
CORS_ORIGIN_ALLOW_ALL = True
278+
279+
# Typical secure configuration is simply set CORS_ALLOW_ALL_ORIGINS = False in the env
280+
if allowed_origins := get_env_list('CORS_ALLOWED_ORIGINS'):
281+
CORS_ALLOWED_ORIGINS = allowed_origins
282+
elif allowed_origin_regexes := get_env_list('CORS_ALLOWED_ORIGIN_REGEXES'):
283+
CORS_ALLOWED_ORIGIN_REGEXES = allowed_origin_regexes
284+
else:
285+
CORS_ALLOW_ALL_ORIGINS = get_bool_env('CORS_ALLOW_ALL_ORIGINS', True)
286+
279287
CORS_ALLOW_METHODS = [
280288
'DELETE',
281289
'GET',

poetry.lock

+7-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ django-environ = "0.10.0"
167167
django-filter = "24.3"
168168
django-model-utils = "4.1.1"
169169
django-rq = "^2.10.2"
170-
django-cors-headers = "3.6.0"
170+
django-cors-headers = "4.7.0"
171171
django-extensions = "3.2.3"
172172
django-user-agents = "0.4.0"
173173
django-ranged-fileresponse = ">=0.1.2"

0 commit comments

Comments
 (0)