Issues (152)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  Header Injection
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

api/Controllers/AuthenticationController.php (2 issues)

Labels
Severity
1
<?php
2
3
namespace PhpDraft\Controllers;
4
5
use \Silex\Application;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
9
use PhpDraft\Domain\Entities\LoginUser;
10
use PhpDraft\Domain\Models\PhpDraftResponse;
11
12
class AuthenticationController
13
{
14
  //See Commish->Index for permissions check
15
16
  public function Login(Application $app, Request $request) {
17
    $email = $request->get('_email');
18
    $password = $request->get('_password');
19
20
    $response = new PhpDraftResponse();
21
22
    try {
23
      $credentialValidity = $app['phpdraft.LoginUserValidator']->areLoginCredentialsValid($email, $password);
24
25
      if ($credentialValidity->success == false) {
26
        throw new UsernameNotFoundException(sprintf('Email %s does not exist', $email));
27
      }
28
29
      $user = $app['users']->loadUserByUsername($email);
30
31
      if (!$user->isEnabled() || !$app['security.encoder.digest']->isPasswordValid($user->getPassword(), $password, $user->getSalt())) {
32
        throw new UsernameNotFoundException(sprintf('Email %s does not exist', $email));
33
      } else {
34
        $response->success = true;
35
36
        $response = $app['phpdraft.LoginUserService']->SetAuthenticationObjectValuesOnLogin($response, $user);
37
38
        //If user is enabled, provided valid password and has a verification (pwd reset) key, wipe it (no longer needed)
39
        if ($user->hasVerificationKey()) {
40
          $app['phpdraft.LoginUserRepository']->EraseVerificationKey($user->getEmail());
41
        }
42
      }
43
    } catch (UsernameNotFoundException $e) {
44
      $response->success = false;
45
      $response->errors[] = 'Invalid credentials.';
46
    }
47
48
    return $app->json($response, $response->responseType());
49
  }
50
51
  public function Register(Application $app, Request $request) {
52
    $validity = $app['phpdraft.LoginUserValidator']->IsRegistrationUserValid($request);
53
54
    if (!$validity->success) {
55
      return $app->json($validity, Response::HTTP_BAD_REQUEST);
56
    }
57
58
    //TODO: Remove. Temporary workaround to disable Recaptcha verifications on localhost
59
    $whitelist = array(
60
      '127.0.0.1',
61
      '::1'
62
    );
63
64
    $captcha = $request->get('_recaptcha');
65
    $userIp = $request->getClientIp();
66
67
    if (!in_array($userIp, $whitelist)) {
68
69
      $recaptcha = new \ReCaptcha\ReCaptcha(RECAPTCHA_SECRET);
0 ignored issues
show
The constant PhpDraft\Controllers\RECAPTCHA_SECRET was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
70
      $recaptchaResponse = $recaptcha->verify($captcha, $userIp);
71
72
      if (!$recaptchaResponse->isSuccess()) {
73
        $response = new PhpDraftResponse(false, array());
74
        $response->errors = $recaptchaResponse->getErrorCodes();
75
        return $app->json($response, $response->responseType());
76
      }
77
    }
78
79
    $user = new LoginUser();
80
81
    $user->email = $request->get('_email');
82
    $user->password = $request->get('_password');
83
    $user->name = $request->get('_name');
84
85
    $response = $app['phpdraft.LoginUserService']->CreateUnverifiedNewUser($user);
86
87
    return $app->json($response, $response->responseType());
88
  }
89
90
  public function VerifyAccount(Application $app, Request $request) {
91
    $validity = $app['phpdraft.LoginUserValidator']->IsVerificationValid($request);
92
93
    if (!$validity->success) {
94
      return $app->json($validity, Response::HTTP_BAD_REQUEST);
95
    }
96
97
    $email = $request->get('_email');
98
99
    $user = $app['phpdraft.LoginUserRepository']->Load($email);
100
101
    $response = $app['phpdraft.LoginUserService']->VerifyUser($user);
102
103
    if ($response->success) {
104
      $loginUser = $app['users']->loadUserByUsername($email);
105
      $response = $app['phpdraft.LoginUserService']->SetAuthenticationObjectValuesOnLogin($response, $loginUser);
106
    }
107
108
    return $app->json($response, $response->responseType());
109
  }
110
111
  public function LostPassword(Application $app, Request $request) {
112
    $validity = $app['phpdraft.LoginUserValidator']->IsForgottenPasswordUserValid($request);
113
114
    if (!$validity->success) {
115
      return $app->json($validity, Response::HTTP_BAD_REQUEST);
116
    }
117
118
    $email = $request->get('_email');
119
120
    //TODO: Remove. Temporary workaround to disable Recaptcha verifications on localhost
121
    $whitelist = array(
122
      '127.0.0.1',
123
      '::1'
124
    );
125
126
    $captcha = $request->get('_recaptcha');
127
    $userIp = $request->getClientIp();
128
129
    if (!in_array($userIp, $whitelist)) {
130
131
      $recaptcha = new \ReCaptcha\ReCaptcha(RECAPTCHA_SECRET);
0 ignored issues
show
The constant PhpDraft\Controllers\RECAPTCHA_SECRET was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
132
      $recaptchaResponse = $recaptcha->verify($captcha, $userIp);
133
134
      if (!$recaptchaResponse->isSuccess()) {
135
        $response = new PhpDraftResponse(false, array());
136
        $response->errors = $recaptchaResponse->getErrorCodes();
137
        return $app->json($response, $response->responseType());
138
      }
139
    }
140
141
    $user = $app['phpdraft.LoginUserRepository']->Load($email);
142
143
    $response = $app['phpdraft.LoginUserService']->BeginForgottenPasswordProcess($user);
144
145
    return $app->json($response, $response->responseType());
146
  }
147
148
  public function VerifyResetPasswordToken(Application $app, Request $request) {
149
    $email = $request->get('_email');
150
    $verificationToken = $request->get('_verificationToken');
151
152
    $validity = $app['phpdraft.LoginUserValidator']->IsResetPasswordTokenValid($email, $verificationToken);
153
154
    return $app->json($validity, $validity->responseType());
155
  }
156
157
  public function ResetPassword(Application $app, Request $request) {
158
    $validity = $app['phpdraft.LoginUserValidator']->IsResetPasswordRequestValid($request);
159
160
    if (!$validity->success) {
161
      return $app->json($validity, Response::HTTP_BAD_REQUEST);
162
    }
163
164
    $email = $request->get('_email');
165
    $password = $request->get('_password');
166
167
    $user = $app['phpdraft.LoginUserRepository']->Load($email);
168
169
    $user->password = $password;
170
171
    $response = $app['phpdraft.LoginUserService']->ResetPassword($user);
172
173
    if ($response->success) {
174
      $loginUser = $app['users']->loadUserByUsername($email);
175
      $response = $app['phpdraft.LoginUserService']->SetAuthenticationObjectValuesOnLogin($response, $loginUser);
176
    }
177
178
    return $app->json($response, $response->responseType());
179
  }
180
}
181