Bird
0
0

How can you configure FastAPI CORS middleware to allow credentials only from a single trusted origin?

hard🚀 Application Q9 of 15
FastAPI - Middleware and Hooks
How can you configure FastAPI CORS middleware to allow credentials only from a single trusted origin?
ASet allow_origins to ["*"] and allow_credentials=True
BSet allow_origins to ["https://trusted.com"] and allow_credentials=False
CSet allow_origins to ["https://trusted.com"] and allow_credentials=True
DSet allow_origins to ["*"] and allow_credentials=False
Step-by-Step Solution
Solution:
  1. Step 1: Understand credentials and origins

    Credentials require specific origins, not wildcard "*".
  2. Step 2: Match trusted origin with credentials

    Setting allow_origins to trusted site and allow_credentials=True is correct.
  3. Final Answer:

    Set allow_origins to ["https://trusted.com"] and allow_credentials=True -> Option C
  4. Quick Check:

    Credentials + specific origin = B [OK]
Quick Trick: Credentials need specific origin, not wildcard [OK]
Common Mistakes:
MISTAKES
  • Using wildcard origins with credentials
  • Disabling credentials when needed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes