Skip to content

[object-storage] Creating Temporary URL with slash (/) returns invalid URL #1993

@Lirt

Description

@Lirt

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions