Skip to content

Validate upload content before persisting to /uploads#2

Open
ORDL-AMF wants to merge 1 commit into
mainfrom
codex/fix-unrestricted-file-upload-vulnerability
Open

Validate upload content before persisting to /uploads#2
ORDL-AMF wants to merge 1 commit into
mainfrom
codex/fix-unrestricted-file-upload-vulnerability

Conversation

@ORDL-AMF
Copy link
Copy Markdown
Member

Motivation

  • Close a stored-XSS/content-hosting hole where uploaded bytes were saved with attacker-controlled extensions and exposed at /uploads without content validation.
  • Ensure only bona fide raster images are persisted so the static /uploads mount cannot serve HTML/SVG/JS from user uploads.

Description

  • Replaced extension-from-filename/content-type logic with a content-based validator by adding _validated_image_suffix(content: bytes) which attempts to parse the bytes with Pillow and maps trusted raster formats to safe extensions (.jpg, .png, .webp, .gif, .bmp, .tiff).
  • Updated _persist_uploaded_asset to call _validated_image_suffix and only write files when the content is a supported image; otherwise it returns None and logs a warning, preserving existing behavior of returning asset_url when persisted.
  • Added imports required for validation (BytesIO, PIL.Image, UnidentifiedImageError) and removed the prior filename-suffix reliance.

Testing

  • Ran python -m py_compile aether-system/backend/api/routes.py and it succeeded to validate syntax.
  • Attempted a small runtime validation of _validated_image_suffix but the environment lacked fastapi which caused import failure (ModuleNotFoundError: No module named 'fastapi'), so dynamic execution tests were not completed.
  • Committed the change after static checks and ensured the modified module compiles cleanly.

Codex Task

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant