2025-02-17 22:11:40 +03:00
|
|
|
package security
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"net/http"
|
|
|
|
|
|
2025-11-20 01:26:21 +06:00
|
|
|
"github.com/imgproxy/imgproxy/v3/errctx"
|
2025-02-17 22:11:40 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type (
|
2025-11-20 01:26:21 +06:00
|
|
|
SignatureError struct{ *errctx.TextError }
|
|
|
|
|
ImageResolutionError struct{ *errctx.TextError }
|
|
|
|
|
SourceURLError struct{ *errctx.TextError }
|
2025-02-17 22:11:40 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func newSignatureError(msg string) error {
|
2025-11-20 01:26:21 +06:00
|
|
|
return SignatureError{errctx.NewTextError(
|
|
|
|
|
msg,
|
2025-02-17 22:11:40 +03:00
|
|
|
1,
|
2025-11-20 01:26:21 +06:00
|
|
|
errctx.WithStatusCode(http.StatusForbidden),
|
|
|
|
|
errctx.WithPublicMessage("Forbidden"),
|
|
|
|
|
errctx.WithShouldReport(false),
|
|
|
|
|
)}
|
2025-02-17 22:11:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func newImageResolutionError(msg string) error {
|
2025-11-20 01:26:21 +06:00
|
|
|
return ImageResolutionError{errctx.NewTextError(
|
|
|
|
|
msg,
|
2025-02-17 22:11:40 +03:00
|
|
|
1,
|
2025-11-20 01:26:21 +06:00
|
|
|
errctx.WithStatusCode(http.StatusUnprocessableEntity),
|
|
|
|
|
errctx.WithPublicMessage("Invalid source image"),
|
|
|
|
|
errctx.WithShouldReport(false),
|
|
|
|
|
)}
|
2025-02-17 22:11:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func newSourceURLError(imageURL string) error {
|
2025-11-20 01:26:21 +06:00
|
|
|
return SourceURLError{errctx.NewTextError(
|
|
|
|
|
fmt.Sprintf("Source URL is not allowed: %s", imageURL),
|
2025-02-17 22:11:40 +03:00
|
|
|
1,
|
2025-11-20 01:26:21 +06:00
|
|
|
errctx.WithStatusCode(http.StatusNotFound),
|
|
|
|
|
errctx.WithPublicMessage("Invalid source URL"),
|
|
|
|
|
errctx.WithShouldReport(false),
|
|
|
|
|
)}
|
2025-02-17 22:11:40 +03:00
|
|
|
}
|