mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-10 12:12:40 +02:00
Check bucket name and object key in S3, GCS, ABS, and Swift integrations
This commit is contained in:
@@ -4,6 +4,9 @@
|
|||||||
### Add
|
### Add
|
||||||
- Add [IMGPROXY_ALWAYS_RASTERIZE_SVG](https://docs.imgproxy.net/latest/configuration/options#IMGPROXY_ALWAYS_RASTERIZE_SVG) config.
|
- Add [IMGPROXY_ALWAYS_RASTERIZE_SVG](https://docs.imgproxy.net/latest/configuration/options#IMGPROXY_ALWAYS_RASTERIZE_SVG) config.
|
||||||
|
|
||||||
|
### Change
|
||||||
|
- Respond with 404 when the bucket/container name or object key is empty in an S3, Google Cloud Storage, Azure Blob Storage, or OpenStack Object Storage (Swift) URL.
|
||||||
|
|
||||||
## [3.23.0] - 2024-03-11
|
## [3.23.0] - 2024-03-11
|
||||||
### Add
|
### Add
|
||||||
- Add request ID, processing/info options, and source image URL to error reports.
|
- Add request ID, processing/info options, and source image URL to error reports.
|
||||||
|
@@ -84,7 +84,22 @@ func New() (http.RoundTripper, error) {
|
|||||||
|
|
||||||
func (t transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
func (t transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||||
container := req.URL.Host
|
container := req.URL.Host
|
||||||
key := req.URL.Path
|
key := strings.TrimPrefix(req.URL.Path, "/")
|
||||||
|
|
||||||
|
if len(container) == 0 || len(key) == 0 {
|
||||||
|
body := strings.NewReader("Invalid ABS URL: container name or object key is empty")
|
||||||
|
return &http.Response{
|
||||||
|
StatusCode: http.StatusNotFound,
|
||||||
|
Proto: "HTTP/1.0",
|
||||||
|
ProtoMajor: 1,
|
||||||
|
ProtoMinor: 0,
|
||||||
|
Header: http.Header{},
|
||||||
|
ContentLength: int64(body.Len()),
|
||||||
|
Body: io.NopCloser(body),
|
||||||
|
Close: false,
|
||||||
|
Request: req,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
statusCode := http.StatusOK
|
statusCode := http.StatusOK
|
||||||
|
|
||||||
@@ -112,7 +127,7 @@ func (t transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
|||||||
statusCode = http.StatusPartialContent
|
statusCode = http.StatusPartialContent
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := t.client.DownloadStream(req.Context(), container, strings.TrimPrefix(key, "/"), opts)
|
result, err := t.client.DownloadStream(req.Context(), container, key, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if azError, ok := err.(*azcore.ResponseError); !ok || azError.StatusCode < 100 || azError.StatusCode == 301 {
|
if azError, ok := err.(*azcore.ResponseError); !ok || azError.StatusCode < 100 || azError.StatusCode == 301 {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@@ -77,8 +77,26 @@ func New() (http.RoundTripper, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
func (t transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||||
bkt := t.client.Bucket(req.URL.Host)
|
bucket := req.URL.Host
|
||||||
obj := bkt.Object(strings.TrimPrefix(req.URL.Path, "/"))
|
key := strings.TrimPrefix(req.URL.Path, "/")
|
||||||
|
|
||||||
|
if len(bucket) == 0 || len(key) == 0 {
|
||||||
|
body := strings.NewReader("Invalid GCS URL: bucket name or object key is empty")
|
||||||
|
return &http.Response{
|
||||||
|
StatusCode: http.StatusNotFound,
|
||||||
|
Proto: "HTTP/1.0",
|
||||||
|
ProtoMajor: 1,
|
||||||
|
ProtoMinor: 0,
|
||||||
|
Header: http.Header{},
|
||||||
|
ContentLength: int64(body.Len()),
|
||||||
|
Body: io.NopCloser(body),
|
||||||
|
Close: false,
|
||||||
|
Request: req,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
bkt := t.client.Bucket(bucket)
|
||||||
|
obj := bkt.Object(key)
|
||||||
|
|
||||||
if g, err := strconv.ParseInt(req.URL.RawQuery, 10, 64); err == nil && g > 0 {
|
if g, err := strconv.ParseInt(req.URL.RawQuery, 10, 64); err == nil && g > 0 {
|
||||||
obj = obj.Generation(g)
|
obj = obj.Generation(g)
|
||||||
|
@@ -94,9 +94,27 @@ func New() (http.RoundTripper, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||||
|
bucket := req.URL.Host
|
||||||
|
key := strings.TrimPrefix(req.URL.Path, "/")
|
||||||
|
|
||||||
|
if len(bucket) == 0 || len(key) == 0 {
|
||||||
|
body := strings.NewReader("Invalid S3 URL: bucket name or object key is empty")
|
||||||
|
return &http.Response{
|
||||||
|
StatusCode: http.StatusNotFound,
|
||||||
|
Proto: "HTTP/1.0",
|
||||||
|
ProtoMajor: 1,
|
||||||
|
ProtoMinor: 0,
|
||||||
|
Header: http.Header{},
|
||||||
|
ContentLength: int64(body.Len()),
|
||||||
|
Body: io.NopCloser(body),
|
||||||
|
Close: false,
|
||||||
|
Request: req,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
input := &s3.GetObjectInput{
|
input := &s3.GetObjectInput{
|
||||||
Bucket: aws.String(req.URL.Host),
|
Bucket: aws.String(bucket),
|
||||||
Key: aws.String(strings.TrimPrefix(req.URL.Path, "/")),
|
Key: aws.String(key),
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(req.URL.RawQuery) > 0 {
|
if len(req.URL.RawQuery) > 0 {
|
||||||
|
@@ -54,6 +54,21 @@ func (t transport) RoundTrip(req *http.Request) (resp *http.Response, err error)
|
|||||||
container := req.URL.Host
|
container := req.URL.Host
|
||||||
objectName := strings.TrimPrefix(req.URL.Path, "/")
|
objectName := strings.TrimPrefix(req.URL.Path, "/")
|
||||||
|
|
||||||
|
if len(container) == 0 || len(objectName) == 0 {
|
||||||
|
body := strings.NewReader("Invalid Swift URL: container name or object name is empty")
|
||||||
|
return &http.Response{
|
||||||
|
StatusCode: http.StatusNotFound,
|
||||||
|
Proto: "HTTP/1.0",
|
||||||
|
ProtoMajor: 1,
|
||||||
|
ProtoMinor: 0,
|
||||||
|
Header: http.Header{},
|
||||||
|
ContentLength: int64(body.Len()),
|
||||||
|
Body: io.NopCloser(body),
|
||||||
|
Close: false,
|
||||||
|
Request: req,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
reqHeaders := make(swift.Headers)
|
reqHeaders := make(swift.Headers)
|
||||||
if r := req.Header.Get("Range"); len(r) > 0 {
|
if r := req.Header.Get("Range"); len(r) > 0 {
|
||||||
reqHeaders["Range"] = r
|
reqHeaders["Range"] = r
|
||||||
|
Reference in New Issue
Block a user