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:
baodev0
2026-10-13 13:23:33 +07:00
co-authored by Claude Sonnet 5
parent e888a6ed5d
commit 12d5b4951c
33 changed files with 1499 additions and 51 deletions
@@ -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();
}
};