Skip to content

Commit 721d349

Browse files
committed
Merge branch 'temp' into 'fix-email-delivery-error-log'
2 parents 656e098 + 071ff39 commit 721d349

File tree

15 files changed

+150
-47
lines changed

15 files changed

+150
-47
lines changed

.github/release.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
changelog:
2+
exclude:
3+
authors:
4+
- dependabot
5+
categories:
6+
- title: Breaking Changes
7+
labels:
8+
- 'breaking change'
9+
- title: Fixed Bugs
10+
labels:
11+
- bug
12+
- title: New Features
13+
labels:
14+
- 'new feature'
15+
- title: Enhancements
16+
labels:
17+
- enhancement
18+
- title: Refactoring
19+
labels:
20+
- refactor
21+
- title: Others (Only for checking. Remove this category)
22+
labels:
23+
- "*"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ access for a mobile application that you build.
3535

3636
Usage of Shield requires the following:
3737

38-
- A [CodeIgniter 4](https://github.com/codeigniter4/CodeIgniter4/)-based project
38+
- A [CodeIgniter 4.2.3+](https://github.com/codeigniter4/CodeIgniter4/) based project
3939
- [Composer](https://getcomposer.org/) for package management
4040
- PHP 7.4.3+
4141

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
"require-dev": {
2525
"codeigniter4/devkit": "^1.0",
26-
"codeigniter4/framework": "^4.1",
26+
"codeigniter4/framework": "^4.2.3",
2727
"mockery/mockery": "^1.0"
2828
},
2929
"provide": {

docs/customization.md

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -95,35 +95,47 @@ Shield has the following rules for registration:
9595

9696
```php
9797
[
98-
'username' => [
99-
'required',
100-
'max_length[30]',
101-
'min_length[3]',
102-
'regex_match[/\A[a-zA-Z0-9\.]+\z/]',
103-
'is_unique[users.username]',
104-
],
105-
'email' => 'required|max_length[254]|valid_email|is_unique[auth_identities.secret]',
106-
'password' => 'required|strong_password',
107-
'password_confirm' => 'required|matches[password]',
98+
'username' => [
99+
'label' => 'Auth.username',
100+
'rules' => 'required|max_length[30]|min_length[3]|regex_match[/\A[a-zA-Z0-9\.]+\z/]|is_unique[users.username]',
101+
],
102+
'email' => [
103+
'label' => 'Auth.email',
104+
'rules' => 'required|max_length[254]|valid_email|is_unique[auth_identities.secret]',
105+
],
106+
'password' => [
107+
'label' => 'Auth.password',
108+
'rules' => 'required|strong_password',
109+
],
110+
'password_confirm' => [
111+
'label' => 'Auth.passwordConfirm',
112+
'rules' => 'required|matches[password]',
113+
],
108114
];
109115
```
110116

111117
If you need a different set of rules for registration, you can specify them in your `Validation` configuration (**app/Config/Validation.php**) like:
112118

113119
```php
114-
//--------------------------------------------------------------------
115-
// Rules
116-
//--------------------------------------------------------------------
117-
public $registration = [
118-
'username' => [
119-
'required',
120-
'max_length[30]',
121-
'min_length[3]',
122-
'regex_match[/\A[a-zA-Z0-9\.]+\z/]',
123-
'is_unique[users.username]',
120+
//--------------------------------------------------------------------
121+
// Rules
122+
//--------------------------------------------------------------------
123+
public $registration = [
124+
'username' => [
125+
'label' => 'Auth.username',
126+
'rules' => 'required|max_length[30]|min_length[3]|regex_match[/\A[a-zA-Z0-9\.]+\z/]|is_unique[users.username]',
124127
],
125-
'email' => 'required|max_length[254]|valid_email|is_unique[auth_identities.secret]',
126-
'password' => 'required|strong_password',
127-
'password_confirm' => 'required|matches[password]',
128-
];
128+
'email' => [
129+
'label' => 'Auth.email',
130+
'rules' => 'required|max_length[254]|valid_email|is_unique[auth_identities.secret]',
131+
],
132+
'password' => [
133+
'label' => 'Auth.password',
134+
'rules' => 'required|strong_password',
135+
],
136+
'password_confirm' => [
137+
'label' => 'Auth.passwordConfirm',
138+
'rules' => 'required|matches[password]',
139+
],
140+
];
129141
```

docs/install.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212

1313
These instructions assume that you have already [installed the CodeIgniter 4 app starter](https://codeigniter.com/user_guide/installation/installing_composer.html) as the basis for your new project, set up your `.env` file, and created a database that you can access via the Spark CLI script.
1414

15+
> **Note**
16+
> CodeIgniter Shield requires Codeigniter v4.2.3 or later.
17+
18+
> **Note**
19+
> You must set ``Config\Security::$csrfProtection`` to `'session'` (or set `security.csrfProtection = session` in your `.env` file) for security reasons, if you use Session Authenticator.
20+
1521
Installation is done through [Composer](https://getcomposer.org). The example assumes you have it installed globally.
1622
If you have it installed as a phar, or othewise you will need to adjust the way you call composer itself.
1723

src/Authentication/Actions/Email2FA.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function handle(IncomingRequest $request)
7777
$email->setMessage(view(setting('Auth.views')['action_email_2fa_email'], ['code' => $identity->secret]));
7878

7979
if ($email->send(false) === false) {
80-
throw new RuntimeException('Cannot send email for user: ' . $user->email . '\n' . $email->printDebugger(['headers']));
80+
throw new RuntimeException('Cannot send email for user: ' . $user->email . "\n" . $email->printDebugger(['headers']));
8181
}
8282

8383
return view(setting('Auth.views')['action_email_2fa_verify']);
@@ -114,7 +114,7 @@ public function afterLogin(User $user): void
114114
$this->createIdentity($user);
115115
}
116116

117-
private function createIdentity(User $user): void
117+
final protected function createIdentity(User $user): void
118118
{
119119
/** @var UserIdentityModel $identityModel */
120120
$identityModel = model(UserIdentityModel::class);

src/Authentication/Actions/EmailActivator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function show(): string
4747
$email->setMessage(view(setting('Auth.views')['action_email_activate_email'], ['code' => $code]));
4848

4949
if ($email->send(false) === false) {
50-
throw new RuntimeException('Cannot send email for user: ' . $user->email . '\n' . $email->printDebugger(['headers']));
50+
throw new RuntimeException('Cannot send email for user: ' . $user->email . "\n" . $email->printDebugger(['headers']));
5151
}
5252

5353
// Display the info page
@@ -100,7 +100,7 @@ public function afterRegister(User $user): void
100100
$this->createIdentity($user);
101101
}
102102

103-
private function createIdentity(User $user): string
103+
final protected function createIdentity(User $user): string
104104
{
105105
/** @var UserIdentityModel $identityModel */
106106
$identityModel = model(UserIdentityModel::class);

src/Authentication/Authenticators/Session.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
use CodeIgniter\Shield\Entities\UserIdentity;
1616
use CodeIgniter\Shield\Exceptions\InvalidArgumentException;
1717
use CodeIgniter\Shield\Exceptions\LogicException;
18+
use CodeIgniter\Shield\Exceptions\SecurityException;
1819
use CodeIgniter\Shield\Models\LoginModel;
1920
use CodeIgniter\Shield\Models\RememberModel;
2021
use CodeIgniter\Shield\Models\UserIdentityModel;
2122
use CodeIgniter\Shield\Models\UserModel;
2223
use CodeIgniter\Shield\Result;
24+
use Config\Security;
25+
use Config\Services;
2326
use stdClass;
2427

2528
class Session implements AuthenticatorInterface
@@ -72,6 +75,25 @@ public function __construct(UserModel $provider)
7275
$this->loginModel = model(LoginModel::class);
7376
$this->rememberModel = model(RememberModel::class);
7477
$this->userIdentityModel = model(UserIdentityModel::class);
78+
79+
$this->checkSecurityConfig();
80+
}
81+
82+
/**
83+
* Checks less secure Configuration.
84+
*/
85+
private function checkSecurityConfig(): void
86+
{
87+
/** @var Security $securityConfig */
88+
$securityConfig = config('Security');
89+
90+
if ($securityConfig->csrfProtection === 'cookie') {
91+
throw new SecurityException(
92+
'Config\Security::$csrfProtection is set to \'cookie\'.'
93+
. ' Same-site attackers may bypass the CSRF protection.'
94+
. ' Please set it to \'session\'.'
95+
);
96+
}
7597
}
7698

7799
/**
@@ -567,7 +589,10 @@ public function startLogin(User $user): void
567589

568590
// Regenerate the session ID to help protect against session fixation
569591
if (ENVIRONMENT !== 'testing') {
570-
session()->regenerate();
592+
session()->regenerate(true);
593+
594+
// Regenerate CSRF token even if `security.regenerate = false`.
595+
Services::security()->generateHash();
571596
}
572597

573598
// Let the session know we're logged in

src/Controllers/LoginController.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,18 @@ public function loginAction(): RedirectResponse
7070
protected function getValidationRules(): array
7171
{
7272
return setting('Validation.login') ?? [
73-
//'username' => config('AuthSession')->usernameValidationRules,
74-
'email' => config('AuthSession')->emailValidationRules,
75-
'password' => 'required',
73+
// 'username' => [
74+
// 'label' => 'Auth.username',
75+
// 'rules' => config('AuthSession')->usernameValidationRules,
76+
// ],
77+
'email' => [
78+
'label' => 'Auth.email',
79+
'rules' => config('AuthSession')->emailValidationRules,
80+
],
81+
'password' => [
82+
'label' => 'Auth.password',
83+
'rules' => 'required',
84+
],
7685
];
7786
}
7887

src/Controllers/MagicLinkController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,10 @@ private function recordLoginAttempt(
192192
protected function getValidationRules(): array
193193
{
194194
return [
195-
'email' => config('AuthSession')->emailValidationRules,
195+
'email' => [
196+
'label' => 'Auth.email',
197+
'rules' => config('AuthSession')->emailValidationRules,
198+
],
196199
];
197200
}
198201
}

0 commit comments

Comments
 (0)