Skip to main content
🔒 Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial →
← CoursesFastAPI ProductionModule 6 · Real-World PatternsCORS pitfallspredict103 / 105
+125 XP
Task
📝 **Task:** Predict the output. `validate_cors` returns (False, reason) for misconfigurations and (True, 'ok') for safe ones. Wildcard + credentials is the classic bug. Empty origins is also rejected. 📋 Implement the function above. Tests run automatically. 💡 **Hint:** Re-read the theory if stuck.
Predict the output

Read the code carefully

def validate_cors(origins, allow_credentials):
    if allow_credentials and '*' in origins:
        return False, 'wildcard origin forbidden with credentials'
    if not origins:
        return False, 'origins list cannot be empty'
    return True, 'ok'

print(validate_cors(['*'], True))
print(validate_cors(['*'], False))
print(validate_cors(['https://app.example.com'], True))
print(validate_cors([], False))

What will the program print? Write here:

💬 Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…