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:
2025-01-27 22:31:08 +00:00
parent 8a5e42ce30
commit 6162f5c566
+4 -2
View File
@@ -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'])