Skip to content

Commit fb8e81d

Browse files
committed
Restrict HTTP methods and headers with CORS
1 parent 1312d47 commit fb8e81d

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

  • backend/src/acidwatch_api

backend/src/acidwatch_api/app.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,14 @@
5151

5252
fastapi_app.include_router(router)
5353

54+
# Fail if origin misconfigured
55+
if any(origin == "*" for origin in origins):
56+
raise RuntimeError("Wildcard CORS origin '*' is not allowed with credentials")
57+
5458
app = CORSMiddleware(
5559
fastapi_app,
5660
allow_origins=origins,
5761
allow_credentials=True,
58-
allow_methods=["*"],
59-
allow_headers=["*"],
62+
allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"],
63+
allow_headers=["Authorization", "Content-Type"],
6064
)

0 commit comments

Comments
 (0)