Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

194
Views
Is this a legitimate XSS vulnerability and if yes, how to refactor to fix it?

The following function is flagged as a reflective vector for XSS attacks by scanning software. However, the function is never passed any user-inputted data of any kind nor does it use data from a database that has user-entered data.

Added: The goal of the code is a simple module for other classes to call and build a button with an assigned event action.

So,

  1. this cannot be a vector for XSS attacks, correct?
  2. if I missed something in my understanding of XSS vulnerabilities even when no user-entered data is used, how should this be re-factored to eliminate the threat?
export default class Button {
    constructor(html = "", classList = []) {

        this._button = document.createElement("button");
        this._button.classList.add(...classList);
        this._button.innerHTML = html; // <-- flagged by scanning software
    }
    
    get button() {
        return this._button;
    }
    
    setOnClickAction(action = null) {
        if (action === null || !(action instanceof Function)) {
            throw new Error("Button action cannot be null.");
        }

        this._element.addEventListener("click", action);
    }
}

function is called like this:

const button = new Button("General<small><br>(Receiving)</small>",
                                  ["btn", "btn-light", "btn-outline-dark", "ml-1", "mr-1", "text-info"]);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you are absolutely sure no user created values at all are entered in the html argument, then it is fine.

On another note, you shouldn't be using .innerHTML unless the value will pass in HTML like <h1>content here</h1>. Instead, use .innerText, which does not allow HTML to be rendered, instead passes plain CDATA content.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!