Skip to content

Commit 7620d23

Browse files
susnuxnickvergessen
andcommitted
fix(Request): Catch exceptions in isTrustedProxy
The function fails if the configured trusted proxies contain invalid characters and the underlying IpUtils will throw. But as it is used by `getRemoteAddress` which is used by logging / templating, thrown errors are not reported but silently fail with error 500. Co-authored-by: Ferdinand Thiessen <opensource@fthiessen.de> Co-authored-by: Joas Schilling <213943+nickvergessen@users.noreply.github.com> Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 65b8c8f commit 7620d23

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/private/AppFramework/Http/Request.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,14 @@ public function getId(): string {
573573
* @return boolean true if $remoteAddress matches any entry in $trustedProxies, false otherwise
574574
*/
575575
protected function isTrustedProxy($trustedProxies, $remoteAddress) {
576-
return IpUtils::checkIp($remoteAddress, $trustedProxies);
576+
try {
577+
return IpUtils::checkIp($remoteAddress, $trustedProxies);
578+
} catch (\Throwable) {
579+
// We can not log to our log here as the logger is using `getRemoteAddress` which uses the function, so we would have a cyclic dependency
580+
// Reaching this line means `trustedProxies` is in invalid format.
581+
error_log('Nextcloud trustedProxies has malformed entries');
582+
return false;
583+
}
577584
}
578585

579586
/**

0 commit comments

Comments
 (0)