diff options
author | Rory& <root@rory.gay> | 2024-02-26 19:09:43 +0100 |
---|---|---|
committer | Rory& <root@rory.gay> | 2024-02-26 19:09:43 +0100 |
commit | f30b7ed9e6b7c0e557ff0b70902fa8a492052c34 (patch) | |
tree | 9fa58c8f3f7e767e70ad8b13a19b22646db2cb98 | |
parent | Log request headers. (diff) | |
download | MatrixMediaGate-f30b7ed9e6b7c0e557ff0b70902fa8a492052c34.tar.xz |
Use X-Real-IP and X-Forwarded-For if available
-rw-r--r-- | MatrixMediaGate/Services/AuthValidator.cs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/MatrixMediaGate/Services/AuthValidator.cs b/MatrixMediaGate/Services/AuthValidator.cs index 4b74006..28127ae 100644 --- a/MatrixMediaGate/Services/AuthValidator.cs +++ b/MatrixMediaGate/Services/AuthValidator.cs @@ -80,6 +80,15 @@ public class AuthValidator(ILogger<AuthValidator> logger, ProxyConfiguration cfg Console.WriteLine($"Authorized (ignore me) - Headers: {key}: {value}"); } + // X-Real-IP X-Forwarded-For + if (ctx.Request.Headers.TryGetValue("X-Real-IP", out var xRealIp)) { + return xRealIp.ToString(); + } + + if (ctx.Request.Headers.TryGetValue("X-Forwarded-For", out var xForwardedFor)) { + return xForwardedFor.ToString(); + } + return ctx.Connection.RemoteIpAddress?.ToString(); } } \ No newline at end of file |