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

[FacebookBridge] Handle mobile links and standardise host validation #1789

Merged
merged 3 commits into from
Oct 15, 2020
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
37 changes: 20 additions & 17 deletions bridges/FacebookBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,7 @@ private function sanitizeGroup($group) {

$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];

Expand All @@ -236,6 +227,24 @@ private function sanitizeGroup($group) {

}

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
Expand Down Expand Up @@ -348,13 +357,7 @@ private function sanitizeUser($user) {

$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'] === '/') {
Expand Down