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

208
Views
What is wrong in my implementation of nonce for a inline-js with csp and flask?

I have implemented a nonce for a csp inline js. Struggling with finding why it doesn't work. When accessing a page get this error:

Content Security Policy: The page's settings blocked the loading of a resource at https://loca.../script.js ("script-src").
Content Security Policy: The page's settings blocked the loading of a resource at inline ("script-src").

Implempleted to flask: // Inside timer.py file implemented a function to create nonce.

def GetCspNonce():
  """Returns a random nonce."""
  NONCE_LENGTH = 16
  return base64.b64encode(os.urandom(NONCE_LENGTH))

nonce = GetCspNonce()

function to redirect to a template:
return render_template('base/timer.html', timer= timer, nonce=nonce)

// Added to init.py csp nonce.

def create_app():
    # create and configure the app
....

    csp = {
        'default-src': ['\'self\''],
        'script-src': ['https://www.goog....], 'nonce-{nonce}'],...

//timer.html

<td> 
    <p> ...</p>

        <script type="text/javascript" src="../static/text/script.js" nonce="{nonce}"></script>

            </td>
about 4 years ago · Juan Pablo Isaza
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!