Skip to content

Commit cd3bd0e

Browse files
docs(upload): add security configuration documentation (#2790) (#2807)
* docs(upload): add security configuration documentation * docs(upload): improve description wording * Update docusaurus/docs/cms/features/media-library.md * feat(docs): modifying description --------- Co-authored-by: Araksya Gevorgyan <31159659+araksyagevorgyan@users.noreply.github.com>
1 parent 94155b1 commit cd3bd0e

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

docusaurus/docs/cms/features/media-library.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ When using the default upload provider, the following specific configuration opt
111111
| `providerOptions.localServer` | Options that will be passed to <ExternalLink to="https://github.com/koajs/static" text="koa-static"/> upon which the Upload server is build (see [local server configuration](#local-server)) | Object | - |
112112
| `sizeLimit` | Maximum file size in bytes (see [max file size](#max-file-size)) | Integer | `209715200`<br/><br/>(200 MB in bytes, i.e., 200 x 1024 x 1024 bytes) |
113113
| `breakpoints` | Allows to override the breakpoints sizes at which responsive images are generated when the "Responsive friendly upload" option is set to `true` (see [responsive images](#responsive-images)) | Object | `{ large: 1000, medium: 750, small: 500 }` |
114+
| `security` | Configures validation rules for uploaded files to enhance media security | Object | - |
114115

115116
:::note
116117
The Upload request timeout is defined in the server options, not in the Upload plugin options, as it's not specific to the Upload plugin but is applied to the whole Strapi server instance (see [upload request timeout](#upload-request-timeout)).
@@ -145,6 +146,10 @@ module.exports = ({ env })=>({
145146
small: 500,
146147
xsmall: 64
147148
},
149+
security: {
150+
allowedTypes: ['image/*', 'application/*'],
151+
deniedTypes: ['application/x-sh', 'application/x-dosexec']
152+
},
148153
},
149154
},
150155
});
@@ -171,6 +176,10 @@ export default () => ({
171176
small: 500,
172177
xsmall: 64
173178
},
179+
security: {
180+
allowedTypes: ['image/*', 'application/*'],
181+
deniedTypes: ['application/x-sh', 'application/x-dosexec']
182+
},
174183
},
175184
},
176185
})
@@ -319,6 +328,59 @@ export default {
319328

320329
</Tabs>
321330

331+
#### Security
332+
333+
The Upload plugin validates files based on their actual MIME type rather than the declared file extension.
334+
Only files matching the defined security rules are uploaded.
335+
336+
The `security` configuration provides 2 options: `allowedTypes` or `deniedTypes`, which let you control which file types can or cannot be uploaded.
337+
338+
:::note
339+
You can use `allowedTypes` and `deniedTypes` separately or together to fine-tune which files are accepted. Files must match an allowed type and must not match any denied type. If you use a wildcard like `*` in `allowedTypes`, you can narrow down the validation by specifying exceptions in `deniedTypes`.
340+
:::
341+
342+
You can provide them by creating or editing [the `/config/plugins` file](/cms/configurations/plugins). The following is an example of how to combine `allowedTypes` and `deniedTypes`:
343+
344+
<Tabs groupId="js-ts">
345+
346+
<TabItem value="javascript" label="JavaScript">
347+
348+
```js title="/config/plugins.js"
349+
module.exports = {
350+
// ...
351+
upload: {
352+
config: {
353+
security: {
354+
allowedTypes: ['image/*', 'application/*'],
355+
deniedTypes: ['application/x-sh', 'application/x-dosexec']
356+
},
357+
}
358+
}
359+
};
360+
```
361+
362+
</TabItem>
363+
364+
<TabItem value="typescript" label="TypeScript">
365+
366+
```js title="/config/plugins.ts"
367+
export default {
368+
// ...
369+
upload: {
370+
config: {
371+
security: {
372+
allowedTypes: ['image/*', 'application/*'],
373+
deniedTypes: ['application/x-sh', 'application/x-dosexec']
374+
},
375+
}
376+
}
377+
};
378+
```
379+
380+
</TabItem>
381+
382+
</Tabs>
383+
322384
#### Upload request timeout
323385

324386
By default, the value of `strapi.server.httpServer.requestTimeout` is set to 330 seconds. This includes uploads.

0 commit comments

Comments
 (0)