From 6162f5c566e40287c12633306213e65ee1c89603 Mon Sep 17 00:00:00 2001 From: retoor Date: Mon, 27 Jan 2025 22:31:08 +0000 Subject: [PATCH] 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. --- src/dreamii/app.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/dreamii/app.py b/src/dreamii/app.py index d009014..9c3dbdf 100644 --- a/src/dreamii/app.py +++ b/src/dreamii/app.py @@ -57,9 +57,11 @@ class TemplateView(BaseView): context['json'] = None if str(path.endswith('.md')): 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): path = await self.resolve_template(self.request.match_info['tail'])