[backend] Allow admins to specity extra web domains the instance is accessible from

For frontends that expect relative paths
This commit is contained in:
Kopper 2024-09-01 04:01:15 +03:00 committed by Iceshrimp development
parent 30cf0db0fb
commit 834661981a
3 changed files with 8 additions and 0 deletions

View file

@ -32,6 +32,9 @@ public sealed class Config
[Required] public string WebDomain { get; init; } = null!; [Required] public string WebDomain { get; init; } = null!;
[Required] public string AccountDomain { get; init; } = null!; [Required] public string AccountDomain { get; init; } = null!;
[Range(1, 100000)] public int CharacterLimit { get; init; } = 8192; [Range(1, 100000)] public int CharacterLimit { get; init; } = 8192;
public string? ExtraWebDomains { get; init; }
public string[] ExtraWebDomainsArray => ExtraWebDomains?.Split(',') ?? [];
} }
public sealed class SecuritySection public sealed class SecuritySection

View file

@ -22,6 +22,7 @@ public class RequestVerificationMiddleware(
public bool IsValid(HttpRequest rq) public bool IsValid(HttpRequest rq)
{ {
if (rq.Host.Host == config.Value.WebDomain) return true; if (rq.Host.Host == config.Value.WebDomain) return true;
if (config.Value.ExtraWebDomainsArray.Contains(rq.Host.Host)) return true;
if (rq.Host.Host == config.Value.AccountDomain && rq.Path.StartsWithSegments("/.well-known")) if (rq.Host.Host == config.Value.AccountDomain && rq.Path.StartsWithSegments("/.well-known"))
{ {
if (rq.Path == "/.well-known/webfinger") return true; if (rq.Path == "/.well-known/webfinger") return true;

View file

@ -10,6 +10,10 @@ WebDomain = shrimp.example.org
AccountDomain = example.org AccountDomain = example.org
;; End of problematic settings block ;; End of problematic settings block
;; Extra web domains this instance allows access from, separated by commas.
;; Certain frontends such as Akkoma-FE may require reverse proxy configurations that send requests through the frontend domain.
;ExtraWebDomains =
;; Maximum number of characters allowed for local notes (must not be larger than the global limit, which is 100000 characters) ;; Maximum number of characters allowed for local notes (must not be larger than the global limit, which is 100000 characters)
CharacterLimit = 8192 CharacterLimit = 8192