feat(service): custom product, lịch sử giám sát VM và mã hoá response theo phiên
- Dịch vụ custom: bảng custom_products + services.custom_product_id; createService nhận
custom{} thay product_id, giá = đơn giá tháng x số tháng chu kỳ (1/3/6/12/24/36),
gia hạn tính theo cùng đơn giá, ServiceClientDetailResource trả custom_product và specs.
- Giám sát VM: GET v1/system/vm-metrics/history gom lịch sử về tối đa 240 điểm;
lỗi lấy dung lượng đĩa không còn làm hỏng cả thẻ metrics.
- SealResponse: AES-256-GCM theo khoá phiên do proxy Next cấp qua header x-seal-key
(HMAC của session id). Client opt-in bằng x-seal; chi tiết dịch vụ, mật khẩu VM và
console ticket luôn được mã hoá. Body gửi lên dạng {enc} được giải mã trước validate;
khoá lệch trả 428 để client lấy khoá mới. Đây là che mắt DevTools, không phải bảo mật
chống chính chủ tài khoản.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
8108e8fe53
commit
6315a392c0
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Support\ResponseCipher;
|
||||
use Closure;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SealResponse
|
||||
{
|
||||
public const KEY_HEADER = 'x-seal-key';
|
||||
|
||||
public const OPT_IN_HEADER = 'x-seal';
|
||||
|
||||
private const SEALED_ATTRIBUTE = 'response_sealed';
|
||||
|
||||
public function handle(Request $request, Closure $next, ?string $mode = null)
|
||||
{
|
||||
$key = ResponseCipher::keyFrom($request->headers->get(self::KEY_HEADER));
|
||||
|
||||
if ($this->openRequest($request, $key) === false) {
|
||||
return new JsonResponse(['message' => 'Khoá phiên không khớp, vui lòng thử lại.'], 428);
|
||||
}
|
||||
|
||||
$response = $next($request);
|
||||
|
||||
$wanted = $mode === 'always' || $request->headers->get(self::OPT_IN_HEADER) === '1';
|
||||
if (! $key || ! $wanted || $request->attributes->has(self::SEALED_ATTRIBUTE) || ! $response instanceof JsonResponse) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$request->attributes->set(self::SEALED_ATTRIBUTE, true);
|
||||
$response->setData(['enc' => ResponseCipher::seal($response->getContent(), $key)]);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
private function openRequest(Request $request, ?string $key): ?bool
|
||||
{
|
||||
$sealed = $request->isJson() ? $request->json('enc') : null;
|
||||
if (! is_string($sealed)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = $key ? json_decode((string) ResponseCipher::open($sealed, $key), true) : null;
|
||||
if (! is_array($data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$request->json()->replace($data);
|
||||
$request->request->replace($data);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user