Skip to content

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

Bind API method input to type when there is possible ambiguity (#2159)

Leendert de Borst28e20062a66f
diff --git a/apps/server/AliasVault.Api/Controllers/V1/Email/EmailController.cs b/apps/server/AliasVault.Api/Controllers/V1/Email/EmailController.cs
index 84aab334a..20814bf9e 100644
--- a/apps/server/AliasVault.Api/Controllers/V1/Email/EmailController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V1/Email/EmailController.cs
@@ -31,7 +31,7 @@ public class EmailController(ILogger<EmailController> logger, IAliasServerDbCont
/// </summary>
/// <param name="id">The email ID to open.</param>
/// <returns>List of aliases in JSON format.</returns>
- [HttpGet(template: "{id}", Name = "GetEmail")]
+ [HttpGet(template: "{id:int}", Name = "GetEmail")]
public async Task<IActionResult> GetEmail(int id)
{
await using var context = await dbContextFactory.CreateDbContextAsync();
@@ -81,7 +81,7 @@ public class EmailController(ILogger<EmailController> logger, IAliasServerDbCont
/// </summary>
/// <param name="id">The email ID to delete.</param>
/// <returns>A response indicating the success or failure of the deletion.</returns>
- [HttpDelete(template: "{id}", Name = "DeleteEmail")]
+ [HttpDelete(template: "{id:int}", Name = "DeleteEmail")]
public async Task<IActionResult> DeleteEmail(int id)
{
await using var context = await dbContextFactory.CreateDbContextAsync();
@@ -114,7 +114,7 @@ public class EmailController(ILogger<EmailController> logger, IAliasServerDbCont
/// <param name="id">The email ID.</param>
/// <param name="attachmentId">The attachment ID.</param>
/// <returns>Attachment bytes in encrypted form.</returns>
- [HttpGet(template: "{id}/attachments/{attachmentId}", Name = "GetEmailAttachment")]
+ [HttpGet(template: "{id:int}/attachments/{attachmentId:int}", Name = "GetEmailAttachment")]
public async Task<IActionResult> GetEmailAttachment(int id, int attachmentId)
{
await using var context = await dbContextFactory.CreateDbContextAsync();
diff --git a/apps/server/AliasVault.Api/Controllers/V1/Security/SecurityController.cs b/apps/server/AliasVault.Api/Controllers/V1/Security/SecurityController.cs
index b370ea080..be4f98ae3 100644
--- a/apps/server/AliasVault.Api/Controllers/V1/Security/SecurityController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V1/Security/SecurityController.cs
@@ -58,7 +58,7 @@ public class SecurityController(IAliasServerDbContextFactory dbContextFactory, U
/// </summary>
/// <param name="id">The ID of the refresh token to revoke.</param>
/// <returns>Http200 if success.</returns>
- [HttpDelete("sessions/{id}")]
+ [HttpDelete("sessions/{id:guid}")]
public async Task<IActionResult> RevokeSession(Guid id)
{
var user = await GetCurrentUserAsync();
diff --git a/apps/server/AliasVault.Api/Controllers/V2/Email/EmailController.cs b/apps/server/AliasVault.Api/Controllers/V2/Email/EmailController.cs
index 2e0d71c29..0edeecd19 100644
--- a/apps/server/AliasVault.Api/Controllers/V2/Email/EmailController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V2/Email/EmailController.cs
@@ -32,7 +32,7 @@ public class EmailController(ILogger<EmailController> logger, IAliasServerDbCont
/// </summary>
/// <param name="id">The email ID to open.</param>
/// <returns>List of aliases in JSON format.</returns>
- [HttpGet(template: "{id}", Name = "GetEmail")]
+ [HttpGet(template: "{id:int}", Name = "GetEmail")]
public async Task<IActionResult> GetEmail(int id)
{
await using var context = await dbContextFactory.CreateDbContextAsync();
@@ -69,7 +69,7 @@ public class EmailController(ILogger<EmailController> logger, IAliasServerDbCont
/// </summary>
/// <param name="id">The email ID to delete.</param>
/// <returns>A response indicating the success or failure of the deletion.</returns>
- [HttpDelete(template: "{id}", Name = "DeleteEmail")]
+ [HttpDelete(template: "{id:int}", Name = "DeleteEmail")]
public async Task<IActionResult> DeleteEmail(int id)
{
await using var context = await dbContextFactory.CreateDbContextAsync();
@@ -102,7 +102,7 @@ public class EmailController(ILogger<EmailController> logger, IAliasServerDbCont
/// <param name="id">The email ID.</param>
/// <param name="partIndex">The part index, as advertised by the X-AliasVault-Part header on the attachment in the message source.</param>
/// <returns>Part bytes in encrypted form.</returns>
- [HttpGet(template: "{id}/parts/{partIndex}", Name = "GetEmailPart")]
+ [HttpGet(template: "{id:int}/parts/{partIndex:int}", Name = "GetEmailPart")]
public async Task<IActionResult> GetEmailPart(int id, int partIndex)
{
await using var context = await dbContextFactory.CreateDbContextAsync();
diff --git a/apps/server/AliasVault.Api/Controllers/V2/Security/SecurityController.cs b/apps/server/AliasVault.Api/Controllers/V2/Security/SecurityController.cs
index d30fa72af..76d909133 100644
--- a/apps/server/AliasVault.Api/Controllers/V2/Security/SecurityController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V2/Security/SecurityController.cs
@@ -58,7 +58,7 @@ public class SecurityController(IAliasServerDbContextFactory dbContextFactory, U
/// </summary>
/// <param name="id">The ID of the refresh token to revoke.</param>
/// <returns>Http200 if success.</returns>
- [HttpDelete("sessions/{id}")]
+ [HttpDelete("sessions/{id:guid}")]
public async Task<IActionResult> RevokeSession(Guid id)
{
var user = await GetCurrentUserAsync();