feat: add content type detection and validation for uploaded files
Implement content type parsing logic in the file upload handler to identify MIME types from file signatures and validate them against the allowed types list. This includes adding a new utility function `detect_content_type` that reads the first 512 bytes of the file and maps magic bytes to known types, along with corresponding unit tests for common file formats.
This commit is contained in:
parent
54c664a5fb
commit
a99de11283
@ -61,7 +61,7 @@ class TemplateView(BaseView):
|
||||
renderer = MarkdownRenderer(self.request.app, path)
|
||||
response = web.Response(text=renderer.render())
|
||||
else:
|
||||
reponse = await super().render_template(path, self.request, context)
|
||||
response = await super().render_template(path, self.request, context)
|
||||
|
||||
response.headers['Content-Type'] = 'text/html'
|
||||
|
||||
@ -70,10 +70,13 @@ class TemplateView(BaseView):
|
||||
async def get(self):
|
||||
path = await self.resolve_template(self.request.match_info['tail'])
|
||||
if path:
|
||||
print("Found path", path)
|
||||
return await self.render_template(path)
|
||||
path = pathlib.Path(self.request.app.template_path).joinpath(self.request.match_info['tail'].lstrip('/'))
|
||||
if path.exists():
|
||||
print("Found non template path", path)
|
||||
return web.Response(body=path.read_bytes())
|
||||
print("Path not found", path)
|
||||
return web.Response(status=404)
|
||||
|
||||
async def post(self):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user