GuardianUnivalle-Benito-Yucra 0.1.28__py3-none-any.whl → 0.1.29__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of GuardianUnivalle-Benito-Yucra might be problematic. Click here for more details.
- GuardianUnivalle_Benito_Yucra/detectores/detector_xss.py +3 -33
- {guardianunivalle_benito_yucra-0.1.28.dist-info → guardianunivalle_benito_yucra-0.1.29.dist-info}/METADATA +1 -1
- {guardianunivalle_benito_yucra-0.1.28.dist-info → guardianunivalle_benito_yucra-0.1.29.dist-info}/RECORD +6 -6
- {guardianunivalle_benito_yucra-0.1.28.dist-info → guardianunivalle_benito_yucra-0.1.29.dist-info}/WHEEL +0 -0
- {guardianunivalle_benito_yucra-0.1.28.dist-info → guardianunivalle_benito_yucra-0.1.29.dist-info}/licenses/LICENSE +0 -0
- {guardianunivalle_benito_yucra-0.1.28.dist-info → guardianunivalle_benito_yucra-0.1.29.dist-info}/top_level.txt +0 -0
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
"""
|
|
2
|
-
detector_xss.py (version separada con IPs confiables independientes)
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
1
|
from __future__ import annotations
|
|
6
2
|
import json
|
|
7
3
|
import logging
|
|
8
4
|
import re
|
|
9
5
|
from typing import List, Tuple
|
|
10
|
-
|
|
11
6
|
from django.conf import settings
|
|
12
|
-
from django.http import JsonResponse
|
|
13
7
|
from django.utils.deprecation import MiddlewareMixin
|
|
14
8
|
|
|
15
9
|
# Logger
|
|
@@ -94,26 +88,24 @@ def extract_payload_text(request) -> str:
|
|
|
94
88
|
class XSSDefenseMiddleware(MiddlewareMixin):
|
|
95
89
|
"""
|
|
96
90
|
Middleware Django que detecta XSS en IPs no confiables.
|
|
91
|
+
Solo marca el ataque en request.sql_attack_info para que
|
|
92
|
+
AuditoriaMiddleware lo registre y bloquee.
|
|
97
93
|
"""
|
|
98
94
|
|
|
99
95
|
def process_request(self, request):
|
|
100
|
-
# 1) Obtener IP confiable específica para XSS
|
|
101
96
|
trusted_ips: List[str] = getattr(settings, "XSS_DEFENSE_TRUSTED_IPS", [])
|
|
102
97
|
ip = request.META.get("REMOTE_ADDR", "")
|
|
103
98
|
if ip in trusted_ips:
|
|
104
99
|
return None # IP confiable → no analizar
|
|
105
100
|
|
|
106
|
-
# 2) Verificar rutas excluidas
|
|
107
101
|
excluded_paths: List[str] = getattr(settings, "XSS_DEFENSE_EXCLUDED_PATHS", [])
|
|
108
102
|
if any(request.path.startswith(p) for p in excluded_paths):
|
|
109
103
|
return None
|
|
110
104
|
|
|
111
|
-
# 3) Extraer payload
|
|
112
105
|
payload = extract_payload_text(request)
|
|
113
106
|
if not payload:
|
|
114
107
|
return None
|
|
115
108
|
|
|
116
|
-
# 4) Detectar XSS
|
|
117
109
|
flagged, matches = detect_xss_text(payload)
|
|
118
110
|
if not flagged:
|
|
119
111
|
return None
|
|
@@ -125,23 +117,7 @@ class XSSDefenseMiddleware(MiddlewareMixin):
|
|
|
125
117
|
payload,
|
|
126
118
|
)
|
|
127
119
|
|
|
128
|
-
#
|
|
129
|
-
if getattr(settings, "XSS_DEFENSE_SANITIZE_INPUT", False):
|
|
130
|
-
try:
|
|
131
|
-
if hasattr(request, "POST"):
|
|
132
|
-
mutable_post = request.POST.copy()
|
|
133
|
-
for k in mutable_post.keys():
|
|
134
|
-
mutable_post[k] = sanitize_input_basic(mutable_post.get(k))
|
|
135
|
-
request.POST = mutable_post
|
|
136
|
-
if hasattr(request, "GET"):
|
|
137
|
-
mutable_get = request.GET.copy()
|
|
138
|
-
for k in mutable_get.keys():
|
|
139
|
-
mutable_get[k] = sanitize_input_basic(mutable_get.get(k))
|
|
140
|
-
request.GET = mutable_get
|
|
141
|
-
except Exception:
|
|
142
|
-
logger.debug("Error sanitizando inputs; continuar")
|
|
143
|
-
|
|
144
|
-
# 6) Registrar ataque en AuditoriaMiddleware
|
|
120
|
+
# Solo marcamos el ataque, no bloqueamos aquí
|
|
145
121
|
request.sql_attack_info = {
|
|
146
122
|
"ip": ip,
|
|
147
123
|
"tipos": ["XSS"],
|
|
@@ -149,12 +125,6 @@ class XSSDefenseMiddleware(MiddlewareMixin):
|
|
|
149
125
|
"payload": payload,
|
|
150
126
|
}
|
|
151
127
|
|
|
152
|
-
# 7) Bloquear petición si está configurado
|
|
153
|
-
if getattr(settings, "XSS_DEFENSE_BLOCK", True):
|
|
154
|
-
return JsonResponse(
|
|
155
|
-
{"mensaje": "Ataque detectado (XSS)", "tipos": matches}, status=403
|
|
156
|
-
)
|
|
157
|
-
|
|
158
128
|
return None
|
|
159
129
|
|
|
160
130
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: GuardianUnivalle-Benito-Yucra
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.29
|
|
4
4
|
Summary: Middleware y detectores de seguridad (SQLi, XSS, CSRF, DoS, Keylogger) para Django/Flask
|
|
5
5
|
Author-email: Andres Benito Calle Yucra <benitoandrescalle035@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -8,13 +8,13 @@ GuardianUnivalle_Benito_Yucra/detectores/detector_csrf.py,sha256=EAYfLkHuxGC5rXS
|
|
|
8
8
|
GuardianUnivalle_Benito_Yucra/detectores/detector_dos.py,sha256=lMWmCw6nccCEnek53nVjpoBCeiBqLdrSXxqRuI7VP2I,696
|
|
9
9
|
GuardianUnivalle_Benito_Yucra/detectores/detector_keylogger.py,sha256=rEDG-Q_R56OsG2ypfHVBK7erolYjdvATnAxB3yvPXts,729
|
|
10
10
|
GuardianUnivalle_Benito_Yucra/detectores/detector_sql.py,sha256=b7pd4-CTH0FqW5-dwA6RA38Dls0bSBXKSLlmnKbLnbA,2982
|
|
11
|
-
GuardianUnivalle_Benito_Yucra/detectores/detector_xss.py,sha256=
|
|
11
|
+
GuardianUnivalle_Benito_Yucra/detectores/detector_xss.py,sha256=S2vJUbdrh4oG7-1plBK7Emu2eG5ERWHBFWZe-e5OTgo,4201
|
|
12
12
|
GuardianUnivalle_Benito_Yucra/middleware_web/middleware_web.py,sha256=23pLLYqliUoMrIC6ZEwz3hKXeDjWfHSm9vYPWGmDDik,495
|
|
13
13
|
GuardianUnivalle_Benito_Yucra/mitigacion/limitador_peticion.py,sha256=ipMOebYhql-6mSyHs0ddYXOcXq9w8P_IXLlpiIqGncw,246
|
|
14
14
|
GuardianUnivalle_Benito_Yucra/mitigacion/lista_bloqueo.py,sha256=6AYWII4mrmwCLHCvGTyoBxR4Oasr4raSHpFbVjqn7d8,193
|
|
15
15
|
GuardianUnivalle_Benito_Yucra/puntuacion/puntuacion_amenaza.py,sha256=Wx5XfcII4oweLvZsTBEJ7kUc9pMpP5-36RfI5C5KJXo,561
|
|
16
|
-
guardianunivalle_benito_yucra-0.1.
|
|
17
|
-
guardianunivalle_benito_yucra-0.1.
|
|
18
|
-
guardianunivalle_benito_yucra-0.1.
|
|
19
|
-
guardianunivalle_benito_yucra-0.1.
|
|
20
|
-
guardianunivalle_benito_yucra-0.1.
|
|
16
|
+
guardianunivalle_benito_yucra-0.1.29.dist-info/licenses/LICENSE,sha256=5e4IdL542v1E8Ft0A24GZjrxZeTsVK7XrS3mZEUhPtM,37
|
|
17
|
+
guardianunivalle_benito_yucra-0.1.29.dist-info/METADATA,sha256=E6PCNE91cwAxPFWHDpeLdEnsGHKfvvH8TRDQ3fNIFj4,1893
|
|
18
|
+
guardianunivalle_benito_yucra-0.1.29.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
19
|
+
guardianunivalle_benito_yucra-0.1.29.dist-info/top_level.txt,sha256=HTWfZM64WAV_QYr5cnXnLuabQt92dvlxqlR3pCwpbDQ,30
|
|
20
|
+
guardianunivalle_benito_yucra-0.1.29.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|