Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Request): Catch exceptions in isTrustedProxy #42794

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/private/AppFramework/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,14 @@
* @return boolean true if $remoteAddress matches any entry in $trustedProxies, false otherwise
*/
protected function isTrustedProxy($trustedProxies, $remoteAddress) {
return IpUtils::checkIp($remoteAddress, $trustedProxies);
try {
return IpUtils::checkIp($remoteAddress, $trustedProxies);
} catch (\Throwable) {

Check warning on line 578 in lib/private/AppFramework/Http/Request.php

View check run for this annotation

Codecov / codecov/patch

lib/private/AppFramework/Http/Request.php#L578

Added line #L578 was not covered by tests
// 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
// Reaching this line means `trustedProxies` is in invalid format.
error_log('Nextcloud trustedProxies has malformed entries');
return false;

Check warning on line 582 in lib/private/AppFramework/Http/Request.php

View check run for this annotation

Codecov / codecov/patch

lib/private/AppFramework/Http/Request.php#L581-L582

Added lines #L581 - L582 were not covered by tests
}
}

/**
Expand Down
Loading