-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add redirect capabilities to Invest Controller (#627)
* add redirect capabilities to invest controller (cherry picked from commit f863efc) * add allowed domains field to url config * add library to handle allowed domains * refactor to use new Domains library * save session return_to only if it's allowed * parse urls comming from settings * decode return_to url * move decode of return_to to domain library
- Loading branch information
Showing
4 changed files
with
72 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Goteo\Library; | ||
|
||
use Goteo\Application\Config; | ||
use Goteo\Application\Config\ConfigException; | ||
|
||
class Domain | ||
{ | ||
public static function isAllowedDomain(string $domain): bool | ||
{ | ||
try { | ||
$domains = Config::get('url.allowed_domains'); | ||
} catch (ConfigException $e) { | ||
return false; | ||
} | ||
|
||
if (empty($domains)) | ||
return false; | ||
|
||
$parse = parse_url(rawurldecode($domain), PHP_URL_HOST); | ||
if (!$parse) | ||
return false; | ||
|
||
$validDomains = array_filter($domains, function ($domain) use ($parse) { | ||
$parsedDomain = parse_url($domain); | ||
if (!$parsedDomain['scheme']) | ||
return $parsedDomain['path'] == $parse; | ||
|
||
return $parsedDomain['host'] == $parse; | ||
}); | ||
|
||
return !empty($validDomains); | ||
} | ||
} |