Skip to content

Commit 34d03d9

Browse files
author
Corentin
committed
fixing XSS from issue #101
1 parent 19ea26d commit 34d03d9

File tree

3 files changed

+45
-15
lines changed

3 files changed

+45
-15
lines changed

app/ontocreate/routes.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import json
22
import os
33

4+
import bleach
5+
46
from app import db
57
from app.historeport.onto_func import StandardVocabulary
68
from app.models import ReportHisto
@@ -79,14 +81,15 @@ def modify_onto():
7981
with open(
8082
os.path.join(current_app.config["ONTOLOGY_FOLDER"], "ontology.json"), "w"
8183
) as json_file:
82-
json.dump(clean_tree, json_file, indent=4)
84+
sanitized_json = json.loads(bleach.clean(json.dumps(clean_tree)))
85+
json.dump(sanitized_json, json_file, indent=4)
8386

8487
# Update All Reports to the latest Version of ontology
8588
template_ontology = StandardVocabulary(clean_tree)
8689
for report in ReportHisto.query.all():
8790
current_report_ontology = StandardVocabulary(report.ontology_tree)
88-
updated_report_ontology = json.loads(
89-
json.dumps(current_report_ontology.update_ontology(template_ontology))
91+
updated_report_ontology = json.loads(bleach.clean(
92+
json.dumps(current_report_ontology.update_ontology(template_ontology)))
9093
)
9194
# Issue: SQLAlchemy not updating JSON https://stackoverflow.com/questions/42559434/updates-to-json-field-dont-persist-to-db
9295

poetry.lock

Lines changed: 37 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "impatient"
3-
version = "1.5.0"
3+
version = "1.5.1"
44
description = "IMPatienT: an integrated web application to digitize, process and explore multimodal patient data"
55
authors = ["Corentin Meyer <[email protected]>"]
66
license = "AGPL"
@@ -45,6 +45,7 @@ en_core_web_sm = { url = "https://github.com/explosion/spacy-models/releases/dow
4545
fr_core_news_sm = { url = "https://github.com/explosion/spacy-models/releases/download/fr_core_news_sm-3.2.0/fr_core_news_sm-3.2.0-py3-none-any.whl" }
4646
Flask-Cors = "^3.0.10"
4747
textacy = "^0.12.0"
48+
bleach = "^5.0.1"
4849

4950
[tool.poetry.group.dev.dependencies]
5051
ruff = "^0.0.221"

0 commit comments

Comments
 (0)