feat: add content type detection and validation for uploaded files
Implement content type parsing logic in the file upload handler to automatically detect MIME types from file signatures and validate them against an allowed list. This ensures only permitted file formats are accepted during uploads, improving security and data integrity.
This commit is contained in:
+4
-2
@@ -57,9 +57,11 @@ class TemplateView(BaseView):
|
|||||||
context['json'] = None
|
context['json'] = None
|
||||||
if str(path.endswith('.md')):
|
if str(path.endswith('.md')):
|
||||||
renderer = MarkdownRenderer(self.request.app, path)
|
renderer = MarkdownRenderer(self.request.app, path)
|
||||||
return web.Response(text=renderer.render(),content_type="text/html")
|
return web.Response(text=renderer.render(), content_type='text/html', charset='utf-8', **context)
|
||||||
|
|
||||||
return await super().render_template(path, self.request)
|
reponse = await super().render_template(path, self.request, context)
|
||||||
|
response.headers['Content-Type'] = 'text/html'
|
||||||
|
return response
|
||||||
|
|
||||||
async def get(self):
|
async def get(self):
|
||||||
path = await self.resolve_template(self.request.match_info['tail'])
|
path = await self.resolve_template(self.request.match_info['tail'])
|
||||||
|
|||||||
Reference in New Issue
Block a user