From dc882c723724007500b8acc0ea27a996d759b5d6 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 12 Jan 2022 00:30:25 +0100 Subject: [PATCH] Do os.path.abspath on custom content folders in the app constructor before initialization If relative paths are used for the content folder then send_from_directory may mistakenly interpret the paths as relative to the main application, instead of the content folder --- madblog/app.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/madblog/app.py b/madblog/app.py index 1bd6526..01fe535 100644 --- a/madblog/app.py +++ b/madblog/app.py @@ -1,4 +1,5 @@ import datetime +import os import re from glob import glob from typing import Optional @@ -23,19 +24,19 @@ class BlogApp(Flask): img_dir = os.path.join(config.content_dir, 'img') if os.path.isdir(img_dir): - self.img_dir = img_dir + self.img_dir = os.path.abspath(img_dir) css_dir = os.path.join(config.content_dir, 'css') if os.path.isdir(css_dir): - self.css_dir = css_dir + self.css_dir = os.path.abspath(css_dir) fonts_dir = os.path.join(config.content_dir, 'fonts') if os.path.isdir(fonts_dir): - self.fonts_dir = fonts_dir + self.fonts_dir = os.path.abspath(fonts_dir) templates_dir = os.path.join(config.content_dir, 'templates') if os.path.isdir(templates_dir): - self.template_folder = templates_dir + self.template_folder = os.path.abspath(templates_dir) def get_page_metadata(self, page: str) -> dict: if not page.endswith('.md'):