Skip to content

Commit f109b3f

Browse files
httplib: cover filename metacharacter escaping in ServeSetHeaders (#330)
* httplib: cover filename metacharacter escaping in ServeSetHeaders * tests: clarify filename escaping test comment
1 parent 1c44b16 commit f109b3f

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

modules/httplib/serve_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ func TestServeSetHeadersContentDisposition(t *testing.T) {
121121
ServeSetHeaders(w, &ServeHeaderOptions{Filename: "foo.zip", Disposition: "inline"})
122122
assert.Equal(t, `inline; filename="foo.zip"; filename*=UTF-8''foo.zip`, w.Header().Get("Content-Disposition"))
123123

124+
// quotes and backslashes must be escaped in the quoted-string form and
125+
// percent-encoded in the RFC 5987 parameter, so the filename cannot break
126+
// out of the quoted-string and inject disposition parameters
127+
w = httptest.NewRecorder()
128+
ServeSetHeaders(w, &ServeHeaderOptions{Filename: `a"b\c.zip`})
129+
assert.Equal(t, `attachment; filename="a\"b\\c.zip"; filename*=UTF-8''a%22b%5Cc.zip`, w.Header().Get("Content-Disposition"))
130+
124131
w = httptest.NewRecorder()
125132
ServeSetHeaders(w, &ServeHeaderOptions{})
126133
assert.Empty(t, w.Header().Get("Content-Disposition"))

0 commit comments

Comments
 (0)