@@ -22,7 +22,8 @@ func (api *API) postFile(rw http.ResponseWriter, r *http.Request) {
22
22
apiKey := httpmw .APIKey (r )
23
23
// This requires the site wide action to create files.
24
24
// Once created, a user can read their own files uploaded
25
- if ! api .Authorize (rw , r , rbac .ActionCreate , rbac .ResourceFile ) {
25
+ if ! api .Authorize (r , rbac .ActionCreate , rbac .ResourceFile ) {
26
+ httpapi .Forbidden (rw )
26
27
return
27
28
}
28
29
@@ -86,9 +87,7 @@ func (api *API) fileByHash(rw http.ResponseWriter, r *http.Request) {
86
87
}
87
88
file , err := api .Database .GetFileByHash (r .Context (), hash )
88
89
if errors .Is (err , sql .ErrNoRows ) {
89
- httpapi .Write (rw , http .StatusNotFound , httpapi.Response {
90
- Message : fmt .Sprintf ("File %q not found." , hash ),
91
- })
90
+ httpapi .ResourceNotFound (rw , fmt .Sprintf ("File %s" , hash ))
92
91
return
93
92
}
94
93
if err != nil {
@@ -99,8 +98,10 @@ func (api *API) fileByHash(rw http.ResponseWriter, r *http.Request) {
99
98
return
100
99
}
101
100
102
- if ! api .Authorize (rw , r , rbac .ActionRead ,
101
+ if ! api .Authorize (r , rbac .ActionRead ,
103
102
rbac .ResourceFile .WithOwner (file .CreatedBy .String ()).WithID (file .Hash )) {
103
+ // Return 404 to not leak the file exists
104
+ httpapi .ResourceNotFound (rw , fmt .Sprintf ("File %s" , hash ))
104
105
return
105
106
}
106
107
0 commit comments