Fix: Galeria Movil, Contactos, Estado de Verificación de Mail al Cambiar Clave y Otros.
This commit is contained in:
@@ -161,14 +161,16 @@ app.UseMiddleware<MotoresArgentinosV2.API.Middleware.ExceptionHandlingMiddleware
|
||||
// USAR EL MIDDLEWARE DE HEADERS
|
||||
app.UseForwardedHeaders();
|
||||
|
||||
// 🔒 HEADERS DE SEGURIDAD MIDDLEWARE
|
||||
// 🔒 HEADERS DE SEGURIDAD & PNA FIX MIDDLEWARE
|
||||
app.Use(async (context, next) =>
|
||||
{
|
||||
// --- 1. SEGURIDAD EXISTENTE (HARDENING) ---
|
||||
context.Response.Headers.Append("X-Frame-Options", "DENY");
|
||||
context.Response.Headers.Append("X-Content-Type-Options", "nosniff");
|
||||
context.Response.Headers.Append("Referrer-Policy", "strict-origin-when-cross-origin");
|
||||
context.Response.Headers.Append("X-XSS-Protection", "1; mode=block");
|
||||
context.Response.Headers.Append("Permissions-Policy", "accelerometer=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), payment=(), usb=()");
|
||||
|
||||
string csp = "default-src 'self'; " +
|
||||
"img-src 'self' data: https: blob:; " +
|
||||
"script-src 'self' 'unsafe-inline'; " +
|
||||
@@ -179,8 +181,32 @@ app.Use(async (context, next) =>
|
||||
"form-action 'self'; " +
|
||||
"frame-ancestors 'none';";
|
||||
context.Response.Headers.Append("Content-Security-Policy", csp);
|
||||
|
||||
context.Response.Headers.Remove("Server");
|
||||
context.Response.Headers.Remove("X-Powered-By");
|
||||
|
||||
// Esto permite que el sitio público (eldia.com) pida recursos a tu IP local/privada.
|
||||
// Si el navegador pregunta explícitamente "Puedo acceder a la red privada?"
|
||||
if (context.Request.Headers.ContainsKey("Access-Control-Request-Private-Network"))
|
||||
{
|
||||
context.Response.Headers.Append("Access-Control-Allow-Private-Network", "true");
|
||||
}
|
||||
// O si estamos sirviendo imágenes/API (Backup por si el navegador no manda el header de request)
|
||||
else if (context.Request.Path.StartsWithSegments("/uploads") || context.Request.Path.StartsWithSegments("/api"))
|
||||
{
|
||||
context.Response.Headers.Append("Access-Control-Allow-Private-Network", "true");
|
||||
}
|
||||
|
||||
// Asegurar que el header esté presente en las peticiones OPTIONS (Preflight)
|
||||
if (context.Request.Method == "OPTIONS")
|
||||
{
|
||||
// A veces es necesario forzarlo aquí también para que el preflight pase
|
||||
if (!context.Response.Headers.ContainsKey("Access-Control-Allow-Private-Network"))
|
||||
{
|
||||
context.Response.Headers.Append("Access-Control-Allow-Private-Network", "true");
|
||||
}
|
||||
}
|
||||
|
||||
await next();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user