1
0

errors.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package security
  2. import (
  3. "fmt"
  4. "net/http"
  5. "github.com/imgproxy/imgproxy/v3/ierrors"
  6. )
  7. type (
  8. SignatureError string
  9. ImageResolutionError string
  10. SecurityOptionsError struct{}
  11. SourceURLError string
  12. )
  13. func newSignatureError(msg string) error {
  14. return ierrors.Wrap(
  15. SignatureError(msg),
  16. 1,
  17. ierrors.WithStatusCode(http.StatusForbidden),
  18. ierrors.WithPublicMessage("Forbidden"),
  19. ierrors.WithShouldReport(false),
  20. )
  21. }
  22. func (e SignatureError) Error() string { return string(e) }
  23. func newImageResolutionError(msg string) error {
  24. return ierrors.Wrap(
  25. ImageResolutionError(msg),
  26. 1,
  27. ierrors.WithStatusCode(http.StatusUnprocessableEntity),
  28. ierrors.WithPublicMessage("Invalid source image"),
  29. ierrors.WithShouldReport(false),
  30. )
  31. }
  32. func (e ImageResolutionError) Error() string { return string(e) }
  33. func newSecurityOptionsError() error {
  34. return ierrors.Wrap(
  35. SecurityOptionsError{},
  36. 1,
  37. ierrors.WithStatusCode(http.StatusForbidden),
  38. ierrors.WithPublicMessage("Invalid URL"),
  39. ierrors.WithShouldReport(false),
  40. )
  41. }
  42. func (e SecurityOptionsError) Error() string { return "Security processing options are not allowed" }
  43. func newSourceURLError(imageURL string) error {
  44. return ierrors.Wrap(
  45. SourceURLError(fmt.Sprintf("Source URL is not allowed: %s", imageURL)),
  46. 1,
  47. ierrors.WithStatusCode(http.StatusNotFound),
  48. ierrors.WithPublicMessage("Invalid source URL"),
  49. ierrors.WithShouldReport(false),
  50. )
  51. }
  52. func (e SourceURLError) Error() string { return string(e) }