[FacebookBridge] Handle mobile links and unify host validation (#1789)

This commit is contained in:
Joshua Coales 2020-10-15 10:08:03 +01:00 committed by GitHub
parent 0a1ff10a52
commit 45e2f385b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -215,16 +215,7 @@ class FacebookBridge extends BridgeAbstract {
$urlparts = parse_url($group);
if($urlparts['host'] !== parse_url(self::URI)['host']
&& 'www.' . $urlparts['host'] !== parse_url(self::URI)['host']) {
returnClientError('The host you provided is invalid! Received "'
. $urlparts['host']
. '", expected "'
. parse_url(self::URI)['host']
. '"!');
}
$this->validateHost($urlparts['host']);
return explode('/', $urlparts['path'])[2];
@ -236,6 +227,24 @@ class FacebookBridge extends BridgeAbstract {
}
private function validateHost($provided_host) {
// Handle mobile links
if (strpos($provided_host, 'm.') === 0) {
$provided_host = substr($provided_host, strlen('m.'));
}
$facebook_host = parse_url(self::URI)['host'];
if ($provided_host !== $facebook_host
&& 'www.' . $provided_host !== $facebook_host) {
returnClientError('The host you provided is invalid! Received "'
. $provided_host
. '", expected "'
. $facebook_host
. '"!');
}
}
private function isPublicGroup($html) {
// Facebook redirects to the groups about page for non-public groups
@ -348,13 +357,7 @@ class FacebookBridge extends BridgeAbstract {
$urlparts = parse_url($user);
if($urlparts['host'] !== parse_url(self::URI)['host']) {
returnClientError('The host you provided is invalid! Received "'
. $urlparts['host']
. '", expected "'
. parse_url(self::URI)['host']
. '"!');
}
$this->validateHost($urlparts['host']);
if(!array_key_exists('path', $urlparts)
|| $urlparts['path'] === '/') {