Skip to content

Commit fd61fd5

Browse files
authored
Add Client-Id to allowed CORS headers (#518)
1 parent de1da65 commit fd61fd5

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: '3'
2-
31
services:
42
elasticsearch7:
53
image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1

rorapi/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from dotenv import load_dotenv
1919
from elasticsearch import Elasticsearch, RequestsHttpConnection
2020
from requests_aws4auth import AWS4Auth
21+
from corsheaders.defaults import default_headers
2122
from sentry_sdk.integrations.django import DjangoIntegration
2223

2324
sentry_sdk.init(dsn=os.environ.get('SENTRY_DSN', None),
@@ -144,6 +145,7 @@
144145
USE_TZ = True
145146

146147
CORS_ORIGIN_ALLOW_ALL = True
148+
CORS_ALLOW_HEADERS = list(default_headers) + ['Client-Id']
147149

148150
# Static files (CSS, JavaScript, Images)
149151
# https://docs.djangoproject.com/en/2.2/howto/static-files/
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from django.test import TestCase
2+
3+
4+
class CORSClientIdTestCase(TestCase):
5+
"""Test that CORS preflight allows the Client-Id header."""
6+
7+
def test_preflight_allows_client_id_header(self):
8+
response = self.client.options(
9+
'/v2/organizations/02feahw73',
10+
HTTP_ORIGIN='http://localhost:5173',
11+
HTTP_ACCESS_CONTROL_REQUEST_METHOD='GET',
12+
HTTP_ACCESS_CONTROL_REQUEST_HEADERS='Client-Id',
13+
)
14+
self.assertIn(response.status_code, (200, 204))
15+
allow_headers = response.get('Access-Control-Allow-Headers')
16+
self.assertIsNotNone(allow_headers)
17+
allowed = [h.strip().lower() for h in allow_headers.split(',')]
18+
self.assertIn('client-id', allowed)

0 commit comments

Comments
 (0)