ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilWhiteListUrlValidator Class Reference

Class ilWhiteListUrlValidator. More...

+ Collaboration diagram for ilWhiteListUrlValidator:

Public Member Functions

 __construct (string $url, array $whitelist)
 ilWhiteListUrlValidator constructor. More...
 
 isValid ()
 

Protected Attributes

 $url = ''
 
 $whitelist = []
 

Private Member Functions

 isValidDomain (string $domain)
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilWhiteListUrlValidator::__construct ( string  $url,
array  $whitelist 
)

ilWhiteListUrlValidator constructor.

Parameters
string$url
string[]$whitelist

Definition at line 22 of file class.ilWhiteListUrlValidator.php.

23 {
24 $this->url = $url;
25 $this->whitelist = array_filter(array_map(function (string $domain) {
26 return trim($domain); // Used for trimming and type validation (strict primitive type hint)
27 }, $whitelist));
28 }
if(!array_key_exists('domain', $_REQUEST)) $domain
Definition: resume.php:8

References $domain, $url, and $whitelist.

Member Function Documentation

◆ isValid()

ilWhiteListUrlValidator::isValid ( )
Returns
bool

Definition at line 59 of file class.ilWhiteListUrlValidator.php.

59 : bool
60 {
61 $redirectDomain = parse_url($this->url, PHP_URL_HOST);
62 if (null === $redirectDomain) {
63 return false;
64 }
65
66 return $this->isValidDomain($redirectDomain);
67 }

References isValidDomain().

+ Here is the call graph for this function:

◆ isValidDomain()

ilWhiteListUrlValidator::isValidDomain ( string  $domain)
private
Parameters
string$domain
Returns
bool

Definition at line 34 of file class.ilWhiteListUrlValidator.php.

34 : bool
35 {
36 foreach ($this->whitelist as $validDomain) {
37 if ($domain === $validDomain) {
38 return true;
39 }
40
41 $firstChar = $validDomain[0];
42 if ('.' !== $firstChar) {
43 $validDomain = '.' . $validDomain;
44 }
45
46 if (strlen($domain) > strlen($validDomain)) {
47 if (substr($domain, (0 - strlen($validDomain))) === $validDomain) {
48 return true;
49 }
50 }
51 }
52
53 return false;
54 }

References $domain.

Referenced by isValid().

+ Here is the caller graph for this function:

Field Documentation

◆ $url

ilWhiteListUrlValidator::$url = ''
protected

Definition at line 12 of file class.ilWhiteListUrlValidator.php.

Referenced by __construct().

◆ $whitelist

ilWhiteListUrlValidator::$whitelist = []
protected

Definition at line 15 of file class.ilWhiteListUrlValidator.php.

Referenced by __construct().


The documentation for this class was generated from the following file: