Skip to content

fix: replace mark_safe(f-string) with format_html to prevent XSS in admin#219

Open
fabiocaccamo with Copilot wants to merge 6 commits into
mainfrom
copilot/fix-code-scanning-alerts-high-level
Open

fix: replace mark_safe(f-string) with format_html to prevent XSS in admin#219
fabiocaccamo with Copilot wants to merge 6 commits into
mainfrom
copilot/fix-code-scanning-alerts-high-level

Conversation

Copilot AI commented Apr 17, 2026

Copy link
Copy Markdown
Contributor
  • Fix XSS vulnerabilities in treenode/admin.py: replace mark_safe(f'...') with format_html(...) for proper HTML escaping in all three display methods
  • Add unit tests for _get_treenode_field_display_with_accordion, _get_treenode_field_display_with_breadcrumbs, and _get_treenode_field_display_with_indentation to restore code coverage (15 new tests, all pass)
  • Run pre-commit on all files → all hooks pass (django-upgrade + ruff format fixes applied to tests/test_admin.py)

…dmin display methods

Agent-Logs-Url: https://github.com/fabiocaccamo/django-treenode/sessions/6152e0b0-d0e9-4bed-b726-23c8565a663d

Co-authored-by: fabiocaccamo <1035294+fabiocaccamo@users.noreply.github.com>
@fabiocaccamo
fabiocaccamo marked this pull request as ready for review April 17, 2026 14:39
Copilot AI review requested due to automatic review settings April 17, 2026 14:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens TreeNodeModelAdmin’s admin list display rendering by replacing raw mark_safe(f"...") HTML construction with Django’s format_html() / format_html_join() so interpolated values are properly escaped and stored XSS risk is reduced.

Changes:

  • Update accordion display HTML generation to use format_html() for attribute/value escaping.
  • Refactor breadcrumbs display to use format_html_join() instead of manual string concatenation.
  • Refactor indentation display to use format_html() while keeping indentation markup safe.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread treenode/admin.py Outdated
Comment thread treenode/admin.py Outdated
Comment thread treenode/admin.py
fabiocaccamo and others added 2 commits April 17, 2026 07:53
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@codecov

codecov Bot commented Apr 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 11.11111% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.63%. Comparing base (6e95aa7) to head (ba5a9f4).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
treenode/admin.py 11.11% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #219      +/-   ##
==========================================
+ Coverage   91.23%   91.63%   +0.40%     
==========================================
  Files          11       11              
  Lines         707      705       -2     
==========================================
+ Hits          645      646       +1     
+ Misses         62       59       -3     
Flag Coverage Δ
unittests 91.63% <11.11%> (+0.40%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants