Add support to override default templates with custom ones (Fixes: #14)

This commit is contained in:
doobry 2019-02-26 12:40:11 +01:00
parent 15a1139577
commit c52b417840
No known key found for this signature in database
GPG Key ID: B336D1A4E1A12B24
3 changed files with 14 additions and 0 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
__pycache__
custom_templates

View File

@ -79,6 +79,12 @@ collector cronjob to remove leftover files . Besides, it can create a
the uploads folder, to ensure that the uploaded files won't be recoverable
between reboots.
# Custom templates
You can override the default templates from `templates/` by putting replacements
into the directory path that's configured in `app.config['CUSTOM_TEMPLATES_DIR']`
(default `custom_templates/`).
# Threat model
- An attacker in possession of the very same file that a user wants to clean,

View File

@ -6,6 +6,7 @@ from libmat2 import parser_factory
from flask import Flask, flash, request, redirect, url_for, render_template
from flask import send_from_directory, after_this_request
import jinja2
from werkzeug.utils import secure_filename
@ -14,6 +15,12 @@ app = Flask(__name__)
app.config['SECRET_KEY'] = os.urandom(32)
app.config['UPLOAD_FOLDER'] = './uploads/'
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB
app.config['CUSTOM_TEMPLATES_DIR'] = 'custom_templates'
app.jinja_loader = jinja2.ChoiceLoader([ # type: ignore
jinja2.FileSystemLoader(app.config['CUSTOM_TEMPLATES_DIR']),
app.jinja_loader,
])
def __hash_file(filepath: str) -> str:
sha256 = hashlib.sha256()