Bird
0
0

You want to configure Flask-Talisman to add a Content-Security-Policy that only allows scripts from your own domain and trusted.com. Which code snippet correctly sets this?

hard📝 Application Q8 of 15
Flask - Security Best Practices
You want to configure Flask-Talisman to add a Content-Security-Policy that only allows scripts from your own domain and trusted.com. Which code snippet correctly sets this?
ATalisman(app, content_security_policy="script-src 'self' trusted.com")
BTalisman(app, content_security_policy={"script-src": ["'self'", "trusted.com"]})
CTalisman(app, content_security_policy={"script-src": "'self' trusted.com"})
DTalisman(app, content_security_policy={"script-src": ["self", "trusted.com"]})
Step-by-Step Solution
Solution:
  1. Step 1: Understand Talisman content_security_policy format

    It expects a dictionary with directives as keys and lists of sources as values.
  2. Step 2: Check correct syntax for script-src

    Sources must be strings with quotes for 'self', so ["'self'", "trusted.com"] is correct.
  3. Final Answer:

    Talisman(app, content_security_policy={"script-src": ["'self'", "trusted.com"]}) -> Option B
  4. Quick Check:

    Use dict with list of quoted sources for CSP in Talisman [OK]
Quick Trick: CSP in Talisman uses dict with list of quoted sources [OK]
Common Mistakes:
MISTAKES
  • Passing CSP as string
  • Omitting quotes around 'self'
  • Using unquoted self without quotes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes