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

197
Visualizações
Content Security Policy connect-src sources 'unsafe-inline' and 'unsafe-eval'

I'm trying to sort out in what situation the sources 'unsafe-inline' and 'unsafe-eval' would be needed on the connect-src directive. They are listed here as sources: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/connect-src

It seems clear to me why these sources would be needed on script-src, I just can not piece together why they would be necessary for connect-src - and I'm assuming there must be a reason for MDN to list them as sources on this directive.

Can someone help me understand or give me the use case? Take the example below. Notice that I'm successfully making a GET request to mocky.io from an inline script, and then calling eval() w/in the callback WITHOUT the 'unsafe-inline' or 'unsafe-eval' source for the connect-src directive.

<html lang="en">

<head>
    <meta http-equiv="Content-Security-Policy" content="script-src 'unsafe-inline' 'unsafe-eval'; connect-src https://run.mocky.io;">
</head>

<body>
    <h1>Testing CSP</h1>
    
    <!-- testing any JS executing from unsafe inline -->
    <script type="text/javascript">
    console.log("Testing some unsafe inline");
    </script>
    
    <!-- testing XHR calls from unsafe inline -->
    <script type="text/javascript">
    const callMocky = () => {
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                //eval from the XHR state change
                eval("console.log('XHR Sent and Received!')")
                console.log(xhttp.responseText);

            }
        };
        xhttp.open("GET", "https://run.mocky.io/v3/7ef12b35-8438-424f-8a5f-b11521d03fe7", true);
        xhttp.send();
    }

    callMocky()
    </script>

    <!-- testing unsafe eval from unsafe inline -->
    <script type="text/javascript">
        eval('console.log("this is an unsafe eval!")')
    </script>


</body>

</html>
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