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 | /** |
||
4 | * Mastodon SampleApp routes config |
||
5 | * |
||
6 | * @author USAMI Kenta <[email protected]> |
||
7 | * @copyright 2017 Baguette HQ |
||
8 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPL-3.0 |
||
9 | */ |
||
10 | |||
11 | use Teto\Routing\Action; |
||
12 | use Baguette\Mastodon as m; |
||
13 | use Baguette\Mastodon\Service\AuthFactory; |
||
14 | use Baguette\Mastodon\Grant\CodeGrant; |
||
15 | |||
16 | const RE_ACCT = '/\A[_a-z0-9]+@[-:.a-z0-9]+\z/'; |
||
17 | |||
18 | $routes = []; |
||
19 | $routes['index'] = ['GET', '/', function (Action $action) { |
||
0 ignored issues
–
show
|
|||
20 | chrome_log()->info('Hello, World!'); |
||
21 | chrome_log()->info('session', $_SESSION); |
||
22 | |||
23 | return [200, [], view('index')]; |
||
24 | }]; |
||
25 | |||
26 | $routes['acct'] = ['GET', '/acct/:acct', function (Action $action) { |
||
27 | chrome_log()->info('session', $_SESSION); |
||
28 | |||
29 | $acct_input = $action->param['acct']; |
||
30 | |||
31 | View Code Duplication | if (!isset($_SESSION['mastodons'][$acct_input])) { |
|
0 ignored issues
–
show
This code seems to be duplicated across 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. ![]() |
|||
32 | set_flash(['error' => "Not logged in: {$acct_input}"]); |
||
33 | return [302, ['Location' => '/'], null]; |
||
34 | }; |
||
35 | |||
36 | return [200, [], view('acct', [ |
||
37 | 'acct' => $acct_input, |
||
38 | ])]; |
||
39 | }, ['acct' => RE_ACCT]]; |
||
40 | |||
41 | $routes['license'] = ['GET', '/license', function (Action $action) { |
||
0 ignored issues
–
show
|
|||
42 | $path = __DIR__ . '/../../LICENSE'; |
||
43 | return [200, ['Content-Type' => 'text/plain;charset=UTF-8'], file_get_contents($path)]; |
||
44 | }]; |
||
45 | |||
46 | $routes['post_login'] = ['POST', '/login', function (Action $action) { |
||
0 ignored issues
–
show
|
|||
47 | $acct_input = filter_input(INPUT_POST, 'acct', FILTER_DEFAULT); |
||
48 | $acct = ltrim($acct_input, '@'); |
||
49 | |||
50 | if (strpos($acct, '@') === false) { |
||
51 | set_flash(['error' => "Invalid Mastodon account: {$acct_input}"]); |
||
52 | return [302, ['Location' => '/'], null]; |
||
53 | } |
||
54 | |||
55 | list($user, $instance) = explode('@', $acct, 2); |
||
0 ignored issues
–
show
The assignment to
$user is unused. Consider omitting it like so list($first,,$third) .
This checks looks for assignemnts to variables using the Consider the following code example. <?php
function returnThreeValues() {
return array('a', 'b', 'c');
}
list($a, $b, $c) = returnThreeValues();
print $a . " - " . $c;
Only the variables Instead, the list call could have been. list($a,, $c) = returnThreeValues();
![]() |
|||
56 | |||
57 | if (strpos($instance, 'localhost:') === 0 || strpos($instance, '0.0.0.0:') === 0) { |
||
58 | $instance = "http://{$instance}"; |
||
59 | } |
||
60 | |||
61 | $client = new m\Client($instance, ['name' => SERVICE_NAME]); |
||
62 | $scope = m\scope('read write follow'); |
||
63 | $callback_url = app\get_service_base_url(router()->makePath('auth_callback')); |
||
64 | $state = bin2hex(random_bytes(8)); |
||
65 | |||
66 | try { |
||
67 | $app = app\get_client_app($client, $scope, [$callback_url]); |
||
68 | } catch (\Exception $e) { |
||
69 | set_flash(['error' => $e->getMessage()]); |
||
70 | return [302, ['Location' => '/'], null]; |
||
71 | } |
||
72 | |||
73 | $_SESSION['mastodons'] = isset($_SESSION['mastodons']) ? $_SESSION['mastodons'] : []; |
||
74 | |||
75 | View Code Duplication | if (isset($_SESSION['mastodons'][$instance])) { |
|
0 ignored issues
–
show
This code seems to be duplicated across 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. ![]() |
|||
76 | set_flash(['error' => "already linked to {$instance}"]); |
||
77 | return [302, ['Location' => '/'], null]; |
||
78 | } |
||
79 | |||
80 | $_SESSION['login'][$state] = [ |
||
81 | 'instance' => $instance, |
||
82 | 'acct' => $acct, |
||
83 | 'expire' => time() + 600, |
||
84 | ]; |
||
85 | chrome_log()->info("redirect", ['state' => $state, 'session' => $_SESSION]); |
||
86 | |||
87 | //$_SESSION['mastodons'][$instance] = []; |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
77% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
88 | $auth = new m\Service\AuthFactory($client, $app['client_id'], $app['client_secret']); |
||
89 | |||
90 | $redirect_url = m\Grant\CodeGrant::getRedirectUrl($client, $auth, $scope, $callback_url, $state); |
||
91 | return [302, ['Location' => $redirect_url], null]; |
||
92 | }]; |
||
93 | |||
94 | $routes['auth_callback'] = ['GET', '/auth/callback', function (Action $action) { |
||
0 ignored issues
–
show
|
|||
95 | $code_input = filter_input(INPUT_GET, 'code', FILTER_DEFAULT); |
||
96 | $state_input = filter_input(INPUT_GET, 'state', FILTER_DEFAULT); |
||
97 | |||
98 | if (!isset($_SESSION['login'], $_SESSION['login'][$state_input]) || !is_array($_SESSION['login'][$state_input])) { |
||
99 | set_flash(['error' => "invalid login flow."]); |
||
100 | return [302, ['Location' => '/'], null]; |
||
101 | } |
||
102 | |||
103 | $instance = $_SESSION['login'][$state_input]; |
||
104 | $client = new m\Client($instance['instance'], ['name' => SERVICE_NAME]); |
||
105 | $scope = m\scope('read write follow'); |
||
106 | $callback_url = app\get_service_base_url(router()->makePath('auth_callback')); |
||
107 | |||
108 | try { |
||
109 | $app = app\get_client_app($client, $scope, [$callback_url]); |
||
110 | } catch (\Exception $e) { |
||
111 | throw $e; |
||
112 | set_flash(['error' => $e->getMessage()]); |
||
0 ignored issues
–
show
set_flash(array('error' => $e->getMessage())); does not seem to be reachable.
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed. Unreachable code is most often the result of function fx() {
try {
doSomething();
return true;
}
catch (\Exception $e) {
return false;
}
return false;
}
In the above example, the last ![]() |
|||
113 | return [302, ['Location' => '/'], null]; |
||
114 | } |
||
115 | |||
116 | $grant = new CodeGrant($code_input, $callback_url); |
||
117 | $auth_factory = new AuthFactory($client, $app['client_id'], $app['client_secret']); |
||
118 | $auth_factory->setGrant($grant); |
||
119 | |||
120 | try { |
||
121 | $auth = $auth_factory->authorize($scope); |
||
122 | } catch (\Exception $e) { |
||
123 | throw $e; |
||
124 | set_flash(['error' => $e->getMessage()]); |
||
0 ignored issues
–
show
set_flash(array('error' => $e->getMessage())); does not seem to be reachable.
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed. Unreachable code is most often the result of function fx() {
try {
doSomething();
return true;
}
catch (\Exception $e) {
return false;
}
return false;
}
In the above example, the last ![]() |
|||
125 | return [302, ['Location' => '/'], null]; |
||
126 | } |
||
127 | |||
128 | $_SESSION['mastodons'][$instance['acct']] = [ |
||
129 | 'access_token' => $auth->access_token, |
||
130 | 'token_type' => $auth->token_type, |
||
131 | 'scope' => (string)$auth->scope, |
||
132 | 'created_at' => $auth->created_at, |
||
133 | ]; |
||
134 | |||
135 | unset($_SESSION['login'][$state_input]); |
||
136 | |||
137 | return [302, ['Location' => '/'], null]; |
||
138 | }]; |
||
139 | |||
140 | $routes['#404'] = function (Action $action) { |
||
0 ignored issues
–
show
|
|||
141 | return [404, [], view('404')]; |
||
142 | }; |
||
143 | |||
144 | return $routes; |
||
145 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.