Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
|
| 2 |
-
from flask import Flask, render_template_string, request, redirect, url_for, send_file, flash, jsonify
|
| 3 |
import json
|
| 4 |
import os
|
| 5 |
import logging
|
|
@@ -43,7 +43,22 @@ STATUS_MAP_RU = {
|
|
| 43 |
|
| 44 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 45 |
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
def download_db_from_hf(specific_file=None, retries=DOWNLOAD_RETRIES, delay=DOWNLOAD_DELAY):
|
| 49 |
if not HF_TOKEN_READ and not HF_TOKEN_WRITE:
|
|
|
|
| 1 |
|
| 2 |
+
from flask import Flask, render_template_string, request, redirect, url_for, send_file, flash, jsonify, Response
|
| 3 |
import json
|
| 4 |
import os
|
| 5 |
import logging
|
|
|
|
| 43 |
|
| 44 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 45 |
|
| 46 |
+
@app.after_request
|
| 47 |
+
def add_security_headers(response: Response) -> Response:
|
| 48 |
+
response.headers['Strict-Transport-Security'] = 'max-age=31536000; includeSubDomains'
|
| 49 |
+
csp = (
|
| 50 |
+
"default-src 'self'; "
|
| 51 |
+
"script-src 'self' 'unsafe-inline' https://cdnjs.cloudflare.com; "
|
| 52 |
+
"style-src 'self' 'unsafe-inline' https://cdnjs.cloudflare.com https://fonts.googleapis.com; "
|
| 53 |
+
"img-src 'self' data: https://huggingface.co https://via.placeholder.com; "
|
| 54 |
+
"font-src 'self' https://cdnjs.cloudflare.com https://fonts.gstatic.com; "
|
| 55 |
+
"frame-ancestors 'none';"
|
| 56 |
+
)
|
| 57 |
+
response.headers['Content-Security-Policy'] = csp
|
| 58 |
+
response.headers['X-Frame-Options'] = 'SAMEORIGIN'
|
| 59 |
+
response.headers['X-Content-Type-Options'] = 'nosniff'
|
| 60 |
+
response.headers['Referrer-Policy'] = 'strict-origin-when-cross-origin'
|
| 61 |
+
return response
|
| 62 |
|
| 63 |
def download_db_from_hf(specific_file=None, retries=DOWNLOAD_RETRIES, delay=DOWNLOAD_DELAY):
|
| 64 |
if not HF_TOKEN_READ and not HF_TOKEN_WRITE:
|