Finalize audit: strict env validation, nginx headers, bookmark cleanup, admin stats fix
This commit is contained in:
@@ -50,8 +50,8 @@ export default function AdminDashboard() {
|
|||||||
|
|
||||||
// Compute stats locally
|
// Compute stats locally
|
||||||
const total = usersArray.length;
|
const total = usersArray.length;
|
||||||
const pendingP = usersArray.filter(u => u.pending_personal > 0).length;
|
const pendingP = usersArray.reduce((acc, u) => acc + (u.pending_personal || 0), 0);
|
||||||
const pendingB = usersArray.filter(u => u.pending_business > 0).length;
|
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;
|
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 });
|
setStats({ total_users: total, pending_personal: pendingP, pending_business: pendingB, admins: admins });
|
||||||
|
|||||||
+8
-5
@@ -1,9 +1,12 @@
|
|||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
server_name aicpa.duckdns.org 13.140.170.213;
|
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)
|
# Redirect all HTTP traffic to HTTPS (uncomment when SSL certs are generated)
|
||||||
# location / {
|
# location / {
|
||||||
# return 301 https://$host$request_uri;
|
# return 301 https://$host$request_uri;
|
||||||
@@ -58,7 +61,7 @@ server {
|
|||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
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_set_header X-Forwarded-Proto $scheme;
|
||||||
# Allow larger responses for file downloads
|
# Allow larger responses for file downloads
|
||||||
proxy_buffering off;
|
proxy_buffering off;
|
||||||
@@ -71,7 +74,7 @@ server {
|
|||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
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_set_header X-Forwarded-Proto $scheme;
|
||||||
proxy_read_timeout 60s;
|
proxy_read_timeout 60s;
|
||||||
proxy_send_timeout 60s;
|
proxy_send_timeout 60s;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from fastapi import FastAPI, HTTPException
|
from fastapi import FastAPI, HTTPException
|
||||||
@@ -11,6 +12,12 @@ from app.limiter import limiter
|
|||||||
from app import models
|
from app import models
|
||||||
from app.db import engine
|
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")
|
log = logging.getLogger("uvicorn.error")
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
|
|
||||||
|
|||||||
@@ -1081,12 +1081,27 @@ def delete_user_completely(
|
|||||||
db.query(ChatMessage).filter(ChatMessage.session_id == session.id).delete()
|
db.query(ChatMessage).filter(ChatMessage.session_id == session.id).delete()
|
||||||
db.query(ChatSession).filter(ChatSession.user_id == user_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
|
# Manual cleanup for other tables without reliable ON DELETE CASCADE in older SQLite schemas
|
||||||
from app.models import FilingDeadline, DocumentReviewEvent, AdminDocumentBookmark
|
from app.models import FilingDeadline, DocumentReviewEvent, AdminDocumentBookmark
|
||||||
db.query(FilingDeadline).filter(FilingDeadline.user_id == user_id).delete()
|
db.query(FilingDeadline).filter(FilingDeadline.user_id == user_id).delete()
|
||||||
db.query(DocumentReviewEvent).filter(DocumentReviewEvent.owner_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()
|
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
|
# Delete embeddings
|
||||||
try:
|
try:
|
||||||
delete_user_embeddings(user_id)
|
delete_user_embeddings(user_id)
|
||||||
|
|||||||
@@ -56,7 +56,8 @@ def seed_data():
|
|||||||
name=user_data["name"],
|
name=user_data["name"],
|
||||||
email=user_data["email"],
|
email=user_data["email"],
|
||||||
hashed_password=crud.hash_password(password),
|
hashed_password=crud.hash_password(password),
|
||||||
role=UserRole.user
|
role=UserRole.user,
|
||||||
|
is_verified=True
|
||||||
)
|
)
|
||||||
db.add(new_user)
|
db.add(new_user)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|||||||
Reference in New Issue
Block a user