options.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package security
  2. import (
  3. "github.com/imgproxy/imgproxy/v3/config"
  4. )
  5. // Security options (part of processing options)
  6. type Options struct {
  7. MaxSrcResolution int
  8. MaxSrcFileSize int
  9. MaxAnimationFrames int
  10. MaxAnimationFrameResolution int
  11. MaxResultDimension int
  12. }
  13. // NOTE: This function is a part of processing option, we'll move it in the next PR
  14. func IsSecurityOptionsAllowed() error {
  15. if config.AllowSecurityOptions {
  16. return nil
  17. }
  18. return newSecurityOptionsError()
  19. }
  20. // CheckDimensions checks if the given dimensions are within the allowed limits
  21. func (o *Options) CheckDimensions(width, height, frames int) error {
  22. frames = max(frames, 1)
  23. if frames > 1 && o.MaxAnimationFrameResolution > 0 {
  24. if width*height > o.MaxAnimationFrameResolution {
  25. return newImageResolutionError("Source image frame resolution is too big")
  26. }
  27. } else {
  28. if width*height*frames > o.MaxSrcResolution {
  29. return newImageResolutionError("Source image resolution is too big")
  30. }
  31. }
  32. return nil
  33. }