Commit 47448a2 1 parent 4d8c0bb commit 47448a2 Copy full SHA for 47448a2
File tree 2 files changed +17
-3
lines changed
docs/content/1.docs/2.features
playground/server/api/blob
2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -73,8 +73,7 @@ Returns [`BlobListResult`](#bloblistresult).
73
73
74
74
### ` serve() `
75
75
76
- Returns a blob's data.
77
-
76
+ Returns a blob's data and sets ` Content-Type ` , ` Content-Length ` and ` ETag ` headers.
78
77
79
78
:: code-group
80
79
``` ts [server/routes/images/[...pathname\\ ].get.ts]
@@ -91,6 +90,21 @@ export default eventHandler(async (event) => {
91
90
```
92
91
::
93
92
93
+ :: important
94
+ To prevent XSS attacks, make sure to control the Content type of the blob you serve.
95
+ ::
96
+
97
+ You can also set a ` Content-Security-Policy ` header to add an additional layer of security:
98
+
99
+ ``` ts [server/api/images/[...pathname\\ ].get.ts]
100
+ export default eventHandler (async (event ) => {
101
+ const { pathname } = getRouterParams (event )
102
+
103
+ setHeader (event , ' Content-Security-Policy' , ' default-src \' none\' ;' )
104
+ return hubBlob ().serve (event , pathname )
105
+ })
106
+ ```
107
+
94
108
#### Params
95
109
96
110
:: field-group
Original file line number Diff line number Diff line change @@ -2,6 +2,6 @@ export default eventHandler(async (event) => {
2
2
const { pathname } = await getValidatedRouterParams ( event , z . object ( {
3
3
pathname : z . string ( ) . min ( 1 )
4
4
} ) . parse )
5
-
5
+ setHeader ( event , 'Content-Security-Policy' , 'default-src \'none\';' )
6
6
return hubBlob ( ) . serve ( event , pathname )
7
7
} )
You can’t perform that action at this time.
0 commit comments