1 | <?php |
||||
2 | /****************************************************************************** |
||||
3 | * Wikipedia Account Creation Assistance tool * |
||||
4 | * ACC Development Team. Please see team.json for a list of contributors. * |
||||
5 | * * |
||||
6 | * This is free and unencumbered software released into the public domain. * |
||||
7 | * Please see LICENSE.md for the full licencing statement. * |
||||
8 | ******************************************************************************/ |
||||
9 | |||||
10 | namespace Waca\Pages; |
||||
11 | |||||
12 | use Waca\DataObjects\Domain; |
||||
13 | use Waca\DataObjects\User; |
||||
14 | use Waca\Exceptions\AccessDeniedException; |
||||
15 | use Waca\Exceptions\DomainSwitchNotAllowedException; |
||||
16 | use Waca\Router\RequestRouter; |
||||
17 | use Waca\Tasks\InternalPageBase; |
||||
18 | use Waca\WebRequest; |
||||
19 | |||||
20 | class PageDomainSwitch extends InternalPageBase |
||||
21 | { |
||||
22 | /** |
||||
23 | * @inheritDoc |
||||
24 | */ |
||||
25 | protected function main() |
||||
26 | { |
||||
27 | if (!WebRequest::wasPosted()) { |
||||
28 | $this->redirect('/'); |
||||
29 | |||||
30 | return; |
||||
31 | } |
||||
32 | |||||
33 | $database = $this->getDatabase(); |
||||
34 | $currentUser = User::getCurrent($database); |
||||
35 | |||||
36 | /** @var Domain|false $newDomain */ |
||||
37 | $newDomain = Domain::getById(WebRequest::postInt('newdomain'), $database); |
||||
38 | |||||
39 | if ($newDomain === false) { |
||||
0 ignored issues
–
show
introduced
by
![]() |
|||||
40 | $this->redirect('/'); |
||||
41 | |||||
42 | return; |
||||
43 | } |
||||
44 | |||||
45 | try { |
||||
46 | $this->getDomainAccessManager()->switchDomain($currentUser, $newDomain); |
||||
47 | } |
||||
48 | catch(DomainSwitchNotAllowedException $ex){ |
||||
49 | throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
||||
50 | } |
||||
51 | |||||
52 | // try to stay on the same page if possible. |
||||
53 | // This only checks basic ACLs and not domain privileges, so this may still result in a 403. |
||||
54 | |||||
55 | $referrer = WebRequest::postString('referrer'); |
||||
56 | $priorPath = explode('/', $referrer); |
||||
0 ignored issues
–
show
It seems like
$referrer can also be of type null ; however, parameter $string of explode() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
57 | $router = new RequestRouter(); |
||||
58 | $route = $router->getRouteFromPath($priorPath); |
||||
59 | |||||
60 | if ($this->barrierTest($route[1], $currentUser, $route[0])) { |
||||
61 | $this->redirect('/' . $referrer); |
||||
62 | } else { |
||||
63 | $this->redirect('/'); |
||||
64 | } |
||||
65 | } |
||||
66 | } |