Skip to content

Commit eb0998f

Browse files
authored
Validate first cache command argument type before using as string (#668)
1 parent 138990b commit eb0998f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Sentry/Laravel/Features/CacheIntegration.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Contracts\Events\Dispatcher;
77
use Illuminate\Redis\Events as RedisEvents;
88
use Illuminate\Redis\RedisManager;
9+
use Illuminate\Support\Str;
910
use Sentry\Breadcrumb;
1011
use Sentry\Laravel\Features\Concerns\ResolvesEventOrigin;
1112
use Sentry\Laravel\Integration;
@@ -81,7 +82,16 @@ public function handleRedisCommand(RedisEvents\CommandExecuted $event): void
8182

8283
$context = new SpanContext();
8384
$context->setOp('db.redis');
84-
$context->setDescription(strtoupper($event->command) . ' ' . ($event->parameters[0] ?? null));
85+
86+
$keyForDescription = '';
87+
88+
// If the first parameter is a string and does not contain a newline we use it as the description since it's most likely a key
89+
// This is not a perfect solution but it's the best we can do without understanding the command that was executed
90+
if (!empty($event->parameters[0]) && is_string($event->parameters[0]) && !Str::contains($event->parameters[0], "\n")) {
91+
$keyForDescription = $event->parameters[0];
92+
}
93+
94+
$context->setDescription(rtrim(strtoupper($event->command) . ' ' . $keyForDescription));
8595
$context->setStartTimestamp(microtime(true) - $event->time / 1000);
8696
$context->setEndTimestamp($context->getStartTimestamp() + $event->time / 1000);
8797

0 commit comments

Comments
 (0)