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

283
Visualizações
how to use HTML onselect without violating CSP?

So what I'm trying to do is when someone select an element of 'select' form, does something that has been defined on "showPost()" function on script section. and CSP is keep rejecting my operation :(

I've tried both CSP hash and CSP nonce. and both doesn't work.

If I apply 'unsafe inline' it works, so the function has no problem.

What should be wrong?

P.S. : I'm using custom CSS style inside the HTML(EJS) file, so I did CSP hash work on that too on CSP styleSrc setup. and it works just fine.

1. Error Message

error image

2. My Select Form

image of select from

3. Code

Part of HTML(EJS) File

<select class="form-select" aria-label="Order of Aboutme" id="aboutmeOrder" onchange="showPost()">
                <option selected>글 순서를 정해주세요..</option>
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
                <option value="5">5</option>
                <option value="6">6</option>
                <option value="7">7</option>
                <option value="8">8</option>
                <option value="9">9</option>
                <option value="10">10</option>
            </select>

....
....
  <script nonce="example">
  function showPost(){
    var select = document.getElementById("aboutmeOrder").value;
    console.log(select);
  }
  </script>

Part of index.js FIle

const csp = require('helmet-csp');

app.use(helmet());
app.use(
    csp({
      directives: {
        defaultSrc: ["'self'"],
        styleSrc: ["'self' 'sha256-uts7zrnGYAKZNfvBc7PYcShvKP4t10vo5qemd5Yp0lc=' https://cdn.jsdelivr.net/"],
        scriptSrc: [`'self' 'sha256-RemzkHuAMqaMxa/UriyGSEioInZdZJpm6lnkGuugweU=' 'nonce-example' https://cdn.jsdelivr.net/`],
      },
    })
  );
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

nvm, I've got the answer

you have to use 'unsafe-hashes' or gotta use js file.

https://content-security-policy.com/unsafe-hashes/

about 4 years ago · Juan Pablo Isaza Relatório
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