BF keep the client's authtoken out of the handler failure log
Every message carries the bearer token as data.authtoken. When a handler threw, Controller::controll_message logged the whole message data with Log::error (and Log::info for validation failures), so the token landed in the app's logs and, through Laravel's log breadcrumbs, in Sentry/GlitchTip. The data is now logged without authtoken. Additive: nothing else changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
0ce00227a4
commit
97784e1fb4
|
|
@ -206,9 +206,15 @@ class Controller
|
|||
|
||||
return $payload;
|
||||
} catch (\Throwable $e) {
|
||||
$data = @$message['data'];
|
||||
// The client's bearer token rides in every message; logs and error trackers
|
||||
// must never hold it.
|
||||
if (is_array($data)) {
|
||||
unset($data['authtoken']);
|
||||
}
|
||||
$reload = [
|
||||
'event' => @$message['event'],
|
||||
'data' => @$message['data'],
|
||||
'data' => $data,
|
||||
'channel' => @$message['channel'],
|
||||
'line' => $e->getFile() . ':' . $e->getLine(),
|
||||
'stack' => $e->getTraceAsString(),
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ use BlaxSoftware\LaravelWebSockets\Test\Unit\Support\RecordingConnection;
|
|||
use BlaxSoftware\LaravelWebSockets\Websocket\Controller;
|
||||
use BlaxSoftware\LaravelWebSockets\Websocket\ControllerResolver;
|
||||
use BlaxSoftware\LaravelWebSockets\Websocket\EventRegistry;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use React\EventLoop\Factory as LoopFactory;
|
||||
|
||||
/**
|
||||
|
|
@ -89,6 +90,18 @@ class DispatcherFallbackTest extends TestCase
|
|||
];
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_keeps_the_auth_token_out_of_the_failure_log()
|
||||
{
|
||||
Log::spy();
|
||||
|
||||
$this->dispatch($this->message('dispatchable.explodes', ['authtoken' => '12|secret-bearer', 'keep' => 'me']));
|
||||
|
||||
Log::shouldHaveReceived('error')->withArgs(
|
||||
fn ($message, $context) => $message === 'boom' && $context['data'] === ['keep' => 'me']
|
||||
)->once();
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────
|
||||
// Fallback path
|
||||
// ─────────────────────────────────────────────────────────────────
|
||||
|
|
|
|||
|
|
@ -56,6 +56,13 @@ class DispatchableController
|
|||
return ['kind' => 'with-default', 'mode' => $mode];
|
||||
}
|
||||
|
||||
/** Throws, so the dispatcher logs the failed message. */
|
||||
#[Websocket(suffix: 'explodes')]
|
||||
public function explodes(): array
|
||||
{
|
||||
throw new \RuntimeException('boom');
|
||||
}
|
||||
|
||||
/** Auth-required method. */
|
||||
#[Websocket(suffix: 'protected', needAuth: true)]
|
||||
public function protectedAction(): array
|
||||
|
|
|
|||
Loading…
Reference in New Issue