Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

292
Visualizações
Is a javascript file XSS safe?

I was asked to correct an XSS vulnerability on an old site web, using jsp and javascript.

On a "Return" button, I would put a "backURL" parameter as a href, to be able to go back to the previous page I was on.

Previously, my javascript code was in the HTML page, which would make it exploitable by replacing the parameter with a script.

I came up with 2 "Solutions" and I wanted to ask if they were valid.

First, I would encode the URL when getting the parameter in the javascript function, using this library: https://www.owasp.org/index.php/OWASP_Java_Encoder_Project

Here's the code in my jsp file:

<a class="float_left button" href="#" onclick="goback(this)" >Retour</a>

Then right under it, in the same file:

<script type="text/javascript">
 function goback(domEle) {
        var backUrl = "${e:forHtml(param.backUrl)}";
        domEle.href= decodeEntity(backUrl);
    }

    function decodeEntity(str){
       return str.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">");
    }

But then, I thought that it would maybe work to just put this javascript in another file, doing like this:

JSP file:

<a class="float_left button" href="#" onclick="goback(this,'${param.backUrl}')" >Retour</a>

javascript file:

function goback(domEle,backUrl) {
        domEle.href= backUrl;
    }

From my tests, both seem to work. But I wanted to know if it was really completely XSS proof, and if it is which one is the best way to do.

Thanks in advance !

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda