[backend/federation] Bypass authorized fetch for relay actor (ISH-529)

This commit is contained in:
Laura Hausmann 2025-01-07 07:30:26 +01:00
parent 2fbff537a6
commit c21147c86f
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -28,11 +28,14 @@ public class AuthorizedFetchMiddleware(
{
public static ServiceLifetime Lifetime => ServiceLifetime.Scoped;
private static string? _instanceActorUri;
private static string? _relayActorUri;
public async Task InvokeAsync(HttpContext ctx, RequestDelegate next)
{
// Ensure we're rendering HTML markup (AsyncLocal)
mfmConverter.SupportsHtmlFormatting.Value = true;
mfmConverter.SupportsInlineMedia.Value = true;
mfmConverter.SupportsInlineMedia.Value = true;
if (!config.Value.AuthorizedFetch)
{
@ -45,9 +48,9 @@ public class AuthorizedFetchMiddleware(
var request = ctx.Request;
var ct = appLifetime.ApplicationStopping;
//TODO: cache this somewhere
var instanceActorUri = $"/users/{(await systemUserSvc.GetInstanceActorAsync()).Id}";
if (request.Path.Value == instanceActorUri)
_instanceActorUri ??= $"/users/{(await systemUserSvc.GetInstanceActorAsync()).Id}";
_relayActorUri ??= $"/users/{(await systemUserSvc.GetRelayActorAsync()).Id}";
if (request.Path.Value == _instanceActorUri || request.Path.Value == _relayActorUri)
{
await next(ctx);
return;