mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-12-23 22:11:10 +02:00
* Refactored errors * Make monitoring and errorreport accept `errctx.Error` instead of `error` * Add server.Error; Remove category from errctx; Make HTTP handlers respond with *server.Error * Remove stackSkip from errctx.Wrap; Add errctx.WrapWithStackSkip
45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
package security
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/imgproxy/imgproxy/v3/errctx"
|
|
)
|
|
|
|
type (
|
|
SignatureError struct{ *errctx.TextError }
|
|
ImageResolutionError struct{ *errctx.TextError }
|
|
SourceURLError struct{ *errctx.TextError }
|
|
)
|
|
|
|
func newSignatureError(msg string) error {
|
|
return SignatureError{errctx.NewTextError(
|
|
msg,
|
|
1,
|
|
errctx.WithStatusCode(http.StatusForbidden),
|
|
errctx.WithPublicMessage("Forbidden"),
|
|
errctx.WithShouldReport(false),
|
|
)}
|
|
}
|
|
|
|
func newImageResolutionError(msg string) error {
|
|
return ImageResolutionError{errctx.NewTextError(
|
|
msg,
|
|
1,
|
|
errctx.WithStatusCode(http.StatusUnprocessableEntity),
|
|
errctx.WithPublicMessage("Invalid source image"),
|
|
errctx.WithShouldReport(false),
|
|
)}
|
|
}
|
|
|
|
func newSourceURLError(imageURL string) error {
|
|
return SourceURLError{errctx.NewTextError(
|
|
fmt.Sprintf("Source URL is not allowed: %s", imageURL),
|
|
1,
|
|
errctx.WithStatusCode(http.StatusNotFound),
|
|
errctx.WithPublicMessage("Invalid source URL"),
|
|
errctx.WithShouldReport(false),
|
|
)}
|
|
}
|