Thanks to visit codestin.com
Credit goes to github.com

Skip to content

do not use uniqid() for generating dev tool tokens #57746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function initialize(ConsoleCommandEvent $event): void
return;
}

$request->attributes->set('_stopwatch_token', substr(hash('xxh128', uniqid(mt_rand(), true)), 0, 6));
$request->attributes->set('_stopwatch_token', bin2hex(random_bytes(3)));
$this->stopwatch->openSection();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function beforeDispatch(string $eventName, object $event): void
{
switch ($eventName) {
case KernelEvents::REQUEST:
$event->getRequest()->attributes->set('_stopwatch_token', substr(hash('xxh128', uniqid(mt_rand(), true)), 0, 6));
$event->getRequest()->attributes->set('_stopwatch_token', bin2hex(random_bytes(3)));
$this->stopwatch->openSection();
break;
case KernelEvents::VIEW:
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/Profiler/Profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function collect(Request $request, Response $response, ?\Throwable $excep
return null;
}

$profile = new Profile(substr(hash('xxh128', uniqid(mt_rand(), true)), 0, 6));
$profile = new Profile(bin2hex(random_bytes(3)));
$profile->setTime(time());
$profile->setUrl($request->getUri());
$profile->setMethod($request->getMethod());
Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/Serializer/Debug/TraceableSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(

public function serialize(mixed $data, string $format, array $context = []): string
{
$context[self::DEBUG_TRACE_ID] = $traceId = uniqid('', true);
$context[self::DEBUG_TRACE_ID] = $traceId = bin2hex(random_bytes(4));

$startTime = microtime(true);
$result = $this->serializer->serialize($data, $format, $context);
Expand All @@ -52,7 +52,7 @@ public function serialize(mixed $data, string $format, array $context = []): str

public function deserialize(mixed $data, string $type, string $format, array $context = []): mixed
{
$context[self::DEBUG_TRACE_ID] = $traceId = uniqid('', true);
$context[self::DEBUG_TRACE_ID] = $traceId = bin2hex(random_bytes(4));

$startTime = microtime(true);
$result = $this->serializer->deserialize($data, $type, $format, $context);
Expand All @@ -67,7 +67,7 @@ public function deserialize(mixed $data, string $type, string $format, array $co

public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
{
$context[self::DEBUG_TRACE_ID] = $traceId = uniqid('', true);
$context[self::DEBUG_TRACE_ID] = $traceId = bin2hex(random_bytes(4));

$startTime = microtime(true);
$result = $this->serializer->normalize($object, $format, $context);
Expand All @@ -82,7 +82,7 @@ public function normalize(mixed $object, ?string $format = null, array $context

public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed
{
$context[self::DEBUG_TRACE_ID] = $traceId = uniqid('', true);
$context[self::DEBUG_TRACE_ID] = $traceId = bin2hex(random_bytes(4));

$startTime = microtime(true);
$result = $this->serializer->denormalize($data, $type, $format, $context);
Expand All @@ -97,7 +97,7 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a

public function encode(mixed $data, string $format, array $context = []): string
{
$context[self::DEBUG_TRACE_ID] = $traceId = uniqid('', true);
$context[self::DEBUG_TRACE_ID] = $traceId = bin2hex(random_bytes(4));

$startTime = microtime(true);
$result = $this->serializer->encode($data, $format, $context);
Expand All @@ -112,7 +112,7 @@ public function encode(mixed $data, string $format, array $context = []): string

public function decode(string $data, string $format, array $context = []): mixed
{
$context[self::DEBUG_TRACE_ID] = $traceId = uniqid('', true);
$context[self::DEBUG_TRACE_ID] = $traceId = bin2hex(random_bytes(4));

$startTime = microtime(true);
$result = $this->serializer->decode($data, $format, $context);
Expand Down
Loading