Skip to content

PostPolicy.marshalJSON() ignores Location of expiration time #2134

@qwwqe

Description

@qwwqe

When marshaling a PostPolicy to JSON, expiration is directly formatted into a GMT date string:

minio-go/post-policy.go

Lines 419 to 420 in 564e213

func (p PostPolicy) marshalJSON() []byte {
expirationStr := `"expiration":"` + p.expiration.Format(expirationDateFormat) + `"`

Given that all time.Time values have an associated Location, and that values whose Locations differ but otherwise refer to the same instant in time are treated by the time package as equal, I believe the intuitive behaviour here would be to respect the Location associated with the expiration field, and convert to UTC before formatting as a string:

expirationStr := `"expiration":"` + p.expiration.UTC().Format(expirationDateFormat) + `"`

Furthermore, as far as I understand, the use of the Z suffix in the output string indicates explicitly that the timestamp is in UTC. Since the current behaviour ignores Location and directly formats to expirationDateFormat, this means that whenever p.expiration.Location() is not set to UTC, the marshaled output will not accurately reflect the time value initially passed to PostPolicy.SetExpires(). In other words, PostPolicy.marshalJSON() currently outputs incorrect expiration time stamps for all time values that are not set to UTC. A simple reproduction of this behaviour in the Go Playground can be found here.

I'm not sure if this design is intentional, or whether the maintainers are open to changing this behaviour, but if so I'd be happy to submit a PR.

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