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(security): make SSRF private-network block configurable and guard the last user-URL fetches
Paulo Castellano4a08913d7059
diff --git a/app/Helpers/Upload.php b/app/Helpers/Upload.phpindex 6a1c77f97..0dc2c58d9 100644--- a/app/Helpers/Upload.php+++ b/app/Helpers/Upload.php@@ -2,7 +2,7 @@declare(strict_types=1);-use Illuminate\Support\Facades\Http;+use App\Services\Brand\SafeHttpFetcher;use Illuminate\Support\Facades\Log;use Illuminate\Support\Facades\Storage;use Illuminate\Support\Str;@@ -22,7 +22,7 @@ if (! function_exists('uploadFromUrl')) {}try {- $response = Http::timeout(10)->get($url);+ $response = app(SafeHttpFetcher::class)->guardedRequest($url)->timeout(10)->get($url);if (! $response->successful()) {Log::warning('uploadFromUrl: Failed to download', [diff --git a/app/Http/Controllers/App/AssetController.php b/app/Http/Controllers/App/AssetController.phpindex eab0588d2..3997bf408 100644--- a/app/Http/Controllers/App/AssetController.php+++ b/app/Http/Controllers/App/AssetController.php@@ -9,16 +9,17 @@ use App\Http\Requests\App\Asset\StoreAssetRequest;use App\Http\Requests\App\Asset\StoreChunkedAssetRequest;use App\Http\Resources\App\MediaResource;use App\Models\Media;+use App\Services\Brand\SafeHttpFetcher;use App\Services\UnsplashService;use Illuminate\Http\JsonResponse;use Illuminate\Http\RedirectResponse;use Illuminate\Http\Request;use Illuminate\Http\Resources\Json\AnonymousResourceCollection;-use Illuminate\Support\Facades\Http;use Illuminate\Support\Facades\Storage;use Illuminate\Support\Str;use Inertia\Inertia;use Inertia\Response;+use RuntimeException;use Symfony\Component\HttpFoundation\Response as SymfonyResponse;class AssetController extends Controller@@ -115,7 +116,7 @@ class AssetController extends Controller]);}- public function storeFromUrl(StoreAssetFromUrlRequest $request, UnsplashService $unsplash): MediaResource+ public function storeFromUrl(StoreAssetFromUrlRequest $request, UnsplashService $unsplash, SafeHttpFetcher $safeHttp): MediaResource{$workspace = $request->user()->currentWorkspace;@@ -128,7 +129,13 @@ class AssetController extends Controller$unsplash->trackDownload($downloadLocation);}- $response = Http::timeout(30)->get(data_get($validated, 'url'));+ $url = (string) data_get($validated, 'url');++ try {+ $response = $safeHttp->guardedRequest($url)->timeout(30)->get($url);+ } catch (RuntimeException) {+ abort(SymfonyResponse::HTTP_BAD_REQUEST, 'Failed to download image from URL');+ }if ($response->failed()) {abort(SymfonyResponse::HTTP_BAD_REQUEST, 'Failed to download image from URL');diff --git a/app/Services/Brand/SafeHttpFetcher.php b/app/Services/Brand/SafeHttpFetcher.phpindex 3961a76d1..22695cc10 100644--- a/app/Services/Brand/SafeHttpFetcher.php+++ b/app/Services/Brand/SafeHttpFetcher.php@@ -5,6 +5,7 @@ declare(strict_types=1);namespace App\Services\Brand;use Illuminate\Http\Client\ConnectionException;+use Illuminate\Http\Client\PendingRequest;use Illuminate\Http\Client\Response;use Illuminate\Support\Facades\Http;use RuntimeException;@@ -112,6 +113,22 @@ final class SafeHttpFetcher];}+ /**+ * A PendingRequest with the SSRF guard applied to $url and redirect handling+ * pre-configured (per-hop re-guard when following, or no redirects). Callers+ * add their own timeout / sink / headers and dispatch to the SAME $url, so a+ * user-supplied URL can never be fetched without the guard and redirect+ * protection.+ */+ public function guardedRequest(string $url, bool $followRedirects = true): PendingRequest+ {+ $this->guardAgainstSsrf($url);++ return Http::withUserAgent(self::USER_AGENT)->withOptions(+ $followRedirects ? $this->redirectGuardOptions() : ['allow_redirects' => false],+ );+ }+public function guardAgainstSsrf(string $url): void{$parts = parse_url($url);@@ -127,6 +144,13 @@ final class SafeHttpFetcherthrow new RuntimeException(__('workspaces.create.autofill_errors.missing_host'));}+ // Self-hosted operators can opt into fetching their own internal+ // network. Only the private/reserved-IP rejection below is skipped;+ // the scheme and host checks above still always apply.+ if ((bool) config('trypost.security.allow_private_network')) {+ return;+ }+$ip = gethostbyname($host);if ($ip === $host && filter_var($host, FILTER_VALIDATE_IP) === false) {diff --git a/app/Services/Post/MediaAttacher.php b/app/Services/Post/MediaAttacher.phpindex 37a71267b..ed1782827 100644--- a/app/Services/Post/MediaAttacher.php+++ b/app/Services/Post/MediaAttacher.php@@ -8,7 +8,7 @@ use App\Enums\Media\Type as MediaType;use App\Models\Media;use App\Models\Post;use App\Models\Workspace;-use Illuminate\Support\Facades\Http;+use App\Services\Brand\SafeHttpFetcher;use RuntimeException;use Throwable;@@ -24,6 +24,8 @@ use Throwable;*/class MediaAttacher{+ public function __construct(private readonly SafeHttpFetcher $safeHttp) {}+/*** @param array<int, array{url: string, alt?: ?string}> $urls* @return array{attached: array<int, array<string, mixed>>, failed: array<int, string>}@@ -159,10 +161,10 @@ class MediaAttacher$temp = tempnam(sys_get_temp_dir(), 'media_');try {- $response = Http::timeout(20)+ $response = $this->safeHttp->guardedRequest($url, followRedirects: false)+ ->timeout(20)->sink($temp)->withOptions([- 'allow_redirects' => false,'progress' => static function ($total, $downloaded) use ($cap): void {if ($downloaded > $cap) {throw new RuntimeException('exceeded max bytes');diff --git a/config/trypost.php b/config/trypost.phpindex 1b204b7e1..96749e8ae 100644--- a/config/trypost.php+++ b/config/trypost.php@@ -16,6 +16,22 @@ return ['self_hosted' => env('SELF_HOSTED', true),+ /*+ |--------------------------------------------------------------------------+ | Security+ |--------------------------------------------------------------------------+ |+ | SafeHttpFetcher blocks requests to private/reserved IP ranges (SSRF+ | protection) by default. Self-hosted operators who need to fetch from+ | their own internal network (e.g. an internal RSS feed or webhook) can+ | opt in here. Leave disabled unless you understand the SSRF risk.+ |+ */++ 'security' => [+ 'allow_private_network' => (bool) env('TRYPOST_ALLOW_PRIVATE_NETWORK', false),+ ],+/*|--------------------------------------------------------------------------| Billingdiff --git a/tests/Feature/Api/PostMediaApiTest.php b/tests/Feature/Api/PostMediaApiTest.phpindex cce8c8363..c72976666 100644--- a/tests/Feature/Api/PostMediaApiTest.php+++ b/tests/Feature/Api/PostMediaApiTest.php@@ -13,6 +13,9 @@ use Illuminate\Http\UploadedFile;use Illuminate\Support\Facades\Http;use Illuminate\Support\Facades\Storage;+// A public IP literal as the host lets SafeHttpFetcher's SSRF guard pass without+// a real DNS lookup; Http::fake() intercepts the request before any network I/O.+beforeEach(function () {$result = createApiTestToken();$this->user = $result['user'];@@ -282,7 +285,7 @@ it('downloads and hosts an external media url when creating a post', function ()$this->socialAccount->update(['is_active' => true]);Http::fake([- 'cdn.example.com/listing.jpg' => Http::response(+ '93.184.216.34/listing.jpg' => Http::response(file_get_contents(__DIR__.'/../../fixtures/1x1.png'),200,['Content-Type' => 'image/png'],@@ -292,7 +295,7 @@ it('downloads and hosts an external media url when creating a post', function ()$this->withHeaders(['Authorization' => 'Bearer '.$this->plainToken])->postJson(route('api.posts.store'), ['content' => 'External media post',- 'media' => [['url' => 'https://cdn.example.com/listing.jpg']],+ 'media' => [['url' => 'https://93.184.216.34/listing.jpg']],'platforms' => [['social_account_id' => $this->socialAccount->id, 'content_type' => 'linkedin_post'],],@@ -303,7 +306,7 @@ it('downloads and hosts an external media url when creating a post', function ()expect($media)->toHaveCount(1)->and(data_get($media, '0.path'))->not->toBeNull()- ->and(data_get($media, '0.url'))->not->toContain('cdn.example.com');+ ->and(data_get($media, '0.url'))->not->toContain('93.184.216.34');expect(Media::where('mediable_id', $this->workspace->id)->count())->toBe(1);});@@ -311,7 +314,7 @@ it('persists alt text submitted on a bare external media url', function () {$this->socialAccount->update(['is_active' => true]);Http::fake([- 'cdn.example.com/car.jpg' => Http::response(+ '93.184.216.34/car.jpg' => Http::response(file_get_contents(__DIR__.'/../../fixtures/1x1.png'),200,['Content-Type' => 'image/png'],@@ -322,7 +325,7 @@ it('persists alt text submitted on a bare external media url', function () {->postJson(route('api.posts.store'), ['content' => 'External alt post','media' => [[- 'url' => 'https://cdn.example.com/car.jpg',+ 'url' => 'https://93.184.216.34/car.jpg','meta' => ['alt_text' => 'A red car parked on a hill'],]],'platforms' => [@@ -340,12 +343,12 @@ it('persists alt text submitted on a bare external media url', function () {it('rejects creating a post when an external media url cannot be fetched', function () {$this->socialAccount->update(['is_active' => true]);- Http::fake(['cdn.example.com/missing.jpg' => Http::response(null, 404)]);+ Http::fake(['93.184.216.34/missing.jpg' => Http::response(null, 404)]);$this->withHeaders(['Authorization' => 'Bearer '.$this->plainToken])->postJson(route('api.posts.store'), ['content' => 'Broken media post',- 'media' => [['url' => 'https://cdn.example.com/missing.jpg']],+ 'media' => [['url' => 'https://93.184.216.34/missing.jpg']],'platforms' => [['social_account_id' => $this->socialAccount->id, 'content_type' => 'linkedin_post'],],@@ -361,20 +364,20 @@ it('rolls back already-hosted media when another url in the batch fails', functi$this->socialAccount->update(['is_active' => true]);Http::fake([- 'cdn.example.com/good.jpg' => Http::response(+ '93.184.216.34/good.jpg' => Http::response(file_get_contents(__DIR__.'/../../fixtures/1x1.png'),200,['Content-Type' => 'image/png'],),- 'cdn.example.com/missing.jpg' => Http::response(null, 404),+ '93.184.216.34/missing.jpg' => Http::response(null, 404),]);$this->withHeaders(['Authorization' => 'Bearer '.$this->plainToken])->postJson(route('api.posts.store'), ['content' => 'Partial media post','media' => [- ['url' => 'https://cdn.example.com/good.jpg'],- ['url' => 'https://cdn.example.com/missing.jpg'],+ ['url' => 'https://93.184.216.34/good.jpg'],+ ['url' => 'https://93.184.216.34/missing.jpg'],],'platforms' => [['social_account_id' => $this->socialAccount->id, 'content_type' => 'linkedin_post'],@@ -391,20 +394,20 @@ it('rejects and rolls back when a media url connection fails (timeout/dns)', fun$this->socialAccount->update(['is_active' => true]);Http::fake([- 'cdn.example.com/good.jpg' => Http::response(+ '93.184.216.34/good.jpg' => Http::response(file_get_contents(__DIR__.'/../../fixtures/1x1.png'),200,['Content-Type' => 'image/png'],),- 'cdn.example.com/timeout.jpg' => fn () => throw new ConnectionException('Connection timed out'),+ '93.184.216.34/timeout.jpg' => fn () => throw new ConnectionException('Connection timed out'),]);$this->withHeaders(['Authorization' => 'Bearer '.$this->plainToken])->postJson(route('api.posts.store'), ['content' => 'Timeout media post','media' => [- ['url' => 'https://cdn.example.com/good.jpg'],- ['url' => 'https://cdn.example.com/timeout.jpg'],+ ['url' => 'https://93.184.216.34/good.jpg'],+ ['url' => 'https://93.184.216.34/timeout.jpg'],],'platforms' => [['social_account_id' => $this->socialAccount->id, 'content_type' => 'linkedin_post'],@@ -421,12 +424,12 @@ it('rejects creating a post when an external media url is not a supported type',$this->socialAccount->update(['is_active' => true]);// Downloads fine (200) but the bytes are not a supported media type.- Http::fake(['cdn.example.com/notes.txt' => Http::response('just some text', 200)]);+ Http::fake(['93.184.216.34/notes.txt' => Http::response('just some text', 200)]);$this->withHeaders(['Authorization' => 'Bearer '.$this->plainToken])->postJson(route('api.posts.store'), ['content' => 'Bad type post',- 'media' => [['url' => 'https://cdn.example.com/notes.txt']],+ 'media' => [['url' => 'https://93.184.216.34/notes.txt']],'platforms' => [['social_account_id' => $this->socialAccount->id, 'content_type' => 'linkedin_post'],],@@ -442,7 +445,7 @@ it('keeps an already-hosted item and a freshly-hosted url in order', function ()$this->socialAccount->update(['is_active' => true]);Http::fake([- 'cdn.example.com/external.jpg' => Http::response(+ '93.184.216.34/external.jpg' => Http::response(file_get_contents(__DIR__.'/../../fixtures/1x1.png'),200,['Content-Type' => 'image/png'],@@ -454,7 +457,7 @@ it('keeps an already-hosted item and a freshly-hosted url in order', function ()'content' => 'Mixed media post','media' => [['id' => 'hosted-1', 'path' => 'assets/already.jpg', 'url' => 'https://cdn.trypost.test/assets/already.jpg', 'type' => 'image'],- ['url' => 'https://cdn.example.com/external.jpg'],+ ['url' => 'https://93.184.216.34/external.jpg'],],'platforms' => [['social_account_id' => $this->socialAccount->id, 'content_type' => 'linkedin_post'],@@ -466,7 +469,7 @@ it('keeps an already-hosted item and a freshly-hosted url in order', function ()expect($media)->toHaveCount(2)->and(data_get($media, '0.path'))->toBe('assets/already.jpg')- ->and(data_get($media, '1.url'))->not->toContain('cdn.example.com')+ ->and(data_get($media, '1.url'))->not->toContain('93.184.216.34')->and(data_get($media, '1.path'))->not->toBeNull();// Only the external URL is hosted; the passed-through item creates no new row.expect(Media::where('mediable_id', $this->workspace->id)->count())->toBe(1);@@ -497,7 +500,7 @@ it('passes already-hosted media through on create without downloading', functionit('downloads and hosts an external media url when updating a post', function () {Http::fake([- 'cdn.example.com/listing.jpg' => Http::response(+ '93.184.216.34/listing.jpg' => Http::response(file_get_contents(__DIR__.'/../../fixtures/1x1.png'),200,['Content-Type' => 'image/png'],@@ -507,7 +510,7 @@ it('downloads and hosts an external media url when updating a post', function ()$this->withHeaders(['Authorization' => 'Bearer '.$this->plainToken])->putJson(route('api.posts.update', $this->post), ['status' => 'draft',- 'media' => [['url' => 'https://cdn.example.com/listing.jpg']],+ 'media' => [['url' => 'https://93.184.216.34/listing.jpg']],])->assertOk();@@ -515,18 +518,18 @@ it('downloads and hosts an external media url when updating a post', function ()expect($media)->toHaveCount(1)->and(data_get($media, '0.path'))->not->toBeNull()- ->and(data_get($media, '0.url'))->not->toContain('cdn.example.com');+ ->and(data_get($media, '0.url'))->not->toContain('93.184.216.34');});it('rejects updating a post when an external media url cannot be fetched', function () {- Http::fake(['cdn.example.com/missing.jpg' => Http::response(null, 404)]);+ Http::fake(['93.184.216.34/missing.jpg' => Http::response(null, 404)]);$original = $this->post->fresh()->media;$this->withHeaders(['Authorization' => 'Bearer '.$this->plainToken])->putJson(route('api.posts.update', $this->post), ['status' => 'draft',- 'media' => [['url' => 'https://cdn.example.com/missing.jpg']],+ 'media' => [['url' => 'https://93.184.216.34/missing.jpg']],])->assertUnprocessable()->assertJsonValidationErrors(['media']);diff --git a/tests/Feature/AssetControllerTest.php b/tests/Feature/AssetControllerTest.phpindex bc3541942..0db068bb1 100644--- a/tests/Feature/AssetControllerTest.php+++ b/tests/Feature/AssetControllerTest.php@@ -164,6 +164,43 @@ test('can store asset from url', function () {$response->assertJsonPath('type', 'image');});+test('rejects a raw private-network url before it reaches the controller', function () {+ // StoreAssetFromUrlRequest already allow-lists the host to+ // images.unsplash.com / media*.giphy.com, so a bare private-IP url like+ // 127.0.0.1 never reaches the controller — it 422s at the FormRequest+ // layer. The SSRF guard below is defense-in-depth against a redirect+ // (or DNS rebind) from one of the allow-listed hosts to an internal one.+ $response = $this->actingAs($this->user)+ ->postJson(route('app.assets.store-from-url'), [+ 'url' => 'http://127.0.0.1/evil.jpg',+ 'filename' => 'evil.jpg',+ ]);++ $response->assertUnprocessable();+});++test('blocks store asset from url when an allow-listed host redirects to a private ip', function () {+ Http::fake([+ 'images.unsplash.com/*' => Http::response('', 302, ['Location' => 'http://127.0.0.1/internal']),+ 'http://127.0.0.1/*' => Http::response('internal secret', 200),+ ]);++ $unsplash = $this->mock(UnsplashService::class);+ $unsplash->shouldReceive('trackDownload')->once();++ $response = $this->actingAs($this->user)+ ->postJson(route('app.assets.store-from-url'), [+ 'url' => 'https://images.unsplash.com/photo-test',+ 'filename' => 'unsplash-test.jpg',+ 'download_location' => 'https://api.unsplash.com/photos/test/download',+ ]);++ $response->assertStatus(400);++ Http::assertNotSent(fn ($r) => str_contains($r->url(), '127.0.0.1'));+ expect(Media::count())->toBe(0);+});+test('chunked upload completes with single chunk', function () {// Use real PNG bytes so mime_content_type detects image/png. The MIME// is sniffed from content magic bytes, not the X-File-Name header.diff --git a/tests/Feature/Social/LinkedInControllerTest.php b/tests/Feature/Social/LinkedInControllerTest.phpindex 5d34f1926..8e1c8edee 100644--- a/tests/Feature/Social/LinkedInControllerTest.php+++ b/tests/Feature/Social/LinkedInControllerTest.php@@ -346,18 +346,20 @@ test('selecting the person downloads and stores the avatar', function () {'refresh_token' => 'test-refresh-token','expires_in' => 5184000,'approved_scopes' => ['openid', 'profile', 'email', 'w_member_social'],- 'person' => ['id' => 'person-avatar', 'name' => 'John Doe', 'avatar' => 'https://media.example.com/avatar.jpg', 'vanity_name' => 'johndoe'],+ 'person' => ['id' => 'person-avatar', 'name' => 'John Doe', 'avatar' => 'https://93.184.216.34/avatar.jpg', 'vanity_name' => 'johndoe'],'organizations' => [],]]);+ // A public IP literal as the host lets SafeHttpFetcher's SSRF guard pass+ // without a real DNS lookup; Http::fake() intercepts before any network I/O.Http::fake([- 'https://media.example.com/avatar.jpg' => Http::response('fake-image-bytes', 200, ['Content-Type' => 'image/jpeg']),+ 'https://93.184.216.34/avatar.jpg' => Http::response('fake-image-bytes', 200, ['Content-Type' => 'image/jpeg']),]);$this->actingAs($this->user)->post(route('app.social.linkedin.select'), ['type' => 'person']);// The avatar download (uploadFromUrl) ran and a stored path was persisted.- Http::assertSent(fn ($request) => $request->url() === 'https://media.example.com/avatar.jpg');+ Http::assertSent(fn ($request) => $request->url() === 'https://93.184.216.34/avatar.jpg');$account = SocialAccount::where('platform_user_id', 'person-avatar')->first();expect($account->getRawOriginal('avatar_url'))->not->toBeNull();diff --git a/tests/Unit/HelpersTest.php b/tests/Unit/HelpersTest.phpindex 0976480ce..0be4ebfc7 100644--- a/tests/Unit/HelpersTest.php+++ b/tests/Unit/HelpersTest.php@@ -93,3 +93,26 @@ test('uploadFromUrl handles exceptions gracefully', function () {expect($result)->toBeNull();});++test('uploadFromUrl returns null for a private-network url and never requests it', function () {+ Http::fake();++ $result = uploadFromUrl('http://127.0.0.1/evil.jpg');++ expect($result)->toBeNull();+ Http::assertNothingSent();+});++test('uploadFromUrl attempts the internal fetch when allow_private_network is enabled', function () {+ config(['trypost.security.allow_private_network' => true]);+ Storage::fake();++ Http::fake([+ 'http://127.0.0.1/internal.jpg' => Http::response('fake-image-content', 200, ['Content-Type' => 'image/jpeg']),+ ]);++ $result = uploadFromUrl('http://127.0.0.1/internal.jpg');++ expect($result)->not->toBeNull();+ Http::assertSent(fn ($request) => str_contains($request->url(), '127.0.0.1'));+});diff --git a/tests/Unit/Services/Brand/SafeHttpFetcherTest.php b/tests/Unit/Services/Brand/SafeHttpFetcherTest.phpindex d424d3c81..9f4983e54 100644--- a/tests/Unit/Services/Brand/SafeHttpFetcherTest.php+++ b/tests/Unit/Services/Brand/SafeHttpFetcherTest.php@@ -3,6 +3,7 @@declare(strict_types=1);use App\Services\Brand\SafeHttpFetcher;+use Illuminate\Http\Client\PendingRequest;use Illuminate\Support\Facades\Http;// Public IP literals let SafeHttpFetcher's SSRF guard pass without a real DNS@@ -68,3 +69,24 @@ test('throws when a redirect chain exceeds the redirect cap', function () {// The cap (3) is hit after following 3 redirects (4 requests); the next hop must never fire.Http::assertNotSent(fn ($request) => str_contains($request->url(), '93.184.216.38'));});++test('guardAgainstSsrf blocks a private ip by default', function () {+ expect(fn () => app(SafeHttpFetcher::class)->guardAgainstSsrf('http://127.0.0.1/x'))+ ->toThrow(RuntimeException::class);+});++test('guardAgainstSsrf allows a private ip when allow_private_network is enabled', function () {+ config(['trypost.security.allow_private_network' => true]);++ app(SafeHttpFetcher::class)->guardAgainstSsrf('http://127.0.0.1/x');+})->throwsNoExceptions();++test('guardedRequest throws for a private ip by default', function () {+ expect(fn () => app(SafeHttpFetcher::class)->guardedRequest('http://127.0.0.1/x'))+ ->toThrow(RuntimeException::class);+});++test('guardedRequest returns a PendingRequest for a public url', function () {+ expect(app(SafeHttpFetcher::class)->guardedRequest('https://93.184.216.34/x'))+ ->toBeInstanceOf(PendingRequest::class);+});diff --git a/tests/Unit/Services/Post/MediaAttacherTest.php b/tests/Unit/Services/Post/MediaAttacherTest.phpnew file mode 100644index 000000000..a105f8f58--- /dev/null+++ b/tests/Unit/Services/Post/MediaAttacherTest.php@@ -0,0 +1,79 @@+<?php++declare(strict_types=1);++use App\Models\Media;+use App\Models\Post;+use App\Models\User;+use App\Models\Workspace;+use App\Services\Post\MediaAttacher;+use Illuminate\Support\Facades\Http;+use Illuminate\Support\Facades\Storage;++// Public IP literals let SafeHttpFetcher's SSRF guard pass without a real DNS+// lookup; Http::fake intercepts the request before any network I/O.++beforeEach(function () {+ Storage::fake();++ $this->user = User::factory()->create();+ $this->workspace = Workspace::factory()->create(['user_id' => $this->user->id]);+ $this->post = Post::factory()->create([+ 'workspace_id' => $this->workspace->id,+ 'user_id' => $this->user->id,+ ]);+});++test('attaches a media item downloaded from a public url', function () {+ Http::fake([+ 'https://93.184.216.34/photo.png' => Http::response(+ file_get_contents(__DIR__.'/../../../fixtures/1x1.png'),+ 200,+ ['Content-Type' => 'image/png'],+ ),+ ]);++ $result = app(MediaAttacher::class)->attachFromUrls($this->post, [+ ['url' => 'https://93.184.216.34/photo.png'],+ ]);++ expect($result['failed'])->toBeEmpty()+ ->and($result['attached'])->toHaveCount(1);++ expect(Media::where('mediable_id', $this->workspace->id)->count())->toBe(1);+});++test('blocks a private-network url and never requests it', function () {+ Http::fake();++ $result = app(MediaAttacher::class)->attachFromUrls($this->post, [+ ['url' => 'http://127.0.0.1/evil.jpg'],+ ]);++ expect($result['attached'])->toBeEmpty()+ ->and($result['failed'])->toBe(['http://127.0.0.1/evil.jpg']);++ Http::assertNothingSent();+ expect(Media::where('mediable_id', $this->workspace->id)->count())->toBe(0);+});++test('attempts the internal fetch when allow_private_network is enabled', function () {+ config(['trypost.security.allow_private_network' => true]);++ Http::fake([+ 'http://127.0.0.1/internal.png' => Http::response(+ file_get_contents(__DIR__.'/../../../fixtures/1x1.png'),+ 200,+ ['Content-Type' => 'image/png'],+ ),+ ]);++ $result = app(MediaAttacher::class)->attachFromUrls($this->post, [+ ['url' => 'http://127.0.0.1/internal.png'],+ ]);++ expect($result['failed'])->toBeEmpty()+ ->and($result['attached'])->toHaveCount(1);++ Http::assertSent(fn ($request) => str_contains($request->url(), '127.0.0.1'));+});