Skip to content

net/url: Go incorrectly unescapes URL and breaks HTTP Redirects #3433

@gopherbot

Description

@gopherbot

by stephane.travostino:

(Using Go 1)

Consider the following URL:

http://www.hulkshare.com/dl/y9g6b0xkgg37/01%20Rack%20City%20(Remix).mp3

When downloading the following file with "curl", this is the interaction:

1) GET http://www.hulkshare.com/dl/y9g6b0xkgg37/01%20Rack%20City%20(Remix).mp3
    <- 302 Found, http://trckr.hulkshare.com/hulkdl/y9g6b0xkgg37/01_Rack_City_%28Remix%29.mp3?z=1

2) GET http://trckr.hulkshare.com/hulkdl/y9g6b0xkgg37/01_Rack_City_%28Remix%29.mp3?z=1
    <- 302 Found, http://cdn01.hulkshare.com/dev1/0/003/400/0003400309.fid/01_Rack_City_%28Remix%29.mp3?key=800ab0ba09002ead53b1f2b4fed24b32&;dl=1

3) GET
http://cdn01.hulkshare.com/dev1/0/003/400/0003400309.fid/01_Rack_City_%28Remix%29.mp3?key=800ab0ba09002ead53b1f2b4fed24b32&;dl=1
    <- 200 OK

Using Go, the following happens:

1) GET http://www.hulkshare.com/dl/y9g6b0xkgg37/01%20Rack%20City%20(Remix).mp3
    <- 302 Found, http://trckr.hulkshare.com/hulkdl/y9g6b0xkgg37/01_Rack_City_%28Remix%29.mp3?z=1

2) GET http://trckr.hulkshare.com/hulkdl/y9g6b0xkgg37/01_Rack_City_(Remix).mp3?z=1
    <- 302 Found, http://cdn04.hulkshare.com/dev4/0/003/400/0003400309.fid/01_Rack_City_%28Remix%29.mp3?key=51eb16a7b50640caabc8224df081e86c&;dl=1

3) GET
http://cdn04.hulkshare.com/dev4/0/003/400/0003400309.fid/01_Rack_City_(Remix).mp3?key=51eb16a7b50640caabc8224df081e86c&;dl=1
    <- 412 Precondition Failed

You can see that the first 302 returned an URL which has been unescaped by Go before
executing GET #2, same for #3 and for some reason the web server returns an error.

The bug seems to be in net/url Parse function which unescapes the string by default,
breaking this mechanism.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions