Potential fix for code scanning alert no. 27: DOM text reinterpreted as HTML #6139
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Potential fix for https://github.com/Catrobat/Catroweb/security/code-scanning/27
In general, the fix is to avoid passing unvalidated DOM text directly into a navigation API. Instead, treat the value as an opaque identifier, validate it strictly (e.g., allow only IDs or a limited pattern), and then safely construct the URL. This both prevents any possibility of HTML/JS interpretation through odd URL schemes and ensures that
window.location.assignonly ever receives an expected, well-formed path.For this code, the best minimal fix without changing functionality is to sanitize the
idargument insideredirectUserbefore it is interpolated into`project/${id}`. Becauseidis used as a path segment, we can (a) restrict its character set to a safe subset (alphanumerics, dash, underscore, etc.) and (b) URL-encode it when building the final URL. This preserves the behavior for well-formed IDs while neutralizing potentially malicious values fromdata-notification-redirect.Concretely:
redirectUser(type, id), introduce a small helper that:idis not a string.A-Za-z0-9_-).encodeURIComponentbefore concatenating into the path.window.location.assigninstead of the rawid.All changes are confined to
assets/User/NotificationsPage.jsin theredirectUsermethod. No new imports or external libraries are needed; we can rely on built‑in JavaScript functions likeencodeURIComponentandString.prototype.replace.Suggested fixes powered by Copilot Autofix. Review carefully before merging.