Skip to content

Commit fa1ca36

Browse files
Added secweb to fix security issues
1 parent 82be95b commit fa1ca36

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

backend/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,4 @@ sentence-transformers==3.0.1
179179
google-cloud-logging==3.10.0
180180
PyMuPDF==1.24.5
181181
pypandoc==1.13
182+
Secweb==1.11.0

backend/score.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
from datetime import datetime, timezone
2727
import time
2828
import gc
29+
from Secweb import SecWeb
30+
from Secweb.StrictTransportSecurity import HSTS
31+
from Secweb.ContentSecurityPolicy import ContentSecurityPolicy
32+
from Secweb.XContentTypeOptions import XContentTypeOptions
33+
from Secweb.XFrameOptions import XFrame
2934

3035
logger = CustomLogger()
3136
CHUNK_DIR = os.path.join(os.path.dirname(__file__), "chunks")
@@ -42,6 +47,11 @@ def sick():
4247
return False
4348

4449
app = FastAPI()
50+
SecWeb(app=app, Option={'referrer': False, 'xframe': False})
51+
app.add_middleware(HSTS, Option={'max-age': 4, 'preload': True})
52+
app.add_middleware(ContentSecurityPolicy, Option={'default-src': ["'self'"], 'base-uri': ["'self'"], 'block-all-mixed-content': []}, script_nonce=False, style_nonce=False, report_only=False)
53+
app.add_middleware(XContentTypeOptions)
54+
app.add_middleware(XFrame, Option={'X-Frame-Options': 'DENY'})
4555

4656
app.add_middleware(
4757
CORSMiddleware,

0 commit comments

Comments
 (0)