Skip to content

Fix more DOM text reinterpreted as HTML issues - #1567

Merged
ihalaij1 merged 1 commit into
apluslms:masterfrom
sayravai:fix_1566
Nov 17, 2026
Merged

ihalaij1 merged 1 commit into
apluslms:masterfrom
sayravai:fix_1566

Conversation

@sayravai

@sayravai sayravai commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Description

What?

Fix several potential XSS issues found by the CodeQL scanner in module_goal.js and chapter.js. Also fix related issues (though not XSS nor reported by CodeQL) in filter_submissions_by_tag.js

How?

Issues in module_goal.js (CodeQL issues 84 and 104):

  • Escaping wasn't an option as the tooltip is already HTML rendered by Bootstrap (data-bs-html="true"), so escaping meta-characters would have broken it.
  • Created a function to build the tooltip safely so the translated label and goal_points value from the AJAX response can never inject HTML

Issues in filter_submissions_by_tag.js (not mentioned by CodeQL but also involved parseFromString like above):

  • Use of parseFromString() was unnecessary here as they were already in the live DOM and were never written back to it. Removed it and used the found elements directly.
  • Fix the templates giving every row of the table an id of “submission_tags”, resulting in multiple elements with the same id, and the need to use getElementsByTagName instead of a direct querySelector to get the tags from DOM. Replaced id with class.

Issues in chapter.js (CodeQL issues 4 and 69):

  • Line 413: the data-title comes from RST (by teacher), so there’s little risk here. Nevertheless, replaced the pure string concatenation with an escaping version.
  • Line 833: text like “” or “a < b” from grader output gets eaten/mangled by re-parsing. Also in the image case, base64 output could break out of the attribute. Fix by escaping parameters properly. Note, that this change may affect some courses as the < or & characters will now appear on the output. Note: to pass CodeQL, I had to strip the base64 of HTML meta-characters (< > ' ") before use, even though valid base64 cannot contain those.

All tests passed for me.

Fixes #1566

Testing

Remember to add or update unit tests for new features and changes.

What type of test did you run?

  • Accessibility test using the WAVE extension.
  • Django unit tests.
  • Playwright tests.
  • Other test. (Add a description below)
  • Manual testing.

[ADD A DESCRIPTION ABOUT WHAT YOU TESTED MANUALLY]

Did you test the changes in

  • Chrome
  • Firefox
  • This pull request cannot be tested in the browser.

Think of what is affected by these changes and could become broken

Translation

Programming style

  • Did you follow our style guides?
  • Did you use Python type hinting in all functions that you added or edited? (type hints for function parameters and return values)

Have you updated the README or other relevant documentation?

  • documents inside the doc directory.
  • README.md.
  • Aplus Manual.
  • Other documentation (mention below which documentation).

Is it Done?

  • Reviewer has finished the code review
  • After the review, the developer has made changes accordingly
  • Customer/Teacher has accepted the implementation of the feature

Clean up your git commit history before submitting the pull request!

@sayravai
sayravai force-pushed the fix_1566 branch 2 times, most recently from 86e831d to 514c9cd Compare November 11, 2026 13:57
@ihalaij1
ihalaij1 requested a max review from Copilot November 13, 2026 08:21
@ihalaij1 ihalaij1 self-assigned this Nov 13, 2026
@ihalaij1 ihalaij1 moved this from Todo to Under review in A+ sprints Nov 13, 2026
@ihalaij1
ihalaij1 self-requested a review November 13, 2026 08:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Dotted module IDs can cause goal deletion to throw after succeeding and leave the UI stale, while regression coverage for text, image, and tooltip rendering remains incomplete.

3 open issues
What changed in this PR

This PR addresses #1566 by hardening A-plus exercise rendering against text being reinterpreted as HTML. It also simplifies staff submission-tag filtering and removes duplicate table-cell IDs.

Changes:

  • Build points-goal tooltip content safely with DOM APIs, without reparsing existing markup.
  • Render active-element titles and text feedback as text, and construct image output through DOM APIs.
  • Read submission tags directly from the live DOM and use class-based selectors.
File Description
exercise/​templates/​exercise/​staff/​_submissions_table.html Replace repeated tag-cell IDs with a shared class.
exercise/​static/​exercise/​module_goal.js Safely build, replace, and remove points-goal tooltip blocks.
exercise/​static/​exercise/​filter_submissions_by_tag.js Read tags directly from class-selected DOM cells.
exercise/​static/​exercise/​chapter.js Avoid HTML reinterpretation of titles, text feedback, and image data.
course/​templates/​course/​staff/​all_submissions_table.html Apply the shared tag-cell class to course-wide submissions.

Review effort: Max

Comment thread exercise/static/exercise/chapter.js Resolved
Comment thread exercise/static/exercise/module_goal.js Resolved
Comment thread exercise/static/exercise/module_goal.js Resolved
@ihalaij1
ihalaij1 merged commit 98301ba into apluslms:master Nov 17, 2026
5 checks passed
@github-project-automation github-project-automation Bot moved this from Under review to Done in A+ sprints Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

More DOM text reinterpreted as HTML issues

4 participants