Piattaforme: istanza unica dopo lo spostamento dei dati, avvio sicuro del contenitore, rilascio con prove e immagine, accesso senza reindirizzamenti esterni (pkg-1, pkg-2, pkg-3, pkg-4, pkg-5, pkg-6, websec-2, web-8, websec-3)

Registro di casa 192.168.30.23:3000 (HTTP) nel modello Unraid, in compose e nel rilascio con buildx; profilo seccomp fuori da /dati.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
Claude committed 2026-10-14 00:59:18 +00:00
1 parent 78c92eb2a4
commit dd9320c54b
36 files changed
+1683 -152

No files matched your search

+57
View File
@@ -0,0 +1,57 @@
using Microsoft.AspNetCore.Http;
namespace Febe.Web.Security;
/// <summary>
/// Where the login page goes back after the password (spec §13.1): <c>/accesso?torna=…</c>. Only a page of this
/// interface, never another site. A browser reads <c>//host</c> as an address of another site, and turns <c>/\host</c>
/// into <c>//host</c> as well (a backslash counts as a slash, tabs and new lines are dropped), so the value must be one
/// path that starts with a single slash and holds no backslash, blank or control character. The login page script
/// (<c>js/core/return-path.js</c>) applies the same rule.
/// </summary>
public static class LoginReturn
{
/// <summary>The name of the query parameter of the login page.</summary>
public const string QueryName = "torna";
/// <summary>The longest path accepted (a real page address is much shorter).</summary>
public const int MaxLength = 2048;
/// <summary><paramref name="value"/> when it is a path of this interface; null otherwise.</summary>
public static string? Sanitize(string? value) => IsSafe(value) ? value : null;
/// <summary>True when <paramref name="value"/> can only lead to a page of this interface.</summary>
public static bool IsSafe(string? value)
{
if (string.IsNullOrEmpty(value) || value.Length > MaxLength || value[0] != '/')
{
return false;
}
if (value.Length > 1 && value[1] is '/' or '\\')
{
return false;
}
foreach (var c in value)
{
if (c == '\\' || c <= ' ' || c == '\u007f' || char.IsWhiteSpace(c) || char.IsControl(c))
{
return false;
}
}
return true;
}
/// <summary>The address of the login page that goes back to <paramref name="path"/> (or just the login page).</summary>
public static string LoginAddress(string? path) =>
Sanitize(path) is { } safe ? "/accesso?" + QueryName + "=" + Uri.EscapeDataString(safe) : "/accesso";
/// <summary>True when the request carries a <c>torna</c> that is not a path of this interface.</summary>
public static bool HasUnsafeReturn(HttpRequest request)
{
ArgumentNullException.ThrowIfNull(request);
return request.Query.TryGetValue(QueryName, out var values) && values.Any(v => !IsSafe(v));
}
}
+32
View File
@@ -0,0 +1,32 @@
using Microsoft.AspNetCore.Http;
namespace Febe.Web.Security;
/// <summary>
/// Whether a request reached Febe over HTTPS, for the <c>Secure</c> flag of its cookies (spec §11, §13.1). Febe itself
/// listens on plain HTTP; remote access goes through a proxy with HTTPS in front, which terminates TLS. Only that trusted
/// proxy (<c>FEBE_PROXY_FIDATO=1</c>) can say so, with <c>X-Forwarded-Proto: https</c>: from anyone else the header is
/// ignored.
/// </summary>
public static class RequestScheme
{
/// <summary>True when the browser talked HTTPS: directly, or to the trusted proxy in front of Febe.</summary>
public static bool IsHttps(HttpRequest request, FebeWebOptions options)
{
ArgumentNullException.ThrowIfNull(request);
ArgumentNullException.ThrowIfNull(options);
if (request.IsHttps)
{
return true;
}
if (!options.TrustForwardedHost)
{
return false;
}
// The first value is the one the proxy closest to the browser wrote.
var forwarded = request.Headers["X-Forwarded-Proto"].ToString().Split(',')[0].Trim();
return string.Equals(forwarded, Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase);
}
}
+17 -2
View File
@@ -47,6 +47,14 @@ public sealed class SecurityMiddleware(RequestDelegate next, FebeWebOptions opti
return;
}
// The login page with a «torna» that leads out of the interface (a crafted link: «/\host», «//host»): the
// value is dropped before the page even shows, so after the password Febe goes only to its own pages.
if (IsLoginPage(request) && LoginReturn.HasUnsafeReturn(request))
{
response.Redirect("/accesso");
return;
}
switch (options.Access)
{
case AccessMode.Token:
@@ -85,7 +93,7 @@ public sealed class SecurityMiddleware(RequestDelegate next, FebeWebOptions opti
{
HttpOnly = true,
SameSite = SameSiteMode.Strict,
Secure = request.IsHttps,
Secure = RequestScheme.IsHttps(request, options),
Path = "/",
IsEssential = true,
});
@@ -141,12 +149,19 @@ public sealed class SecurityMiddleware(RequestDelegate next, FebeWebOptions opti
}
else
{
context.Response.Redirect("/accesso?torna=" + Uri.EscapeDataString(path));
// Back to this page after the password; a path that would lead out of the interface is not carried.
context.Response.Redirect(LoginReturn.LoginAddress(path));
}
return false;
}
/// <summary>The login page: <c>/accesso</c>, or its file <c>/accesso.html</c> served as it is.</summary>
private static bool IsLoginPage(HttpRequest request) =>
(HttpMethods.IsGet(request.Method) || HttpMethods.IsHead(request.Method))
&& (string.Equals(request.Path.Value, "/accesso", StringComparison.OrdinalIgnoreCase)
|| string.Equals(request.Path.Value, "/accesso.html", StringComparison.OrdinalIgnoreCase));
private static bool IsApi(HttpRequest request) => request.Path.StartsWithSegments("/api", StringComparison.OrdinalIgnoreCase);
/// <summary>What may be read without a password: the error page and what it needs, never a command.</summary>