-
Notifications
You must be signed in to change notification settings - Fork 583
[object-storage] Creating Temporary URL with slash (/) returns invalid URL #1993
Copy link
Copy link
Closed
Description
When creating swift temporary URL using function CreateTempURL and objectName contains slash (/), generated link is invalid.
To reproduce issue create bucket with object containing slash and run simple go snippet below:
# Create bucket with object containing slash
swift post my-container
echo "this is my grandma" > grandma.png
swift upload my-container grandma.png --object-name "pictures/grandma.png"package main
import (
"fmt"
"net/http"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack"
"github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects"
)
func main() () {
authOpts, _ := openstack.AuthOptionsFromEnv()
pc, _ := openstack.AuthenticatedClient(authOpts)
client, _ := openstack.NewObjectStorageV1(pc, gophercloud.EndpointOpts{
Region: "default",
})
bucket := "my-container"
key := "pictures/grandma.png"
objUrl, _ := objects.CreateTempURL(client, bucket, key, objects.CreateTempURLOpts{
Method: http.MethodGet,
TTL: 3600,
})
fmt.Printf("%v\n", objUrl)
}Then curl the URL and you get 401 Unauthorized: Temp URL invalid.
The issue lies in encoding/escaping the URL before generating SHA1 hash (https://github.com/gophercloud/gophercloud/blob/master/openstack/objectstorage/v1/objects/requests.go#L482).
Swift middleware documentation says:
Do not URL-encode the path when you generate the HMAC-SHA1 signature. However, when you make the actual HTTP request, you should properly URL-encode the URL. [1]
[1] https://docs.openstack.org/swift/latest/api/temporary_url_middleware.html
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels