Update app.py
Browse files
app.py
CHANGED
|
@@ -308,50 +308,50 @@ class WebsiteAnalyzer:
|
|
| 308 |
|
| 309 |
results = {}
|
| 310 |
for header, name in security_headers.items
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
|
| 356 |
def _get_header_recommendation(self, header):
|
| 357 |
recommendations = {
|
|
|
|
| 308 |
|
| 309 |
results = {}
|
| 310 |
for header, name in security_headers.items
|
| 311 |
+
def _check_security_headers(self, url):
|
| 312 |
+
try:
|
| 313 |
+
response = requests.get(url)
|
| 314 |
+
headers = response.headers
|
| 315 |
+
|
| 316 |
+
security_headers = {
|
| 317 |
+
'Strict-Transport-Security': 'HSTS',
|
| 318 |
+
'Content-Security-Policy': 'CSP',
|
| 319 |
+
'X-Frame-Options': 'X-Frame',
|
| 320 |
+
'X-Content-Type-Options': 'X-Content-Type',
|
| 321 |
+
'X-XSS-Protection': 'XSS Protection',
|
| 322 |
+
'Referrer-Policy': 'Referrer Policy',
|
| 323 |
+
'Permissions-Policy': 'Permissions Policy',
|
| 324 |
+
'Cross-Origin-Embedder-Policy': 'COEP',
|
| 325 |
+
'Cross-Origin-Opener-Policy': 'COOP',
|
| 326 |
+
'Cross-Origin-Resource-Policy': 'CORP'
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
results = {}
|
| 330 |
+
score = 100
|
| 331 |
+
recommendations = []
|
| 332 |
+
|
| 333 |
+
for header, name in security_headers.items(): # Fixed here: added () to items
|
| 334 |
+
if header in headers:
|
| 335 |
+
results[name] = {
|
| 336 |
+
"موجود": "✅",
|
| 337 |
+
"القيمة": headers[header]
|
| 338 |
+
}
|
| 339 |
+
else:
|
| 340 |
+
results[name] = {
|
| 341 |
+
"موجود": "❌",
|
| 342 |
+
"التوصية": self._get_header_recommendation(header)
|
| 343 |
+
}
|
| 344 |
+
score -= 10
|
| 345 |
+
recommendations.append(f"إضافة رأس {name}")
|
| 346 |
|
| 347 |
+
return {
|
| 348 |
+
"الرؤوس الموجودة": results,
|
| 349 |
+
"درجة الأمان": f"{max(score, 0)}/100",
|
| 350 |
+
"التوصيات": recommendations,
|
| 351 |
+
"المستوى العام": self._get_security_level(score)
|
| 352 |
+
}
|
| 353 |
+
except Exception as e:
|
| 354 |
+
return {"error": f"خطأ في فحص رؤوس الأمان: {str(e)}"}
|
| 355 |
|
| 356 |
def _get_header_recommendation(self, header):
|
| 357 |
recommendations = {
|