YTShortMakerArchx commited on
Commit
28693fa
·
verified ·
1 Parent(s): 76db87d

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +13 -14
main.py CHANGED
@@ -27,8 +27,8 @@ from pydantic import BaseModel, Field
27
  # =============================================================================
28
  HF_DATASET = os.getenv("HF_DATASET", "YTShortMakerArchx/BG_VIDS_ARCHX_YT")
29
  HF_TOKEN = os.getenv("HF_TOKEN")
30
- APP_KEY = os.getenv("APP_KEY", "archx_3f9d15f52n48d41h5fj8a7e2b_private")
31
- UI_ORIGIN = os.getenv("UI_ORIGIN", "https://shortgen-archx.pages.dev")
32
 
33
  BASE_DIR = Path("/tmp")
34
  AUDIO_DIR = BASE_DIR / "audio"
@@ -176,13 +176,10 @@ app = FastAPI(
176
  app.add_middleware(
177
  CORSMiddleware,
178
  allow_origins=[
179
- UI_ORIGIN,
180
- "http://localhost:3000",
181
- "http://127.0.0.1:3000",
182
- "http://127.0.0.1:5500",
183
- "http://localhost:5500",
184
- "http://localhost:8000",
185
- "https://huggingface.co",
186
  ],
187
  allow_credentials=True,
188
  allow_methods=["GET", "POST", "DELETE", "OPTIONS", "HEAD"],
@@ -217,13 +214,15 @@ def validate_origin(req: Request) -> bool:
217
  origin = req.headers.get("origin") or req.headers.get("referer", "")
218
  if not origin:
219
  return True
 
220
  allowed = [
221
- "https://shortgen-archx.pages.dev",
222
- "http://localhost:3000", "http://127.0.0.1:3000",
223
- "http://localhost:5500", "http://127.0.0.1:5500",
224
- "https://huggingface.co",
225
  ]
226
- return any(origin.startswith(a) for a in allowed)
 
227
 
228
  def rate_limit(key: str, limit: int, window: int = 3600) -> bool:
229
  now = time.time()
 
27
  # =============================================================================
28
  HF_DATASET = os.getenv("HF_DATASET", "YTShortMakerArchx/BG_VIDS_ARCHX_YT")
29
  HF_TOKEN = os.getenv("HF_TOKEN")
30
+ APP_KEY = os.getenv("APP_KEY")
31
+ UI_ORIGIN = os.getenv("UI_ORIGIN", "http://shortgenx.pages.dev")
32
 
33
  BASE_DIR = Path("/tmp")
34
  AUDIO_DIR = BASE_DIR / "audio"
 
176
  app.add_middleware(
177
  CORSMiddleware,
178
  allow_origins=[
179
+ "https://shortgenx.pages.dev", # Your website
180
+ "http://localhost:3000", # Local dev only port 3000
181
+ "http://127.0.0.1:3000", # Local dev only port 3000
182
+ "https://ytshortmakerarchx-archnemix-controller.hf.space", # Controller space
 
 
 
183
  ],
184
  allow_credentials=True,
185
  allow_methods=["GET", "POST", "DELETE", "OPTIONS", "HEAD"],
 
214
  origin = req.headers.get("origin") or req.headers.get("referer", "")
215
  if not origin:
216
  return True
217
+ # Strict allowed origins - exact match only
218
  allowed = [
219
+ "https://shortgenx.pages.dev",
220
+ "http://localhost:3000",
221
+ "http://127.0.0.1:3000",
222
+ "https://ytshortmakerarchx-archnemix-controller.hf.space",
223
  ]
224
+ # Use exact match, not prefix matching
225
+ return origin in allowed
226
 
227
  def rate_limit(key: str, limit: int, window: int = 3600) -> bool:
228
  now = time.time()