Skip to content

Commit

Permalink
Restricted register endpoint to LocalHost only
Browse files Browse the repository at this point in the history
  • Loading branch information
hilfing committed Jul 28, 2024
1 parent ee3e2c7 commit 74d8577
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Binary file added commit_history.txt
Binary file not shown.
11 changes: 10 additions & 1 deletion server/routers/auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastapi import APIRouter, Depends, HTTPException, status
from fastapi import APIRouter, Depends, HTTPException, status, Request
from pydantic import UUID4
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.future import select
Expand All @@ -16,9 +16,18 @@

@router.post("/register", response_model=auth.schemas.User)
async def register_user(
request: Request,
user: auth.schemas.UserCreate,
db: AsyncSession = Depends(database.get_db)
):
# Check if the request is coming from localhost
client_host = request.client.host
if client_host not in ['127.0.0.1', 'localhost', '::1']:
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="Access Restricted"
)

# Check if the user already exists
result = await db.execute(select(auth.models.User).filter_by(username=user.username))
existing_user = result.scalars().first()
Expand Down

0 comments on commit 74d8577

Please sign in to comment.