Skip to content

Fix duplicate content loading on main page and XSS vulnerability in URL params#53

Draft
Copilot wants to merge 4 commits intomasterfrom
copilot/fix-duplicate-problems-message
Draft

Fix duplicate content loading on main page and XSS vulnerability in URL params#53
Copilot wants to merge 4 commits intomasterfrom
copilot/fix-duplicate-problems-message

Conversation

Copy link
Contributor

Copilot AI commented Nov 7, 2025

The main page was rendering index.md content twice: once into docContainer (unconditionally) and again into indexHeading (when no URL params present).

Changes

Conditional content loading

  • docContainer now only populates when ?type= or ?codes= params exist
  • Main page leaves docContainer empty, rendering index.md only in indexHeading

Security fix

  • Sanitize URL params before injecting into innerHTML to prevent XSS
  • Restrict to [a-zA-Z0-9-] character set (sufficient for all valid problem/error code names)
// Before: Always loaded index.md, vulnerable to XSS
var doc = "./index.md";
if (urlParams.has('type')) {
    doc = "./" + urlParams.get('type') + ".md";
}
docContainer.innerHTML = "<zero-md src='" + doc + "'></zero-md>";

// After: Conditional loading with sanitization
var doc = null;
if (urlParams.has('type')) {
    var type = urlParams.get('type').replace(/[^a-zA-Z0-9-]/g, '');
    doc = "./" + type + ".md";
}
if (doc) {
    docContainer.innerHTML = "<zero-md src='" + doc + "'></zero-md>";
}

Screenshot

Before: Missing content due to duplicate loading interference
Before

Original prompt

On the main page, I'm getting the below appearing twice. Fix it

Problems
These are the shared problems for Bunnings APIs. All problems are compliant with RFC 7807; some include extensions to the base application/problem+json media type. Refer to individual pages for schema definitions.

Problems returned in this format include a Problem Type URL that can be used to interpret the rest of the response. The URL is of the format https://problem.api.bunnings.com.au?type=, for example: https://problem.api.bunnings.com.au?type=invalidServerState.

Problem types
Refer to the links below for details:


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits November 7, 2025 04:04
…to docContainer on main page

Co-authored-by: echapmanFromBunnings <46700551+echapmanFromBunnings@users.noreply.github.com>
Co-authored-by: echapmanFromBunnings <46700551+echapmanFromBunnings@users.noreply.github.com>
Co-authored-by: echapmanFromBunnings <46700551+echapmanFromBunnings@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix duplicate problems message on main page Fix duplicate content loading on main page and XSS vulnerability in URL params Nov 7, 2025
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.

2 participants