Skip to content

Disable libvips unfuzzed operations - #460

Merged
flavorjones merged 1 commit into
mainfrom
block-unfuzzed-operations
Jul 28, 2026
Merged

Disable libvips unfuzzed operations#460
flavorjones merged 1 commit into
mainfrom
block-unfuzzed-operations

Conversation

@flavorjones

@flavorjones flavorjones commented Jul 28, 2026

Copy link
Copy Markdown
Member

Harden image processing, and add test coverage for (un)supported file types.

BMP, ICO, and PSD attachments are no longer variable, and the picture views call variant(:large) unconditionally, which raises ActiveStorage::InvariableError. Introduce Picture#large_image to fall back to the original attachment.

Copilot AI review requested due to automatic review settings July 28, 2026 14:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens Active Storage image processing by restricting libvips operations/loaders and ensures the UI gracefully handles images that cannot be resized (by serving the original instead of raising on variant generation).

Changes:

  • Add a Picture#large_image helper that returns a resized variant for variable images, otherwise returns the original attachment.
  • Block untrusted libvips operations (and OpenSlide explicitly) and remove unsupported image types from active_storage.variable_content_types.
  • Add tests covering loader selection/denial policy and the “cannot be resized” rendering path.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/models/picture_test.rb Verifies large_image returns a variant for variable images and the original for non-variable types (e.g., BMP).
test/lib/vips_loader_policy_test.rb Pins which loaders are allowed/denied under the configured libvips blocking policy.
test/controllers/leafables_controller_test.rb Ensures a picture with a non-resizable image still renders successfully in the show view.
config/initializers/vips.rb Blocks untrusted libvips operations and removes BMP/ICO/PSD from variable content types.
app/views/pictures/_form.html.erb Uses large_image for the preview image to avoid invariable variant errors.
app/views/leaves/_leaf.html.erb Uses large_image for picture leaves to avoid failing when variants can’t be generated.
app/views/leaves/_edit.html.erb Uses large_image for the thumbnail rendering path when an image is attached.
app/views/leafables/show.html.erb Uses large_image for the main picture rendering path (lazy-loaded).
app/models/picture.rb Introduces large_image helper to centralize “variant-or-original” behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

and add test coverage for (un)supported file types.

BMP, ICO, and PSD attachments are no longer variable, and the picture views call
`variant(:large)` unconditionally, which raises `ActiveStorage::InvariableError`.
`Picture#large_image` will fall back to the original attachment.
@flavorjones
flavorjones force-pushed the block-unfuzzed-operations branch from bea7100 to 614a1d5 Compare July 28, 2026 14:58
@flavorjones
flavorjones merged commit 4d4bef3 into main Jul 28, 2026
7 checks passed
@flavorjones
flavorjones deleted the block-unfuzzed-operations branch July 28, 2026 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants