Skip to content

Commit 290b2d2

Browse files
committed
fix: avoid cross-site scripting when rendering html
1 parent 0096627 commit 290b2d2

7 files changed

Lines changed: 30 additions & 19 deletions

File tree

testgen/ui/services/form_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ def render_html_list(dct_row, lst_columns, str_section_header=None, int_data_wid
507507
str_markdown += f"""<div><span class="dk-field-label">{label}</span><span class="dk-{str_use_class}-value">{dct_row[col]!s}</span></div>"""
508508

509509
with st.container():
510-
st.markdown(str_markdown, unsafe_allow_html=True)
510+
st.html(str_markdown)
511511
st.divider()
512512

513513

testgen/ui/views/connections/forms.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,15 +288,14 @@ def render_extra(
288288
elif self._uploaded_file is None and (cached_file_upload := st.session_state.get(cached_file_upload_key)):
289289
self._uploaded_file = cached_file_upload
290290
file_size = f"{round(self._uploaded_file.size / 1024, 2)}KB"
291-
container.markdown(
291+
container.html(
292292
f"""
293293
<div style="display: flex; align-items: center; justify-content: flex-start; padding: 0 16px; margin-bottom: 16px;">
294294
<span style="font-family: 'Material Symbols Rounded'; font-weight: normal; white-space: nowrap; overflow-wrap: normal; font-size: 28.8px; color: rgb(151, 166, 195);">draft</span>
295295
<span style="margin-left: 16px; margin-right: 8px;">{self._uploaded_file.name}</span>
296296
<small style='color: rgba(49, 51, 63, 0.6); font-size: 14px; line-height: 1.25;'>{file_size}</small>
297297
</div>
298-
""",
299-
unsafe_allow_html=True,
298+
"""
300299
)
301300

302301
def reset_cache(self) -> None:

testgen/ui/views/dialogs/application_logs_dialog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def application_logs_dialog():
6565
show_data = log_data
6666

6767
# Refresh button
68-
col3.markdown("<br>", unsafe_allow_html=True)
68+
col3.html("<br>")
6969
if col3.button("Refresh"):
7070
# Clear cache to refresh the log data
7171
st.cache_data.clear()

testgen/ui/views/score_details.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,7 @@ def delete_score_card(definition_id: str) -> None:
169169
delete_clicked, set_delelte_clicked = temp_value(
170170
"score-details:confirm-delete-score-val"
171171
)
172-
st.markdown(
173-
f"Are you sure you want to delete the scorecard <b>{score_definition.name}</b>?",
174-
unsafe_allow_html=True,
175-
)
172+
st.html(f"Are you sure you want to delete the scorecard <b>{score_definition.name}</b>?")
176173

177174
_, button_column = st.columns([.85, .15])
178175
with button_column:

testgen/ui/views/table_groups/page.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,17 @@ def delete_table_group_dialog(self, table_group: pd.Series):
166166
)
167167

168168
if not can_be_deleted:
169-
st.markdown(
170-
":orange[This Table Group has related data, which may include profiling, test definitions and test results. If you proceed, all related data will be permanently deleted.<br/>Are you sure you want to proceed?]",
171-
unsafe_allow_html=True,
169+
st.html(
170+
"""
171+
<div style=\"color: rgb(217, 90, 0);\">
172+
<span>
173+
This Table Group has related data, which may include profiling, test definitions and test results.
174+
If you proceed, all related data will be permanently deleted.
175+
</span>
176+
<br/>
177+
<span>Are you sure you want to proceed?</span>
178+
</div>
179+
"""
172180
)
173181
accept_cascade_delete = st.toggle("I accept deletion of this Table Group and all related TestGen data.")
174182

testgen/ui/views/test_definitions.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,12 @@ def show_test_form(
343343

344344
# Using the test_type, display the default description and usage_notes
345345
if selected_test_type_row["test_description"]:
346-
st.markdown(
346+
st.html(
347347
f"""
348348
<div style="border: 1px solid #e6e6e6; border-radius: 5px; padding: 10px;">
349349
{selected_test_type_row['test_description']}
350350
</div><br/>
351-
""",
352-
unsafe_allow_html=True,
351+
"""
353352
)
354353

355354
if selected_test_type_row["usage_notes"]:
@@ -854,7 +853,7 @@ def show_test_defs_grid(
854853
)
855854

856855
if dct_selected_row:
857-
st.markdown("</p>&nbsp;</br>", unsafe_allow_html=True)
856+
st.html("</p>&nbsp;</br>")
858857
selected_row = dct_selected_row[0]
859858
str_test_id = selected_row["id"]
860859
row_selected = df[df["id"] == str_test_id].iloc[0]

testgen/ui/views/test_suites.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,17 @@ def delete_test_suite_dialog(test_suite_id: str) -> None:
258258
)
259259

260260
if not can_be_deleted:
261-
st.markdown(
262-
":orange[This Test Suite has related data, which includes test definitions and may include test results. If you proceed, all related data will be permanently deleted.<br/>Are you sure you want to proceed?]",
263-
unsafe_allow_html=True,
261+
st.html(
262+
"""
263+
<div style=\"color: rgb(217, 90, 0);\">
264+
<span>
265+
This Test Suite has related data, which includes test definitions and may
266+
include test results. If you proceed, all related data will be permanently deleted.
267+
</span>
268+
<br/>
269+
<span>Are you sure you want to proceed?</span>
270+
</div>
271+
"""
264272
)
265273
accept_cascade_delete = st.toggle("I accept deletion of this Test Suite and all related TestGen data.")
266274

0 commit comments

Comments
 (0)