imageproxy icon indicating copy to clipboard operation
imageproxy copied to clipboard

Prevent pixel flood attacks

Open blakestoddard opened this issue 5 years ago • 4 comments

Presenting large images to ImageProxy that need transformations will cause ImageProxy to crash in some environments, resulting in a DoS attack -- https://gist.github.com/blakestoddard/a2cb5b98eaf335f0f474fcd09c1a751b using https://a.uguu.se/cGlgezGk.jpg (temp link that will expire, but it's a 64250x64250 image).

An easy fix is to halt transform operations for images over a certain pixel threshold. The 10000x10000 that I chose here is arbitrary, I only picked it since it matches the policy that we use internally for other things like ImageMagick.

By returning an error from Transform(), we prevent ImageProxy from crashing while still serving the original requested, untransformed image.

blakestoddard avatar Dec 08 '20 19:12 blakestoddard

Codecov Report

Merging #254 (8572c5b) into main (c08b3c5) will decrease coverage by 0.24%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #254      +/-   ##
==========================================
- Coverage   87.27%   87.03%   -0.25%     
==========================================
  Files           6        6              
  Lines         503      509       +6     
==========================================
+ Hits          439      443       +4     
- Misses         36       37       +1     
- Partials       28       29       +1     
Impacted Files Coverage Δ
transform.go 88.48% <100.00%> (-0.83%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update c08b3c5...3b16e68. Read the comment docs.

codecov[bot] avatar Dec 08 '20 19:12 codecov[bot]

I'm adding a test, give me a few.

blakestoddard avatar Dec 08 '20 19:12 blakestoddard

Bump! Would love to see this merged, or let me know how we can get it there.

mdkent avatar Apr 07 '21 22:04 mdkent

Similar to my comment on #286, if you're trying to prevent abuse, why isn't the solution request signatures? Sure we could prevent requests larger than 10000x10000, but that still doesn't prevent an attack requesting 9999x9999 images with random other transformations that will bypass the cache.

willnorris avatar Apr 08 '21 16:04 willnorris