Skip to content

fix: validate MCP attachment formats and align media allowlist#1541

Open
bsantosh909 wants to merge 1 commit into
mainfrom
fix/mcp-attachment-validation
Open

fix: validate MCP attachment formats and align media allowlist#1541
bsantosh909 wants to merge 1 commit into
mainfrom
fix/mcp-attachment-validation

Conversation

@bsantosh909
Copy link
Copy Markdown
Collaborator

What kind of change does this PR introduce?

Bug fix + small refactor (no behavior change on the web flow).

Why was this change needed?

The MCP integrationSchedulePostTool accepted any attachment URL —
including .mov, .exe, .pdf, etc. — and forwarded them to post
creation with no format check, while the public API enforced an
mp4-only / image allowlist. This closes that gap and consolidates the
allowed-media list into a single source of truth so the file-upload
pipe, the URL DTO validator, the public-API URL controller and the
MCP attachment guard can no longer drift apart.

Other information:

  • ALLOWED_POST_MEDIA is now defined once in
    libraries/helpers/src/utils/has.extension.ts and drives both
    VALID_POST_MEDIA_EXTENSIONS (used by ValidUrlExtension and the
    MCP attachment check via isValidPostMediaUrl) and
    VALID_POST_MEDIA_MIME_TYPES (used by CustomFileValidationPipe
    and the /public/v1/upload-from-url controller).
  • Net result of the alignment: image/avif, image/bmp,
    image/tiff are no longer accepted by /public/v1/upload. They
    were never accepted by /upload-from-url (rejected at the DTO
    level by ValidUrlExtension), so file uploads in those formats
    could be stored but never used downstream — this removes the
    half-working surface.
  • Web flow is unaffected: the frontend uploader already filters to
    png/jpg/jpeg/gif/webp client-side and uses Transloadit to
    transcode non-mp4 videos to mp4 before reaching the API.
  • Tested locally against both /public/v1/upload,
    /public/v1/upload-from-url, and the MCP
    integrationSchedulePostTool with .mp4 / .mov / .exe /
    .pdf / .png payloads.

Checklist:

  • I have read the CONTRIBUTING guide.
  • I confirm I have not used AI to submit this PR or generate code for it.
  • I checked that there were no similar issues or PRs already open for this.
  • This PR fixes just ONE issue

Reject non-mp4 / non-image attachment URLs in the MCP
integrationSchedulePostTool (previously accepted any URL). Introduce
a single ALLOWED_POST_MEDIA source of truth in helpers/has.extension
and derive VALID_POST_MEDIA_EXTENSIONS + VALID_POST_MEDIA_MIME_TYPES
from it, replacing duplicated constants in the file upload pipe, the
public-api URL upload controller, and the ValidUrlExtension DTO
validator. Error messages now consistently list the allowed
extensions across the public API and MCP.
@bsantosh909 bsantosh909 requested a review from nevo-david May 19, 2026 08:15
@postiz-contribution postiz-contribution Bot added the contribution:approved Approved contributor label May 19, 2026
Comment thread libraries/helpers/src/utils/has.extension.ts
!!text?.split?.('?')?.[0].endsWith('.webp') ||
!!text?.split?.('?')?.[0].endsWith('.mp4')
);
const path = text?.split?.('?')?.[0]?.toLowerCase?.();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add here also split for ['#'] on 0

),
attachments: z
.array(z.string())
.describe('The image of the post (URLS)'),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it's possible to add the validation here? I think zod allows for custom schema check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution:approved Approved contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants