File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change 1
1
// @ts -nocheck
2
2
export default defineEventHandler ( ( event ) => {
3
- const isS3Mutation = getRequestURL ( event ) . pathname . includes ( 's3/mutation' )
4
- const isS3Query = getRequestURL ( event ) . pathname . includes ( 's3/query' )
3
+ const { pathname } = getRequestURL ( event )
4
+ const isS3Mutation = pathname . startsWith ( '/api/s3/mutation' )
5
+ const isS3Query = pathname . startsWith ( '/api/s3/query' )
5
6
6
7
if ( isS3Mutation ) {
7
- checkUser ( event )
8
+ checkUpload ( event )
8
9
9
10
// https://github.com/unjs/nitro/issues/1719
10
11
const isBase64 = ( value : string ) => {
Original file line number Diff line number Diff line change 1
1
import type { H3Event } from 'h3'
2
2
import { compareSync } from '#auth'
3
+ import { getKey } from '#s3'
3
4
4
5
export async function checkDevice ( event : H3Event ) {
5
6
const deviceId = event . context . params ?. id
@@ -29,3 +30,15 @@ export function checkUser (event: H3Event) {
29
30
}
30
31
throw createUnauthorizedError ( )
31
32
}
33
+
34
+ export function checkUpload ( event : H3Event ) {
35
+ const { userId } = checkUser ( event )
36
+
37
+ const key = getKey ( event )
38
+
39
+ const userIdFromKey = key . split ( '/' ) [ 0 ]
40
+
41
+ if ( userId !== userIdFromKey ) {
42
+ throw createUnauthorizedError ( )
43
+ }
44
+ }
You can’t perform that action at this time.
0 commit comments