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

295
Views
¿Cómo agregar la palabra clave 'inseguro en línea' para ejecutar javascript en línea?

Estoy aprendiendo javascript y tratando de ejecutar algún código javascript en línea. Estoy usando la guía de inicio rápido de electrones y el código funciona bien antes de intentar agregar un javascript en línea. Aquí está mi index.html :

 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP --> <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'"> <title>Hello World!</title> </head> <body> <script> console.log("Hello World"); // <-- this is the line causing problems </script> <h1>Hello World!</h1> We are using Node.js <span id="node-version"></span>, Chromium <span id="chrome-version"></span>, and Electron <span id="electron-version"></span>. </body> </html>

Cuando intento cargar la página web con el archivo console.log("Hello World") agregado, aparece el error:

Se negó a ejecutar el script en línea porque viola la siguiente directiva de Política de seguridad de contenido: "script-src 'self'". Se requiere la palabra clave 'unsafe-inline', un hash ('sha256-m/hGOmrcpR2CLf5ZFUFQux1kBtD2znXvM4R5xVpagmI=') o un nonce ('nonce-...') para habilitar la ejecución en línea.

El mensaje de error me dice que puedo agregar una palabra clave "insegura en línea" . Exactamente como hago eso?

He intentado buscar ejemplos, como este ejemplo en SO o esta guía en content-security-policy.com . Pero todos los ejemplos solo me dicen que agregue 'inseguro en línea' a la política de seguridad de contenido, sin mostrar realmente cómo se hace.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede agregar unsafe-inline cambiando su metaetiqueta a lo siguiente. Sin embargo, sugeriría mantenerlo igual y simplemente cargar JS a través de un archivo separado, ya que cambiar la etiqueta agrega algunos riesgos de seguridad. Se llama inseguro por una razón.

 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP --> <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline'"> <title>Hello World!</title> </head> <body> <script> console.log("Hello World"); // <-- this is the line causing problems </script> <h1>Hello World!</h1> We are using Node.js <span id="node-version"></span>, Chromium <span id="chrome-version"></span>, and Electron <span id="electron-version"></span>. </body> </html>
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!