[backend] Ignore WebFinger failures with response code 410 Gone

This commit is contained in:
Laura Hausmann 2024-02-05 20:29:11 +01:00
parent 29581d4fb2
commit cb749c94e6
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 15 additions and 0 deletions

View file

@ -27,6 +27,8 @@ public class WebFingerService(HttpClient client, HttpRequestService httpRqSvc) {
var req = httpRqSvc.Get(webFingerUrl, ["application/jrd+json", "application/json"]); var req = httpRqSvc.Get(webFingerUrl, ["application/jrd+json", "application/json"]);
var res = await client.SendAsync(req); var res = await client.SendAsync(req);
if (res.StatusCode == HttpStatusCode.Gone)
throw GracefulException.Accepted("The remote user no longer exists.");
if (!res.IsSuccessStatusCode) if (!res.IsSuccessStatusCode)
return null; return null;
if (res.Content.Headers.ContentType?.MediaType is not "application/jrd+json" and not "application/json") if (res.Content.Headers.ContentType?.MediaType is not "application/jrd+json" and not "application/json")

View file

@ -25,6 +25,12 @@ public class ErrorHandlerMiddleware(IOptions<Config.SecuritySection> options, IL
var verbosity = options.Value.ExceptionVerbosity; var verbosity = options.Value.ExceptionVerbosity;
if (e is GracefulException ce) { if (e is GracefulException ce) {
if (ce.StatusCode == HttpStatusCode.Accepted) {
ctx.Response.StatusCode = (int)ce.StatusCode;
await ctx.Response.CompleteAsync();
return;
}
if (verbosity > ExceptionVerbosity.Basic && ce.OverrideBasic) if (verbosity > ExceptionVerbosity.Basic && ce.OverrideBasic)
verbosity = ExceptionVerbosity.Basic; verbosity = ExceptionVerbosity.Basic;
@ -112,6 +118,13 @@ public class GracefulException(
return new GracefulException(HttpStatusCode.MisdirectedRequest, HttpStatusCode.MisdirectedRequest.ToString(), return new GracefulException(HttpStatusCode.MisdirectedRequest, HttpStatusCode.MisdirectedRequest.ToString(),
"This server is not configured to respond to this request.", null, true, true); "This server is not configured to respond to this request.", null, true, true);
} }
/// <summary>
/// This is intended for cases where no error occured, but the request needs to be aborted early (e.g. WebFinger returning 410 Gone)
/// </summary>
public static GracefulException Accepted(string message) {
return new GracefulException(HttpStatusCode.Accepted, message);
}
} }
public enum ExceptionVerbosity { public enum ExceptionVerbosity {