Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.
PHP ai-agentsblueskyfacebookinstagramlaravellinkedinmastodonmcpmcp-serveropen-sourcerest-apiself-hostedsocial-mediasocial-media-managementsocial-media-schedulerthreadstiktokvuejsxyoutube
fix: GD memory safety check and redact tokens from exception context
Paulo Castellano6e3dac7a6688
diff --git a/app/Exceptions/Social/SocialPublishException.php b/app/Exceptions/Social/SocialPublishException.phpindex 526730d94..384695e6b 100644--- a/app/Exceptions/Social/SocialPublishException.php+++ b/app/Exceptions/Social/SocialPublishException.php@@ -23,14 +23,36 @@ abstract class SocialPublishException extends RuntimeExceptionpublic function context(): array{return [- 'platform' => $this->platform(),+ 'platform' => static::platform(),'category' => $this->category->value,'platform_error_code' => $this->platformErrorCode,'user_message' => $this->userMessage,- 'raw_response' => $this->rawResponse,+ 'raw_response' => $this->redactTokens($this->rawResponse),];}+ private function redactTokens(?string $text): ?string+ {+ if ($text === null) {+ return null;+ }++ // Redact common token patterns from API error responses+ return preg_replace(+ [+ '/access_token=([^&"\s]+)/',+ '/"access_token"\s*:\s*"([^"]+)"/',+ '/Bearer\s+\S+/',+ ],+ [+ 'access_token=[REDACTED]',+ '"access_token":"[REDACTED]"',+ 'Bearer [REDACTED]',+ ],+ $text+ );+ }+abstract public static function fromApiResponse(mixed $response): static;abstract public function platform(): string;diff --git a/app/Services/Media/MediaOptimizer.php b/app/Services/Media/MediaOptimizer.phpindex d701e0b62..c5f0d1c3b 100644--- a/app/Services/Media/MediaOptimizer.php+++ b/app/Services/Media/MediaOptimizer.php@@ -5,6 +5,7 @@ declare(strict_types=1);namespace App\Services\Media;use App\Enums\SocialAccount\Platform;+use Illuminate\Support\Facades\Log;use Intervention\Image\Drivers\Gd\Driver;use Intervention\Image\ImageManager;@@ -24,6 +25,32 @@ class MediaOptimizerpublic function optimizeImage(string $filePath, Platform $platform): string{$config = $this->getImageConfig($platform);++ // Check image dimensions to prevent GD memory overflow+ $imageInfo = @getimagesize($filePath);+ if ($imageInfo) {+ $width = $imageInfo[0];+ $height = $imageInfo[1];+ $channels = $imageInfo['channels'] ?? 4;+ $estimatedMemory = $width * $height * $channels * 1.5; // 1.5x safety margin++ // If image would use more than 256MB of RAM, skip optimization and return as-is+ if ($estimatedMemory > 256 * 1024 * 1024) {+ Log::warning('MediaOptimizer: Image too large for GD processing', [+ 'width' => $width,+ 'height' => $height,+ 'estimated_memory' => $estimatedMemory,+ 'platform' => $platform->value,+ ]);++ // Copy original file to temp location and return+ $tempFile = tempnam(sys_get_temp_dir(), 'media_opt_');+ copy($filePath, $tempFile);++ return $tempFile;+ }+ }+$image = $this->manager->decodePath($filePath);$maxWidth = data_get($config, 'max_width');