fix: guard ContentTypeMatchesPlatform against non-uuid social_account_id (#260)

An MCP client sending a non-uuid social_account_id (e.g. a placeholder
string) reached SocialAccount::find() directly, which threw a Postgres
QueryException (22P02) instead of failing validation gracefully.
This commit is contained in:
Paulo Castellano 2026-08-09 10:46:59 -04:00 committed by GitHub
parent f019053860
commit 9293d0cd8d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View file

@ -40,7 +40,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
$parentKey = Str::beforeLast($attribute, '.'); $parentKey = Str::beforeLast($attribute, '.');
$accountId = data_get($this->data, $parentKey.'.social_account_id'); $accountId = data_get($this->data, $parentKey.'.social_account_id');
if (! $accountId) { if (! $accountId || ! Str::isUuid((string) $accountId)) {
return; return;
} }

View file

@ -67,6 +67,14 @@ function runMatchesPlatformRule(string $contentType, ?string $accountId, array $
expect(runMatchesPlatformRule(ContentType::XPost->value, null))->toBe([]); expect(runMatchesPlatformRule(ContentType::XPost->value, null))->toBe([]);
}); });
test('skips validation without querying the database when social_account_id is not a uuid', function () {
// Regression: a non-uuid social_account_id (e.g. an MCP client sending a
// placeholder string) must not reach SocialAccount::find(), which throws
// a QueryException on Postgres for invalid uuid input instead of
// returning no rows.
expect(runMatchesPlatformRule(ContentType::XPost->value, 'threads-account'))->toBe([]);
});
test('skips validation when content_type is not a known enum value', function () { test('skips validation when content_type is not a known enum value', function () {
$workspace = Workspace::factory()->create(); $workspace = Workspace::factory()->create();
$linkedin = SocialAccount::factory()->create([ $linkedin = SocialAccount::factory()->create([