Skip to main content

Shrine 3.12.0

Security​

  • The download_endpoint plugin now requires the :secret_key option and always signs download URLs (GHSA-w8v6-8q68-85pf). Previously, download URLs were unsigned by default, so attackers could build URLs for arbitrary files in any registered storage, and choose the response Content-Type and filename through the serialized metadata.

    Shrine.plugin :download_endpoint,
      prefix: "attachments",
      secret_key: "<YOUR SECRET KEY>"

    The endpoint returns 403 Forbidden for URLs with a missing or invalid signature. File responses now also include the X-Content-Type-Options: nosniff header.

  • The remote_url plugin now refuses URLs and redirects that resolve to private IP addresses (localhost, private networks, link-local addresses such as cloud metadata endpoints etc), which prevents server-side request forgery. This is done by passing allow_private: false to the downloader. If you need to download from internal addresses, and the URLs don't come from untrusted sources, you can allow it:

    plugin :remote_url, max_size: 20*1024*1024, allow_private: true
    # or
    attacher.assign_remote_url(url, downloader: { allow_private: true })
  • Submitting a cached file can no longer be used to move or delete files uploaded by others (GHSA-v6vc-5f2v-5rj8):

    • FileSystem now rejects ids that resolve to the storage directory itself (e.g. "" or "."), which previously allowed moving the whole cache directory on promotion with move: true.

    • FileSystem#upload with move: true and FileSystem#delete now refuse to move or delete directories.

    • FileSystem now stops cleaning empty directories at the storage directory, instead of continuing into its parent directories.

    • The remove_invalid plugin now only deletes invalid files that were uploaded by the attacher. Cached files assigned from data (e.g. form params), which could belong to other users, are just deassigned.

  • The :ruby_vips analyzer of the store_dimensions plugin now calls Vips.block_untrusted(true) (libvips 8.13+), so that unvalidated uploads cannot reach libvips loaders that haven't been fuzzed (e.g. magickload, svgload) (GHSA-gx57-4cm3-73qj). This can be overridden with the VIPS_BLOCK_UNTRUSTED environment variable.

New features​

  • The remote_url plugin now accepts :net_http, :http or :httpx for the :downloader option, which selects the corresponding Down backend.

    plugin :remote_url, max_size: 20*1024*1024, downloader: :http  # uses Down::Http
    plugin :remote_url, max_size: 20*1024*1024, downloader: :httpx # uses Down::Httpx
  • The download_endpoint plugin now supports :secret_key without :expires_in, which generates non-expiring signed URLs.

Backwards compatibility​

  • The download_endpoint plugin now raises Shrine::Error when the :secret_key option is not given. Previously generated unsigned download URLs will return 403 Forbidden.

  • The remote_url plugin now defaults to the :net_http downloader, so Down.backend is no longer used. If you've changed Down.backend, pass the corresponding backend to the :downloader option instead.

  • Custom remote_url downloaders now receive the :allow_private keyword argument, so they need to accept it. Make sure to forward it to Down, or otherwise refuse URLs resolving to private IP addresses.

  • Shrine now requires Down 6.1.2 or later.

  • FileSystem#delete and FileSystem#upload with move: true now raise Shrine::Error when given an id that resolves to a directory.

  • The remove_invalid plugin no longer deletes cached files assigned from data when validation fails.