feat: refactor countdown update in AFKOverlay #757
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.
Refactor updateCountdown method to use textContent for countdown updates.
fix unsafe HTML construction, avoid writing untrusted data into
innerHTML. Instead, build the DOM structure usingdocument.createElement, and insert dynamic pieces viatextContent/innerTextor by explicitly setting properties on elements. This prevents the dynamic value from being interpreted as HTML and eliminates the XSS sink.For this specific case, the overlay content is simple and mostly static. The only dynamic part is the numeric countdown. The safest and least intrusive fix is:
<span id="afkCountDownNumber">, is created without dynamic content (this is already done increateContentElement).updateCountdownso it does not rebuild the full HTML string withinnerHTML. Instead, locate the existing<span id="afkCountDownNumber">withinthis.textElementand update itstextContentwith the currentcountdownvalue.Concretely, in
Frontend/ui-library/src/Overlay/AFKOverlay.ts, replace line 47’sinnerHTMLassignment with logic like:const span = this.textElement.querySelector('#afkCountDownNumber') as HTMLSpanElement | null;span.textContent = String(countdown);this.textElement.textContentor do nothing; here, a simple defensive check is enough.No changes are needed in
Frontend/ui-library/src/Application/Application.ts, because after the AFKOverlay is made safe, passingcountDownintoupdateCountdownno longer reaches a dangerous sink.Relevant components: