feat: popup quảng cáo, đặt lại mật khẩu bằng token 80 ký tự, 2FA email, vá lỗ hổng bảo mật
- Popup/banner quảng cáo cấu hình từ admin (loại, link, lịch hiển thị) - Đặt lại mật khẩu: token 80 ký tự kèm check digit Luhn thay cho token+email lộ trong URL, chỉ lưu bản băm, một lần dùng, hết hạn 60 phút - Xác thực 2 lớp qua email khi đăng nhập (mã 6 số, ghi nhớ thiết bị 90 ngày) - ApiAuthCheck chặn ngay tài khoản bị khoá dù JWT còn hạn (trước đây dùng được tới hết TTL) - Handler trả 404 thay vì 500 khi ModelNotFoundException không bọc HttpException - Test ClientTamperingTest: xác nhận IDOR/giả mạo dữ liệu từ client đều bị chặn Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
e888a6ed5d
commit
12d5b4951c
@@ -22,6 +22,7 @@ class CustomerFactory extends Factory
|
||||
'email' => $this->faker->unique()->safeEmail(),
|
||||
'email_verify' => now(),
|
||||
'password' => '$2y$10$2Tcx805kaC.Ug/IUD34pW.R.D0l0Gpy.IEeXkrjhBr1uu048pEFp.',
|
||||
'status' => 1,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('popup_banners', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('title', 150);
|
||||
$table->string('type', 30)->index();
|
||||
$table->string('image_path');
|
||||
$table->string('link_url')->nullable();
|
||||
$table->boolean('open_in_new_tab')->default(false);
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->timestamp('starts_at')->nullable();
|
||||
$table->timestamp('ends_at')->nullable();
|
||||
$table->unsignedSmallInteger('sort_order')->default(0);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('popup_banners');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
public function up(): void
|
||||
{
|
||||
DB::table('password_resets')->delete();
|
||||
|
||||
Schema::table('password_resets', function (Blueprint $table) {
|
||||
$table->index('token');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('password_resets', function (Blueprint $table) {
|
||||
$table->dropIndex(['token']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('customers', function (Blueprint $table) {
|
||||
$table->boolean('two_factor_enabled')->default(false);
|
||||
});
|
||||
|
||||
Schema::create('customer_trusted_devices', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('customer_id')->index();
|
||||
$table->char('token_hash', 64)->unique();
|
||||
$table->string('user_agent', 255)->nullable();
|
||||
$table->string('ip_address', 45)->nullable();
|
||||
$table->timestamp('last_used_at')->nullable();
|
||||
$table->timestamp('expires_at')->index();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('customer_trusted_devices');
|
||||
|
||||
Schema::table('customers', function (Blueprint $table) {
|
||||
$table->dropColumn('two_factor_enabled');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
use Database\Seeders\TemplateSeeder;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration {
|
||||
public function up(): void
|
||||
{
|
||||
(new TemplateSeeder())->seedScenarioIfMissing('customer_two_factor_code');
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
DB::table('template')->where('scenario', 'customer_two_factor_code')->delete();
|
||||
}
|
||||
};
|
||||
@@ -34,6 +34,17 @@ final class AccountTemplates
|
||||
. T::paragraph('Nếu Quý khách không yêu cầu, vui lòng bỏ qua email này — mật khẩu hiện tại vẫn giữ nguyên. Mọi thắc mắc xin liên hệ <strong>support@tgs.com.vn</strong> hoặc <strong>(028) 7309. 7379</strong>.')
|
||||
. T::note('Không chia sẻ link này cho bất kỳ ai, kể cả nhân viên Thế Giới Số.'),
|
||||
],
|
||||
[
|
||||
'scenario' => 'customer_two_factor_code',
|
||||
'name' => 'Mã xác thực 2 lớp (2FA)',
|
||||
'subject' => '[{{app_name}}] Mã xác thực {{otp_purpose}}',
|
||||
'body' => T::title('Mã xác thực 2 lớp')
|
||||
. T::greeting('{{full_name}}')
|
||||
. T::paragraph('Quý khách đang thực hiện <strong>{{otp_purpose}}</strong>. Vui lòng nhập mã dưới đây để tiếp tục:')
|
||||
. T::highlight('{{verify_code}}')
|
||||
. T::paragraph('Mã có hiệu lực trong <strong>{{expire_minutes}} phút</strong> và chỉ dùng được một lần. Nếu Quý khách không thực hiện thao tác này, vui lòng đổi mật khẩu ngay và liên hệ <strong>support@tgs.com.vn</strong>.')
|
||||
. T::note('Không chia sẻ mã này cho bất kỳ ai, kể cả nhân viên Thế Giới Số.'),
|
||||
],
|
||||
[
|
||||
'scenario' => 'password_reset_admin',
|
||||
'name' => 'Admin cấp lại mật khẩu',
|
||||
|
||||
@@ -20,8 +20,9 @@ final class TemplateVariables
|
||||
'email' => ['Email đăng nhập', 'string', 'khachhang@example.com'],
|
||||
|
||||
'verify_code' => ['Mã xác thực', 'string', '482913'],
|
||||
'reset_url' => ['Link đặt lại mật khẩu', 'url', 'https://tgs.com.vn/dat-lai-mat-khau?token=abc'],
|
||||
'reset_url' => ['Link đặt lại mật khẩu', 'url', 'https://tgs.com.vn/dat-lai-mat-khau?t=abc'],
|
||||
'expire_minutes' => ['Số phút hiệu lực', 'string', '60'],
|
||||
'otp_purpose' => ['Mục đích mã xác thực', 'string', 'đăng nhập tài khoản'],
|
||||
'password' => ['Mật khẩu mới', 'string', 'Xk9#pL2m'],
|
||||
|
||||
'product_name' => ['Tên dịch vụ', 'string', 'Cloud VPS Pro'],
|
||||
|
||||
@@ -27,6 +27,19 @@ class TemplateSeeder extends Seeder
|
||||
}
|
||||
}
|
||||
|
||||
public function seedScenarioIfMissing(string $scenario): void
|
||||
{
|
||||
if (Template::query()->where('key', $scenario)->orWhere('scenario', $scenario)->exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (self::templates() as $item) {
|
||||
if ($item['scenario'] === $scenario) {
|
||||
$this->upsert($item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function createMarketingIfMissing(array $item): void
|
||||
{
|
||||
$template = Template::firstOrNew(['name' => $item['name']]);
|
||||
|
||||
Reference in New Issue
Block a user