basecamp / thruster

MIT License
672 stars 16 forks source link

Add a minimal image proxy #1

Open kevinmcconnell opened 4 months ago

kevinmcconnell commented 4 months ago

To provide some safety when linking to user-supplied external images, we can provide a simple image proxy handler. Images accessed through this proxy will only be served if they meet the following criteria:

To serve an image through this proxy, its URL should be passed to the handler's path as a src query param. The path is supplied to the application in the IMAGE_PROXY_PATH environment variable.

We'll also provide a helper method to make forming the proxy links easier:

Thruster.image_proxy_path('https://example.com/image.jpg')

This will result in a URL something like the following, which will route the image request through Thruster's proxy handler:

/_t/image?src=https%3A%2F%2Fexample.com%2Fimage.jpg
palkan commented 3 months ago

We'll also provide a helper method to make forming the proxy links easier:

I would suggest integrating with Active Storage instead (so no application changes would be required, just a configuration one); see, for example, https://github.com/imgproxy/imgproxy-rails