From 97df7ea5e6a9b987bb9fa40370dba4298b3eaf4f Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Sun, 11 Feb 2024 20:37:34 +0100 Subject: [PATCH] [backend] Send CORS headers for WellKnownController and NodeInfoController --- Iceshrimp.Backend/Controllers/NodeInfoController.cs | 2 ++ Iceshrimp.Backend/Controllers/WellKnownController.cs | 2 ++ Iceshrimp.Backend/Core/Extensions/ServiceExtensions.cs | 6 ++++++ 3 files changed, 10 insertions(+) diff --git a/Iceshrimp.Backend/Controllers/NodeInfoController.cs b/Iceshrimp.Backend/Controllers/NodeInfoController.cs index a4d784e4..2daeaebd 100644 --- a/Iceshrimp.Backend/Controllers/NodeInfoController.cs +++ b/Iceshrimp.Backend/Controllers/NodeInfoController.cs @@ -1,5 +1,6 @@ using Iceshrimp.Backend.Core.Configuration; using Iceshrimp.Backend.Core.Federation.WebFinger; +using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; @@ -8,6 +9,7 @@ namespace Iceshrimp.Backend.Controllers; [ApiController] [Tags("Federation")] [Route("/nodeinfo")] +[EnableCors("well-known")] public class NodeInfoController(IOptions config) : Controller { [HttpGet("2.1")] [HttpGet("2.0")] diff --git a/Iceshrimp.Backend/Controllers/WellKnownController.cs b/Iceshrimp.Backend/Controllers/WellKnownController.cs index 590fadd9..312b2e71 100644 --- a/Iceshrimp.Backend/Controllers/WellKnownController.cs +++ b/Iceshrimp.Backend/Controllers/WellKnownController.cs @@ -3,6 +3,7 @@ using Iceshrimp.Backend.Core.Configuration; using Iceshrimp.Backend.Core.Database; using Iceshrimp.Backend.Core.Database.Tables; using Iceshrimp.Backend.Core.Federation.WebFinger; +using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; @@ -12,6 +13,7 @@ namespace Iceshrimp.Backend.Controllers; [ApiController] [Tags("Federation")] [Route("/.well-known")] +[EnableCors("well-known")] public class WellKnownController(IOptions config, DatabaseContext db) : Controller { [HttpGet("webfinger")] [Produces("application/json")] diff --git a/Iceshrimp.Backend/Core/Extensions/ServiceExtensions.cs b/Iceshrimp.Backend/Core/Extensions/ServiceExtensions.cs index 9c08d861..b6fa5b21 100644 --- a/Iceshrimp.Backend/Core/Extensions/ServiceExtensions.cs +++ b/Iceshrimp.Backend/Core/Extensions/ServiceExtensions.cs @@ -171,6 +171,12 @@ public static class ServiceExtensions { public static void AddCorsPolicies(this IServiceCollection services) { services.AddCors(options => { + options.AddPolicy("well-known", policy => { + policy.WithOrigins("*") + .WithMethods("GET") + .WithHeaders("Accept") + .WithExposedHeaders("Vary"); + }); options.AddPolicy("drive", policy => { policy.WithOrigins("*") .WithMethods("GET", "HEAD");