Spaces:
Paused
Paused
dushyantsingh0 commited on
Commit ·
4150e03
1
Parent(s): fb5bde6
fix: restore access for existing sessions by using database-backed role checks
Browse files118 unmodified lines1191201211221231241251261 unmodified line128129130131132133134118 unmodified linesraise credentials_exception# --- STRICT PORTAL ISOLATION (Backend Guard) ---from models.user import UserRoleif portal == "internal" and active_role not in [UserRole.SC_AGENT, UserRole.SC_LEAD, UserRole.SC_ADMIN]:# Log this attempt for security auditimport logginglogging.getLogger("security").warning(f"BLOCKED: Customer {user.email} attempted internal portal API access")1 unmodified linestatus_code=status.HTTP_403_FORBIDDEN,detail="Access Denied: Customers cannot access internal operations endpoints.")elif portal == "customer" and active_role not in [UserRole.CUSTOMER_ADMIN, UserRole.CUSTOMER_USER, UserRole.SC_ADMIN]:# Staff can only access the customer portal if they are SC_ADMIN (Super Admin)raise HTTPException(status_code=status.HTTP_403_FORBIDDEN,118 unmodified lines1191201211221231241251261271 unmodified line129130131132133134135118 unmodified linesraise credentials_exception# --- STRICT PORTAL ISOLATION (Backend Guard) ---# We use user.role (fetched from DB) to handle existing sessions that lack the 'role' claim in JWTfrom models.user import UserRoleif portal == "internal" and user.role not in [UserRole.SC_AGENT, UserRole.SC_LEAD, UserRole.SC_ADMIN]:# Log this attempt for security auditimport logginglogging.getLogger("security").warning(f"BLOCKED: Customer {user.email} attempted internal portal API access")1 unmodified linestatus_code=status.HTTP_403_FORBIDDEN,detail="Access Denied: Customers cannot access internal operations endpoints.")elif portal == "customer" and user.role not in [UserRole.CUSTOMER_ADMIN, UserRole.CUSTOMER_USER, UserRole.SC_ADMIN]:# Staff can only access the customer portal if they are SC_ADMIN (Super Admin)raise HTTPException(status_code=status.HTTP_403_FORBIDDEN,
core/deps.py+3-2