fix(security): harden outbound requests and file previews
This commit is contained in:
@@ -170,6 +170,28 @@ func TestPresignedFile_GET_ReturnsContent(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPresignedFile_ForcesActiveContentDownload(t *testing.T) {
|
||||
engine, baseDir, signURL := setupPresignedTestServer(t)
|
||||
storagePath := writeTestFile(t, baseDir, "1/payload.svg", `<svg onload="alert(1)"></svg>`)
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, signURL(storagePath, 1, time.Hour), nil)
|
||||
w := httptest.NewRecorder()
|
||||
engine.ServeHTTP(w, req)
|
||||
|
||||
if got, want := w.Code, http.StatusOK; got != want {
|
||||
t.Fatalf("status = %d, want %d", got, want)
|
||||
}
|
||||
if got := w.Header().Get("Content-Type"); got != "application/octet-stream" {
|
||||
t.Fatalf("Content-Type = %q, want application/octet-stream", got)
|
||||
}
|
||||
if got := w.Header().Get("Content-Disposition"); got != "attachment" {
|
||||
t.Fatalf("Content-Disposition = %q, want attachment", got)
|
||||
}
|
||||
if got := w.Header().Get("X-Content-Type-Options"); got != "nosniff" {
|
||||
t.Fatalf("X-Content-Type-Options = %q, want nosniff", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPresignedFile_InvalidSig_403(t *testing.T) {
|
||||
engine, _, _ := setupPresignedTestServer(t)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user