Attempt to mitigate errors w/ HTTPS

This commit is contained in:
kittentm 2026-02-20 04:44:33 +01:00
commit f5249ae489
4 changed files with 15 additions and 20 deletions

View file

@ -5,14 +5,14 @@ class Settings(BaseSettings):
port: int = 5000 port: int = 5000
db_url: str db_url: str
fernet_key: str fernet_key: str
cookie_httponly: bool = False cookie_httponly: bool = True
frontend_url: str frontend_url: str
boss_url: str boss_url: str
boss_aes_key: str boss_aes_key: str
boss_hmac_key: str boss_hmac_key: str
model_config = SettingsConfigDict(env_file=".env", extra="ignore") model_config = SettingsConfigDict(env_file=".env", extra="ignore")
cookie_secure: bool = False cookie_secure: bool = True
settings = Settings() settings = Settings()
cipher = Fernet(settings.fernet_key.encode()) cipher = Fernet(settings.fernet_key.encode())

View file

@ -23,6 +23,7 @@ class Session(Base):
engine = create_engine(settings.db_url, pool_pre_ping=True) engine = create_engine(settings.db_url, pool_pre_ping=True)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# TODO: look into why this is being called twice on startup
def init_db(): def init_db():
try: try:
Base.metadata.create_all(bind=engine) Base.metadata.create_all(bind=engine)

24
main.py
View file

@ -10,17 +10,6 @@ from services.boss_retrieval import process_boss_file
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
import asyncio import asyncio
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=[settings.frontend_url],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
expose_headers=["Set-Cookie"],
)
async def boss_worker_loop(): async def boss_worker_loop():
print("background worker started") print("background worker started")
while True: while True:
@ -29,10 +18,6 @@ async def boss_worker_loop():
process_boss_file() process_boss_file()
except Exception as e: except Exception as e:
print(f"worker error: {e}") print(f"worker error: {e}")
# TODO: actually sync to what schedule says.
# for now its set to 1hr just incase pretendo fuckery happens
# (such as rotation ending)
await asyncio.sleep(3600) await asyncio.sleep(3600)
@asynccontextmanager @asynccontextmanager
@ -44,6 +29,15 @@ async def lifespan(app: FastAPI):
app = FastAPI(lifespan=lifespan) app = FastAPI(lifespan=lifespan)
app.add_middleware(
CORSMiddleware,
allow_origins=[settings.frontend_url],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
expose_headers=["Set-Cookie"],
)
@app.middleware("http") @app.middleware("http")
async def force_cors_on_errors(request: Request, call_next): async def force_cors_on_errors(request: Request, call_next):
response = await call_next(request) response = await call_next(request)

View file

@ -83,8 +83,8 @@ async def login(
key="session_id", key="session_id",
value=active_session.id, value=active_session.id,
httponly=settings.cookie_httponly, httponly=settings.cookie_httponly,
secure=False, secure=settings.cookie_secure,
samesite="lax", samesite="none",
path="/", path="/",
max_age=cookie_age, max_age=cookie_age,
domain=None domain=None