@@ -67,6 +67,17 @@ class PortalQaAuthTrace
|
||||
}
|
||||
$response = $next($request);
|
||||
$state = self::state($request);
|
||||
$loginInputCheck = null;
|
||||
if ($request->isMethod('POST') && $request->is('login')) {
|
||||
$email = $request->input('email');
|
||||
$password = $request->input('password');
|
||||
$actor = \App\Models\User::find(18);
|
||||
$emailMatches = is_string($email) && $actor && $email === $actor->email;
|
||||
$loginInputCheck = ['expected_qa_account' => 18, 'email_exact_matches_qa18' => (bool) $emailMatches,
|
||||
'password_matches_qa18' => $emailMatches && is_string($password)
|
||||
? \Illuminate\Support\Facades\Hash::check($password, $actor->password) : null];
|
||||
unset($email, $password, $actor);
|
||||
}
|
||||
$persisted = null;
|
||||
if ($request->hasSession()) {
|
||||
$raw = $request->session()->getHandler()->read($request->session()->getId());
|
||||
@@ -88,7 +99,11 @@ class PortalQaAuthTrace
|
||||
$entry = ['at_utc' => gmdate('c'), 'trace' => $trace, 'method' => $request->method(), 'path' => '/'.$request->path(),
|
||||
'origin' => $request->getSchemeAndHttpHost(), 'cookie_name_counts' => $names,
|
||||
'inertia' => $request->headers->has('X-Inertia'), 'json_expected' => $request->expectsJson(),
|
||||
'inertia_version_matches' => $request->headers->has('X-Inertia-Version')
|
||||
? hash_equals((string) app(\App\Http\Middleware\HandleInertiaRequests::class)->version($request), (string) $request->headers->get('X-Inertia-Version')) : null,
|
||||
'qa_restored_account_rejected' => $request->attributes->get('qa_restored_account_rejected', false),
|
||||
'login_input_check' => $loginInputCheck, // Booleans only: no submitted values or password fingerprints.
|
||||
'mfa_input_check' => $request->attributes->get('qa_mfa_input_check'),
|
||||
'loaded' => $request->attributes->get('qa_auth_loaded'), 'after' => $state, 'persisted' => $persisted,
|
||||
'status' => $response->getStatusCode(), 'redirect' => self::destination($response->headers->get('Location') ?? $response->headers->get('X-Inertia-Location')),
|
||||
'set_cookie_attributes' => $cookies, 'default_guard' => config('auth.defaults.guard'), 'fortify_guard' => config('fortify.guard'),
|
||||
@@ -99,9 +114,13 @@ class PortalQaAuthTrace
|
||||
'qa_target' => config('database.connections.pgsql.database').':'.config('database.connections.pgsql.port'),
|
||||
'config_cached' => app()->configurationIsCached()];
|
||||
$file = storage_path('app/private/investmoz-v2/portal-audit/auth-session-trace-qa.jsonl');
|
||||
if (! is_file($file) || filesize($file) < 5 * 1024 * 1024) {
|
||||
file_put_contents($file, json_encode($entry, JSON_THROW_ON_ERROR).PHP_EOL, FILE_APPEND | LOCK_EX);
|
||||
// Preserve the original trace. A full file must not silently stop QA diagnostics.
|
||||
$segment = 0;
|
||||
while (is_file($file) && filesize($file) >= 5 * 1024 * 1024) {
|
||||
$segment++;
|
||||
$file = storage_path('app/private/investmoz-v2/portal-audit/auth-session-trace-qa-'.gmdate('Ymd').'-'.$segment.'.jsonl');
|
||||
}
|
||||
file_put_contents($file, json_encode($entry, JSON_THROW_ON_ERROR).PHP_EOL, FILE_APPEND | LOCK_EX);
|
||||
$response->headers->set('X-Investmoz-QA-Auth-Trace', $trace);
|
||||
|
||||
return $response;
|
||||
@@ -114,6 +133,34 @@ class PortalQaSessionTrace
|
||||
{
|
||||
if ($request->attributes->has('qa_auth_trace')) {
|
||||
$request->attributes->set('qa_auth_loaded', PortalQaAuthTrace::state($request));
|
||||
if ($request->isMethod('POST') && $request->is('two-factor-challenge') && (int) $request->session()->get('login.id') === 18) {
|
||||
// Diagnostic only: never consume a code, extend acceptance windows or authenticate.
|
||||
$code = $request->input('code');
|
||||
$check = ['account_id' => 18, 'six_digits' => is_string($code) && preg_match('/^[0-9]{6}$/D', $code) === 1];
|
||||
try {
|
||||
$actor = \App\Models\User::findOrFail(18);
|
||||
$secret = app('encrypter')->decrypt($actor->two_factor_secret);
|
||||
$check['secret_decrypts'] = is_string($secret);
|
||||
if ($check['six_digits'] && $check['secret_decrypts']) {
|
||||
$engine = new \PragmaRX\Google2FA\Google2FA;
|
||||
$window = config('fortify-options.two-factor-authentication.window');
|
||||
if (is_int($window)) $engine->setWindow($window);
|
||||
$previous = app('cache.store')->get('fortify.2fa_codes.'.md5($code));
|
||||
$check['matches_configured_time_window'] = $engine->verifyKey($secret, $code);
|
||||
$check['previously_used_in_cache'] = $previous !== null;
|
||||
$check['accepted_by_replay_check'] = $engine->verifyKeyNewer($secret, $code, $previous) !== false;
|
||||
$engine->setWindow(12);
|
||||
$check['matches_wider_diagnostic_window_only'] = ! $check['matches_configured_time_window'] && $engine->verifyKey($secret, $code);
|
||||
}
|
||||
} catch (\Illuminate\Contracts\Encryption\DecryptException) {
|
||||
$check['secret_decrypts'] = false;
|
||||
} catch (\Throwable) {
|
||||
$check['diagnostic_unavailable'] = true;
|
||||
} finally {
|
||||
unset($code, $actor, $secret, $engine, $previous);
|
||||
}
|
||||
$request->attributes->set('qa_mfa_input_check', $check);
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
||||
Reference in New Issue
Block a user