Add a read-only Google AdSense analytics module for admins.
Connect AdSense over OAuth, sync entities and daily reports locally, and show placement performance in the admin panel without calling the Management API from public pages.
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services\Adsense;
|
||||
|
||||
final class AdsenseLogSanitizer
|
||||
{
|
||||
/**
|
||||
* @var list<string>
|
||||
*/
|
||||
private const SENSITIVE_KEYS = [
|
||||
'access_token',
|
||||
'refresh_token',
|
||||
'id_token',
|
||||
'token',
|
||||
'code',
|
||||
'client_secret',
|
||||
'authorization',
|
||||
'encrypted_refresh_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $context
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function context(array $context): array
|
||||
{
|
||||
$clean = [];
|
||||
|
||||
foreach ($context as $key => $value) {
|
||||
$normalized = strtolower((string) $key);
|
||||
|
||||
if (in_array($normalized, self::SENSITIVE_KEYS, true) || str_contains($normalized, 'token') || str_contains($normalized, 'secret')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
$clean[$key] = self::context($value);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_string($value) && self::looksLikeSecret($value)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$clean[$key] = $value;
|
||||
}
|
||||
|
||||
return $clean;
|
||||
}
|
||||
|
||||
public static function looksLikeSecret(string $value): bool
|
||||
{
|
||||
if ($value === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (['refresh-secret', 'access-secret', 'ya29.', '1//'] as $marker) {
|
||||
if (str_contains($value, $marker)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user