Skip to content

Commit

Permalink
Update AP Helpers, fix media validation bug that would reject media w…
Browse files Browse the repository at this point in the history
…ith alttext/name longer than 255 chars and store remote alt text if set
  • Loading branch information
dansup committed Jan 31, 2023
1 parent 016c6e4 commit a7f5834
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/Util/ActivityPub/Helpers.php
Expand Up @@ -101,13 +101,13 @@ public static function verifyAttachments($data)
'string',
Rule::in($mediaTypes)
],
'*.url' => 'required|url|max:255',
'*.url' => 'required|url',
'*.mediaType' => [
'required',
'string',
Rule::in($mimeTypes)
],
'*.name' => 'sometimes|nullable|string|max:255'
'*.name' => 'sometimes|nullable|string'
])->passes();

return $valid;
Expand Down Expand Up @@ -665,12 +665,13 @@ public static function importNoteAttachment($data, Status $status)
foreach($attachments as $media) {
$type = $media['mediaType'];
$url = $media['url'];
$blurhash = isset($media['blurhash']) ? $media['blurhash'] : null;
$license = isset($media['license']) ? License::nameToId($media['license']) : null;
$valid = self::validateUrl($url);
if(in_array($type, $allowed) == false || $valid == false) {
continue;
}
$blurhash = isset($media['blurhash']) ? $media['blurhash'] : null;
$license = isset($media['license']) ? License::nameToId($media['license']) : null;
$caption = $media['name'] ? Purify::clean($media['name']) : null;

$media = new Media();
$media->blurhash = $blurhash;
Expand All @@ -680,6 +681,7 @@ public static function importNoteAttachment($data, Status $status)
$media->user_id = null;
$media->media_path = $url;
$media->remote_url = $url;
$media->caption = $caption;
if($license) {
$media->license = $license;
}
Expand Down

0 comments on commit a7f5834

Please sign in to comment.