Skip to content

Images::Image.open takes a path where MiniMagick takes a path OR a URL, and implementing it is an outbound-fetch surface #957

Open

Description

@tannevaled

Image.open takes a path; MiniMagick's takes a path or a URL

Found while settling #950's Images half by reading the reference. go-ruby-images' README calls itself "a MiniMagick / ruby-vips replacement", and MiniMagick's lib/mini_magick/image.rb is:

def self.open(path_or_url, ext = nil, **options)
  if path_or_url.to_s =~ %r{\A(https?|ftp)://}
    uri = URI(path_or_url)
    ext ||= File.extname(uri.path).sub(/:.*/, '')
    uri.open(options) { |file| read(file, ext) }
  else
    pathname = Pathname(path_or_url)
    ext ||= File.extname(pathname.to_s)
    pathname.open(binmode: true, **options) { |file| read(file, ext) }
  end
end

rbgo's (internal/vm/images.go) decodes a file and nothing else:

imagesArity(args, 1)
return imagesWrap(images.Open(strArg(args[0])))

so Images::Image.open("https://example.org/photo.png") raises Images::Error on a file that is not there, where MiniMagick fetches it.

⛔ This is filed, not fixed, because implementing it is a security decision

Making it work means the interpreter performs an outbound HTTP/FTP request driven by an argument that looks like a path. Any program that passes a user-supplied string to Image.open — which reads as a filesystem operation — would acquire a request-forgery surface it did not ask for. MiniMagick has that property; whether rbgo should inherit it is a judgement for the maintainer, not a parity checkbox.

Three options, no recommendation:

  1. Implement it, matching MiniMagick, and document the fetch. The scheme set would be https?|ftp to match; ftp in particular is worth questioning on its own.
  2. Refuse it loudly — detect the \A(https?|ftp):// shape and raise with a message saying rbgo's Image.open is filesystem-only, so the divergence is named at the call site instead of surfacing as a confusing "no such file".
  3. Leave it and record the divergence in the README's table.

Option 2 is the only one that costs nothing and removes the confusing failure, but it is still a behaviour change and still the maintainer's call.

What is NOT part of this

  • The block form: settled, not a gap. MiniMagick's open takes no block, so rbgo discarding one is correct — see Images::Image.open discards its block and has no known reference — the Augeas half was never blocked, see #952 #950 and its PR.
  • The ext argument: MiniMagick takes ext = nil and rbgo ignores a second argument (imagesArity is a minimum, so it is silently accepted rather than refused). Cosmetic: go-ruby-images' Open calls image.Decode, which sniffs the format from the content through the registered PNG/JPEG/GIF/BMP/TIFF/WebP decoders, so the hint changes nothing on either side. Noted here so the next reader does not re-derive it; not worth its own issue.
  • **options: forwarded to Pathname#open/URI#open in MiniMagick. Out of scope until someone wants a specific one.

Refs #950 — settled by its own PR; this is the separate divergence that reading the same reference turned up.

🤖 Generated with Claude Code

Prior art: priorart "Images::Image.open does not accept an http or ftp URL where MiniMagick fetches it" at 2026-11-17 13:37 CET reported prior art; checked: The 680 hits are keyword matches on images/open/accept/http across the tracker: #950 is the block-form question this PR settles, #931/#932/#935/#916 are the socket doors and the network hangs, #951/#952 the door ratchet and Augeas, #867/#497 Renovate. None is about Image.open's ARGUMENT accepting a URL. Nothing covers this.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions