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

+10 -3
View File
@@ -38,7 +38,8 @@ public static class AccessApi
{
HttpOnly = true,
SameSite = SameSiteMode.Strict,
Secure = context.Request.IsHttps,
// Behind the proxy with HTTPS (FEBE_PROXY_FIDATO) too: the session never travels in clear text.
Secure = RequestScheme.IsHttps(context.Request, options),
Path = "/",
IsEssential = true,
MaxAge = passwords.SessionLifetime,
@@ -54,10 +55,16 @@ public static class AccessApi
}
});
endpoints.MapPost("/api/uscita", (HttpContext context) =>
endpoints.MapPost("/api/uscita", (HttpContext context, FebeWebOptions options) =>
{
context.RequestServices.GetService<PasswordAccess>()?.Logout(context.Request.Cookies[PasswordAccess.CookieName]);
context.Response.Cookies.Delete(PasswordAccess.CookieName, new CookieOptions { Path = "/", SameSite = SameSiteMode.Strict, HttpOnly = true });
context.Response.Cookies.Delete(PasswordAccess.CookieName, new CookieOptions
{
Path = "/",
SameSite = SameSiteMode.Strict,
HttpOnly = true,
Secure = RequestScheme.IsHttps(context.Request, options),
});
return ApiHttp.Message("Sei uscito da Febe.");
});
}
+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>
+3 -2
View File
@@ -3,6 +3,7 @@
import { h, fill, brand } from './core/dom.js';
import { loadTexts, t } from './core/text.js';
import { returnAddress } from './core/return-path.js';
async function boot() {
await loadTexts('it');
@@ -31,8 +32,8 @@ async function boot() {
});
const data = await response.json().catch(() => ({}));
if (response.ok && data.ok) {
const back = new URLSearchParams(location.search).get('torna');
location.href = back && back.startsWith('/') && !back.startsWith('//') ? back : '/libreria';
// Back to the page Alberto was opening: only a page of this interface, never another site.
location.href = returnAddress(new URLSearchParams(location.search).get('torna'), location.origin);
return;
}
message.textContent = data.message || t('accesso.sbagliata');
@@ -0,0 +1,24 @@
// Where the login page goes after the password (spec §13.1): the page Alberto was opening («?torna=/account/12»),
// never another site. A link can hide another site in many ways: «//host», «/\host» (a backslash counts as a slash),
// «/%09/host» (tabs and new lines are dropped). The same rule as the server (Febe.Web.Security.LoginReturn): one path
// that starts with a single slash, without backslashes, blanks or control characters; then the address it resolves to
// must still be on this origin, and the page goes to that absolute address (nothing left to read twice).
const SAFE = /^\/(?![\/\\])[^\\\s\u0000-\u001f\u007f-\u009f]*$/;
export const DEFAULT_PAGE = '/libreria';
/** The absolute address to open after the login, on <origin> only; the library when <value> is missing or unsafe. */
export function returnAddress(value, origin) {
const fallback = new URL(DEFAULT_PAGE, origin).href;
if (typeof value !== 'string' || value.length > 2048 || !SAFE.test(value)) {
return fallback;
}
try {
const target = new URL(value, origin);
return target.origin === new URL(origin).origin ? target.href : fallback;
} catch {
return fallback;
}
}