Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

187
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda