diff --git a/frontend/src/pages/AdminDashboard.jsx b/frontend/src/pages/AdminDashboard.jsx index 1aeb211..f36f73b 100644 --- a/frontend/src/pages/AdminDashboard.jsx +++ b/frontend/src/pages/AdminDashboard.jsx @@ -50,8 +50,8 @@ export default function AdminDashboard() { // Compute stats locally const total = usersArray.length; - const pendingP = usersArray.filter(u => u.pending_personal > 0).length; - const pendingB = usersArray.filter(u => u.pending_business > 0).length; + const pendingP = usersArray.reduce((acc, u) => acc + (u.pending_personal || 0), 0); + const pendingB = usersArray.reduce((acc, u) => acc + (u.pending_business || 0), 0); const admins = usersArray.filter(u => u.role === "admin" || u.role === "super_admin").length; setStats({ total_users: total, pending_personal: pendingP, pending_business: pendingB, admins: admins }); diff --git a/nginx/default.conf b/nginx/default.conf index 2c29ba0..6dfd459 100644 --- a/nginx/default.conf +++ b/nginx/default.conf @@ -1,9 +1,12 @@ server { listen 80; server_name aicpa.duckdns.org 13.140.170.213; - - - + # Security Headers + add_header X-Frame-Options "SAMEORIGIN" always; + add_header X-XSS-Protection "1; mode=block" always; + add_header X-Content-Type-Options "nosniff" always; + add_header Referrer-Policy "strict-origin-when-cross-origin" always; + add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline' 'unsafe-eval';" always; # Redirect all HTTP traffic to HTTPS (uncomment when SSL certs are generated) # location / { # return 301 https://$host$request_uri; @@ -58,7 +61,7 @@ server { proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; # Allow larger responses for file downloads proxy_buffering off; @@ -71,7 +74,7 @@ server { proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_read_timeout 60s; proxy_send_timeout 60s; diff --git a/services/api/app/main.py b/services/api/app/main.py index 3171177..aa2afa8 100644 --- a/services/api/app/main.py +++ b/services/api/app/main.py @@ -1,4 +1,5 @@ import os +import sys import logging from pathlib import Path from fastapi import FastAPI, HTTPException @@ -11,6 +12,12 @@ from app.limiter import limiter from app import models from app.db import engine +import subprocess +try: + subprocess.run([sys.executable, "validate_env.py"], check=True) +except subprocess.CalledProcessError: + sys.exit(1) + log = logging.getLogger("uvicorn.error") from contextlib import asynccontextmanager diff --git a/services/api/app/routers/upload.py b/services/api/app/routers/upload.py index 8d16e17..5f94295 100644 --- a/services/api/app/routers/upload.py +++ b/services/api/app/routers/upload.py @@ -1081,11 +1081,26 @@ def delete_user_completely( db.query(ChatMessage).filter(ChatMessage.session_id == session.id).delete() db.query(ChatSession).filter(ChatSession.user_id == user_id).delete() + # Collect IDs for bookmarks cleanup + p_doc_ids = [doc.id for doc in db.query(PersonalDocument).filter(PersonalDocument.user_id == user_id).all()] + b_doc_ids = [doc.id for doc in db.query(BusinessDocument).filter(BusinessDocument.user_id == user_id).all()] + a_doc_ids = [doc.id for doc in db.query(AdminDocument).filter(AdminDocument.user_id == user_id).all()] + # Manual cleanup for other tables without reliable ON DELETE CASCADE in older SQLite schemas from app.models import FilingDeadline, DocumentReviewEvent, AdminDocumentBookmark db.query(FilingDeadline).filter(FilingDeadline.user_id == user_id).delete() db.query(DocumentReviewEvent).filter(DocumentReviewEvent.owner_user_id == user_id).delete() + + # Delete bookmarks created by this user db.query(AdminDocumentBookmark).filter(AdminDocumentBookmark.admin_id == user_id).delete() + + # Delete bookmarks pointing to this user's documents + if p_doc_ids: + db.query(AdminDocumentBookmark).filter(AdminDocumentBookmark.doc_kind == "personal", AdminDocumentBookmark.doc_id.in_(p_doc_ids)).delete(synchronize_session=False) + if b_doc_ids: + db.query(AdminDocumentBookmark).filter(AdminDocumentBookmark.doc_kind == "business", AdminDocumentBookmark.doc_id.in_(b_doc_ids)).delete(synchronize_session=False) + if a_doc_ids: + db.query(AdminDocumentBookmark).filter(AdminDocumentBookmark.doc_kind == "admin", AdminDocumentBookmark.doc_id.in_(a_doc_ids)).delete(synchronize_session=False) # Delete embeddings try: diff --git a/services/api/seed_mock_users.py b/services/api/seed_mock_users.py index d207f7e..68d2822 100644 --- a/services/api/seed_mock_users.py +++ b/services/api/seed_mock_users.py @@ -56,7 +56,8 @@ def seed_data(): name=user_data["name"], email=user_data["email"], hashed_password=crud.hash_password(password), - role=UserRole.user + role=UserRole.user, + is_verified=True ) db.add(new_user) db.commit()