Skip to content

Commit fd340e0

Browse files
claude[bot]yangm2
andcommitted
fix: implement CORS security to prevent unauthorized cross-origin requests
- Add Flask-CORS dependency to pyproject.toml - Configure strict origin allowlist for tenantfirstaid.com domains - Add development localhost origins when ENV=dev - Enable credentials support for session handling - Reject requests from unauthorized origins at server level Fixes #94 Co-authored-by: yangm2 <[email protected]>
1 parent 367110c commit fd340e0

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

backend/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "0.2.0"
44
requires-python = ">=3.12"
55
dependencies = [
66
"flask>=3.1.1",
7+
"flask-cors>=4.0.0",
78
"valkey>=6.1.0",
89
"gunicorn>=23.0.0",
910
"google-auth>=2.40.3",

backend/tenantfirstaid/app.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from pathlib import Path
22
from flask import Flask, jsonify, session
3+
from flask_cors import CORS
34
import os
45
import secrets
56

@@ -16,6 +17,23 @@
1617

1718
app = Flask(__name__)
1819

20+
# Configure CORS with strict origin validation
21+
ALLOWED_ORIGINS = [
22+
"https://tenantfirstaid.com",
23+
"https://www.tenantfirstaid.com",
24+
]
25+
26+
# Add localhost origins for development
27+
if os.getenv("ENV", "dev") == "dev":
28+
ALLOWED_ORIGINS.extend([
29+
"http://localhost:3000",
30+
"http://127.0.0.1:3000",
31+
"http://localhost:5173", # Vite default
32+
"http://127.0.0.1:5173",
33+
])
34+
35+
CORS(app, origins=ALLOWED_ORIGINS, supports_credentials=True)
36+
1937
# Configure Flask sessions
2038
app.secret_key = os.getenv("FLASK_SECRET_KEY", secrets.token_hex(32))
2139
app.config["SESSION_COOKIE_HTTPONLY"] = True

0 commit comments

Comments
 (0)