Skip to content

Commit

Permalink
Fix/remove cors whitelist (#416)
Browse files Browse the repository at this point in the history
  • Loading branch information
RaoHai authored Sep 26, 2024
2 parents c320e7c + 03a5cd5 commit 28b936e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
9 changes: 5 additions & 4 deletions server/auth/middleware.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import traceback
from typing import Awaitable, Callable
from fastapi import HTTPException, Request, status
from fastapi.responses import JSONResponse
Expand Down Expand Up @@ -33,18 +34,18 @@ class AuthMiddleWare(BaseHTTPMiddleware):
async def oauth(self, request: Request):
try:
referer = request.headers.get('referer')
origin = request.headers.get('origin')
if referer and referer.startswith(WEB_URL):
return True

token = await oauth2_scheme(request=request)

if token:
bot_dao = BotDAO()
bot = bot_dao.get_bot(bot_id=token)
return bot and (
"*" in bot.domain_whitelist
or
referer in bot.domain_whitelist
origin in bot.domain_whitelist
)
except HTTPException:
return False
Expand All @@ -65,7 +66,7 @@ async def dispatch(self, request: Request, call_next: Callable[[Request], Awaita
return await call_next(request)

# 获取 session 中的用户信息
user = request.session.get("user")
user = request.session.get("user")
if not user:
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Unauthorized")

Expand All @@ -78,7 +79,7 @@ async def dispatch(self, request: Request, call_next: Callable[[Request], Awaita

return await call_next(request)
except HTTPException as e:

print(traceback.format_exception(e))
# 处理 HTTP 异常
return JSONResponse(status_code=e.status_code, content={"detail": e.detail})
except Exception as e:
Expand Down
1 change: 0 additions & 1 deletion template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ Resources:
MemorySize: 512
Environment:
Variables:
CORS_ORIGIN_WHITELIST: https://petercat.ai,https://www.petercat.ai
AWS_LWA_INVOKE_MODE: RESPONSE_STREAM
PETERCAT_ENV: !Ref PetercatEnv
AWS_GITHUB_SECRET_NAME: !Ref AWSGithubSecretName
Expand Down

0 comments on commit 28b936e

Please sign in to comment.