Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add InvariantCulture defaults to Api and SmtpService to prevent regional setting conflicts (#1013)

Leendert de Borstb0dda6cb77dc
diff --git a/apps/server/AliasVault.Api/Controllers/Email/EmailBoxController.cs b/apps/server/AliasVault.Api/Controllers/Email/EmailBoxController.cs
index cb613b5a6..60453b8bd 100644
--- a/apps/server/AliasVault.Api/Controllers/Email/EmailBoxController.cs
+++ b/apps/server/AliasVault.Api/Controllers/Email/EmailBoxController.cs
@@ -83,8 +83,8 @@ public class EmailBoxController(IAliasServerDbContextFactory dbContextFactory, U
FromLocal = x.FromLocal,
ToDomain = x.ToDomain,
ToLocal = x.ToLocal,
- Date = x.Date,
- DateSystem = x.DateSystem,
+ Date = DateTime.SpecifyKind(x.Date, DateTimeKind.Utc),
+ DateSystem = DateTime.SpecifyKind(x.DateSystem, DateTimeKind.Utc),
SecondsAgo = (int)DateTime.UtcNow.Subtract(x.DateSystem).TotalSeconds,
MessagePreview = x.MessagePreview ?? string.Empty,
EncryptedSymmetricKey = x.EncryptedSymmetricKey,
@@ -148,8 +148,8 @@ public class EmailBoxController(IAliasServerDbContextFactory dbContextFactory, U
FromLocal = x.FromLocal,
ToDomain = x.ToDomain,
ToLocal = x.ToLocal,
- Date = x.Date,
- DateSystem = x.DateSystem,
+ Date = DateTime.SpecifyKind(x.Date, DateTimeKind.Utc),
+ DateSystem = DateTime.SpecifyKind(x.DateSystem, DateTimeKind.Utc),
SecondsAgo = (int)DateTime.UtcNow.Subtract(x.DateSystem).TotalSeconds,
MessagePreview = x.MessagePreview ?? string.Empty,
EncryptedSymmetricKey = x.EncryptedSymmetricKey,
diff --git a/apps/server/AliasVault.Api/Program.cs b/apps/server/AliasVault.Api/Program.cs
index 3dbd6c25c..1b557e976 100644
--- a/apps/server/AliasVault.Api/Program.cs
+++ b/apps/server/AliasVault.Api/Program.cs
@@ -5,8 +5,11 @@
// </copyright>
//-----------------------------------------------------------------------
+using System.Globalization;
using System.Reflection;
using System.Text;
+using System.Text.Json;
+using System.Text.Json.Serialization;
using AliasServerDb;
using AliasServerDb.Configuration;
using AliasVault.Api;
@@ -25,6 +28,12 @@ using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
var builder = WebApplication.CreateBuilder(args);
+
+// Force invariant culture to prevent regional date formatting issues
+// (e.g., times should be formatted as "09:03:09" instead of alternate region formats like "09.03.09").
+CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
+CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;
+
builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
builder.Configuration.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true, reloadOnChange: true);
@@ -117,7 +126,13 @@ builder.Services.AddCors(options =>
.AllowAnyHeader());
});
-builder.Services.AddControllers();
+builder.Services.AddControllers()
+ .AddJsonOptions(options =>
+ {
+ // Ensure consistent date formatting regardless of server locale
+ options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
+ options.JsonSerializerOptions.WriteIndented = false;
+ });
builder.Services.AddMemoryCache();
builder.Services.AddApiVersioning(options =>
diff --git a/apps/server/Services/AliasVault.SmtpService/Handlers/DatabaseMessageStore.cs b/apps/server/Services/AliasVault.SmtpService/Handlers/DatabaseMessageStore.cs
index 237846cb9..328c84f84 100644
--- a/apps/server/Services/AliasVault.SmtpService/Handlers/DatabaseMessageStore.cs
+++ b/apps/server/Services/AliasVault.SmtpService/Handlers/DatabaseMessageStore.cs
@@ -156,7 +156,7 @@ public class DatabaseMessageStore(ILogger<DatabaseMessageStore> logger, Config c
MessageHtml = message.HtmlBody,
MessagePlain = message.TextBody,
MessageSource = message.ToString(),
- Date = message.Date.DateTime,
+ Date = message.Date.DateTime.ToUniversalTime(),
DateSystem = DateTime.UtcNow,
Visible = true,
};
diff --git a/apps/server/Services/AliasVault.SmtpService/Program.cs b/apps/server/Services/AliasVault.SmtpService/Program.cs
index 03b82f0ae..035801169 100644
--- a/apps/server/Services/AliasVault.SmtpService/Program.cs
+++ b/apps/server/Services/AliasVault.SmtpService/Program.cs
@@ -5,6 +5,7 @@
// </copyright>
//-----------------------------------------------------------------------
+using System.Globalization;
using System.Reflection;
using System.Security.Cryptography.X509Certificates;
using AliasServerDb;
@@ -19,6 +20,12 @@ using SmtpServer;
using SmtpServer.Storage;
var builder = Host.CreateApplicationBuilder(args);
+
+// Force invariant culture to prevent regional date formatting issues
+// (e.g., times should be formatted as "09:03:09" instead of alternate region formats like "09.03.09").
+CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
+CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;
+
builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
builder.Configuration.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true, reloadOnChange: true);
builder.Services.ConfigureLogging(builder.Configuration, Assembly.GetExecutingAssembly().GetName().Name!, "../../../logs");