This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Copyright 2016 Facebook, Inc. |
||
4 | * |
||
5 | * You are hereby granted a non-exclusive, worldwide, royalty-free license to |
||
6 | * use, copy, modify, and distribute this software in source code or binary |
||
7 | * form for use in connection with the web services and APIs provided by |
||
8 | * Facebook. |
||
9 | * |
||
10 | * As with any software that integrates with the Facebook platform, your use |
||
11 | * of this software is subject to the Facebook Developer Principles and |
||
12 | * Policies [http://developers.facebook.com/policy/]. This copyright notice |
||
13 | * shall be included in all copies or substantial portions of the software. |
||
14 | * |
||
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||
21 | * DEALINGS IN THE SOFTWARE. |
||
22 | * |
||
23 | */ |
||
24 | namespace Facebook\Tests\Url; |
||
25 | |||
26 | use Facebook\Url\FacebookUrlDetectionHandler; |
||
27 | |||
28 | class FacebookUrlDetectionHandlerTest extends \PHPUnit_Framework_TestCase |
||
29 | { |
||
30 | public function testProperlyGeneratesUrlFromCommonScenario() |
||
0 ignored issues
–
show
|
|||
31 | { |
||
32 | $_SERVER = [ |
||
33 | 'HTTP_HOST' => 'foo.bar', |
||
34 | 'SERVER_PORT' => '80', |
||
35 | 'REQUEST_URI' => '/baz?foo=123', |
||
36 | ]; |
||
37 | |||
38 | $urlHandler = new FacebookUrlDetectionHandler(); |
||
39 | $currentUri = $urlHandler->getCurrentUrl(); |
||
40 | |||
41 | $this->assertEquals('http://foo.bar/baz?foo=123', $currentUri); |
||
42 | } |
||
43 | |||
44 | public function testProperlyGeneratesSecureUrlFromCommonScenario() |
||
0 ignored issues
–
show
testProperlyGeneratesSecureUrlFromCommonScenario uses the super-global variable $_SERVER which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
45 | { |
||
46 | $_SERVER = [ |
||
47 | 'HTTP_HOST' => 'foo.bar', |
||
48 | 'SERVER_PORT' => '443', |
||
49 | 'REQUEST_URI' => '/baz?foo=123', |
||
50 | ]; |
||
51 | |||
52 | $urlHandler = new FacebookUrlDetectionHandler(); |
||
53 | $currentUri = $urlHandler->getCurrentUrl(); |
||
54 | |||
55 | $this->assertEquals('https://foo.bar/baz?foo=123', $currentUri); |
||
56 | } |
||
57 | |||
58 | View Code Duplication | public function testProperlyGeneratesUrlFromProxy() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() testProperlyGeneratesUrlFromProxy uses the super-global variable $_SERVER which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
59 | { |
||
60 | $_SERVER = [ |
||
61 | 'HTTP_X_FORWARDED_PORT' => '80', |
||
62 | 'HTTP_X_FORWARDED_PROTO' => 'http', |
||
63 | 'HTTP_HOST' => 'foo.bar', |
||
64 | 'SERVER_PORT' => '80', |
||
65 | 'REQUEST_URI' => '/baz?foo=123', |
||
66 | ]; |
||
67 | |||
68 | $urlHandler = new FacebookUrlDetectionHandler(); |
||
69 | $currentUri = $urlHandler->getCurrentUrl(); |
||
70 | |||
71 | $this->assertEquals('http://foo.bar/baz?foo=123', $currentUri); |
||
72 | } |
||
73 | |||
74 | View Code Duplication | public function testProperlyGeneratesSecureUrlFromProxy() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() testProperlyGeneratesSecureUrlFromProxy uses the super-global variable $_SERVER which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
75 | { |
||
76 | $_SERVER = [ |
||
77 | 'HTTP_X_FORWARDED_PORT' => '443', |
||
78 | 'HTTP_X_FORWARDED_PROTO' => 'https', |
||
79 | 'HTTP_HOST' => 'foo.bar', |
||
80 | 'SERVER_PORT' => '80', |
||
81 | 'REQUEST_URI' => '/baz?foo=123', |
||
82 | ]; |
||
83 | |||
84 | $urlHandler = new FacebookUrlDetectionHandler(); |
||
85 | $currentUri = $urlHandler->getCurrentUrl(); |
||
86 | |||
87 | $this->assertEquals('https://foo.bar/baz?foo=123', $currentUri); |
||
88 | } |
||
89 | |||
90 | public function testProperlyGeneratesUrlWithCustomPort() |
||
0 ignored issues
–
show
testProperlyGeneratesUrlWithCustomPort uses the super-global variable $_SERVER which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
91 | { |
||
92 | $_SERVER = [ |
||
93 | 'HTTP_HOST' => 'foo.bar', |
||
94 | 'SERVER_PORT' => '1337', |
||
95 | 'REQUEST_URI' => '/foo.php', |
||
96 | ]; |
||
97 | |||
98 | $urlHandler = new FacebookUrlDetectionHandler(); |
||
99 | $currentUri = $urlHandler->getCurrentUrl(); |
||
100 | |||
101 | $this->assertEquals('http://foo.bar:1337/foo.php', $currentUri); |
||
102 | } |
||
103 | |||
104 | View Code Duplication | public function testProperlyGeneratesSecureUrlWithCustomPort() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() testProperlyGeneratesSecureUrlWithCustomPort uses the super-global variable $_SERVER which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
105 | { |
||
106 | $_SERVER = [ |
||
107 | 'HTTP_HOST' => 'foo.bar', |
||
108 | 'SERVER_PORT' => '1337', |
||
109 | 'REQUEST_URI' => '/foo.php', |
||
110 | 'HTTPS' => 'On', |
||
111 | ]; |
||
112 | |||
113 | $urlHandler = new FacebookUrlDetectionHandler(); |
||
114 | $currentUri = $urlHandler->getCurrentUrl(); |
||
115 | |||
116 | $this->assertEquals('https://foo.bar:1337/foo.php', $currentUri); |
||
117 | } |
||
118 | |||
119 | View Code Duplication | public function testProperlyGeneratesUrlWithCustomPortFromProxy() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() testProperlyGeneratesUrlWithCustomPortFromProxy uses the super-global variable $_SERVER which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
120 | { |
||
121 | $_SERVER = [ |
||
122 | 'HTTP_X_FORWARDED_PORT' => '8888', |
||
123 | 'HTTP_X_FORWARDED_PROTO' => 'http', |
||
124 | 'HTTP_HOST' => 'foo.bar', |
||
125 | 'SERVER_PORT' => '80', |
||
126 | 'REQUEST_URI' => '/foo.php', |
||
127 | ]; |
||
128 | |||
129 | $urlHandler = new FacebookUrlDetectionHandler(); |
||
130 | $currentUri = $urlHandler->getCurrentUrl(); |
||
131 | |||
132 | $this->assertEquals('http://foo.bar:8888/foo.php', $currentUri); |
||
133 | } |
||
134 | } |
||
135 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: