fix(auth): audit de securite complet - 12 correctifs

# Fix #28: ProtectedLocalStorage -> ProtectedSessionStorage
#   (donnees token jamais exposees au JS client en Blazor Server)
# Fix #3: GetUserIdFromExpiredToken valide maintenant la signature
#   (plus de ReadJwtToken sans validation)
# Fix #5: API Key handler X-API-Key uniquement (plus de Bearer ambiguité)
# Fix #7: MarkUsed() persiste via SaveChangesAsync()
# Fix #8: Hardcoded permissions (documenté — nécessite migration DB)
# Fix #12: Race condition registration — try/catch DbUpdateException
# Fix #13: Public registration DESACTIVEE par defaut (pas de setting = disabled)
# Fix #15/17: Enable2fa genere et retourne shared key + QR code URI
# Fix #16: Rate limiting specifique 2FA (5 req/min) et RegisterAdmin
# Fix #22/23: RevokeRefreshToken stocke jti (pas token brut)
# Fix #24: Rotation refresh token — ancien token revoque apres refresh
# Fix #39: Audit logging des echecs de login (via IUserRepository)

Breaking: Enable2fa retourne maintenant Enable2faResponse au lieu de Ok()
This commit is contained in:
Arnaud Dartois committed 2026-07-28 14:37:52 +00:00
1 parent 485842b135
commit 234c158a69
12 files changed
+201 -50

No files matched your search

+63 -3
View File
@@ -209,7 +209,7 @@ public partial class Program {
internal static void ConfigureServices(WebApplicationBuilder builder)
{
// ── Sentry (GlitchTip) — DSN from config pipeline with legacy env var fallback ──
// ── Sentry (GlitchTip) — error tracking, performance & structured logs ──
// Primary: Sentry:Dsn from appsettings.json or env var Sentry__Dsn
// Fallback: legacy SENTRY_DSN env var (Docker backward compat)
// Neither set → DSN is null → Sentry SDK no-ops gracefully
@@ -220,11 +220,71 @@ public partial class Program {
builder.WebHost.UseSentry(options =>
{
options.Dsn = sentryDsn;
// ── Env & Release ────────────────────────────────────────
// Environment is auto-read from IHostingEnvironment
// Release should be explicitly set (e.g. "heimdall@1.2.3")
options.Release = builder.Configuration["Sentry:Release"]
?? Environment.GetEnvironmentVariable("SENTRY_RELEASE");
// ── Error sampling ──────────────────────────────────────
options.SampleRate = 1.0f; // 100% errors (adjust if volume too high)
options.AttachStacktrace = true; // Stack traces even on CaptureMessage
options.MaxBreadcrumbs = 100; // Breadcrumb buffer size
options.MinimumBreadcrumbLevel = LogLevel.Debug;
options.MinimumEventLevel = LogLevel.Error;
options.TracesSampleRate = 0.05;
// ── Tracing (Performance) ───────────────────────────────
// GlitchTip counts every transaction as an event.
// 0.05 = 5% sample = good signal-to-noise in production.
options.TracesSampleRate = double.Parse(
builder.Configuration["Sentry:TracesSampleRate"] ?? "0.05");
// ── Request body capture ────────────────────────────────
options.MaxRequestBodySize = Sentry.Extensibility.RequestSize.Small;
options.ProfilesSampleRate = 0.05;
// ── Structured logs (v5.14+) ────────────────────────────
// Enables SentrySdk.Logger.LogInfo() etc.
options.EnableLogs = true;
// ── GlitchTip-specific: disable unsupported features ────
// Release Health / Sessions are NOT supported by GlitchTip
options.AutoSessionTracking = false;
// ── PII & GDPR ──────────────────────────────────────────
options.SendDefaultPii = false; // Explicit RGPD-safe default
options.ServerName = null; // Never send hostname
// ── Enhanced diagnostics ────────────────────────────────
options.CaptureBlockingCalls = true; // Detect .Result / .Wait()
options.CaptureFailedRequests = true; // Capture HttpClient 4xx/5xx
options.IncludeActivityData = true; // DiagnosticSource Activity
// ── Stack traces ────────────────────────────────────────
options.StackTraceMode = Sentry.StackTraceMode.Enhanced;
// ── BeforeSend — scrub PII before it leaves the SDK ────
options.SetBeforeSend((sentryEvent, hint) =>
{
// Never send server name (already null above, belt-and-suspenders)
sentryEvent.ServerName = null;
// Remove sensitive extras
if (sentryEvent.Extra?.ContainsKey("password") == true)
sentryEvent.Extra.Remove("password");
if (sentryEvent.Extra?.ContainsKey("token") == true)
sentryEvent.Extra.Remove("token");
if (sentryEvent.Extra?.ContainsKey("secret") == true)
sentryEvent.Extra.Remove("secret");
return sentryEvent;
});
// ── BeforeBreadcrumb — filter noisy breadcrumbs ────────
options.SetBeforeBreadcrumb(breadcrumb
=> breadcrumb.Category == "Microsoft.AspNetCore.RateLimiting"
? null
: breadcrumb);
});
}