Challenge - 5 Problems
API Security Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Why protect API endpoints?
Why is it important to secure API endpoints in a FastAPI application?
Attempts:
2 left
💡 Hint
Think about what could happen if anyone could call your API without checks.
✗ Incorrect
API security protects sensitive data and operations from unauthorized access. Without it, attackers could steal data or cause harm.
❓ component_behavior
intermediate2:00remaining
Effect of missing authentication in FastAPI
What happens if you create a FastAPI endpoint without any authentication or authorization checks?
FastAPI
from fastapi import FastAPI app = FastAPI() @app.get('/data') async def get_data(): return {'secret': 'value'}
Attempts:
2 left
💡 Hint
Check if there is any code that restricts access.
✗ Incorrect
Without authentication, FastAPI endpoints are open to all users by default.
❓ state_output
advanced2:00remaining
Result of missing rate limiting in FastAPI
What is a likely consequence of not implementing rate limiting on a FastAPI API?
Attempts:
2 left
💡 Hint
Think about what happens if too many people use the API at once.
✗ Incorrect
Without rate limiting, attackers or heavy users can overload the API, causing performance issues or downtime.
📝 Syntax
advanced2:00remaining
Correct way to add API key security in FastAPI
Which code snippet correctly adds an API key header check to a FastAPI endpoint?
Attempts:
2 left
💡 Hint
Look for proper use of Header and raising HTTPException for unauthorized access.
✗ Incorrect
Option D correctly uses FastAPI's Header to get the API key and raises HTTPException with 401 status if invalid.
🔧 Debug
expert3:00remaining
Identify the security flaw in this FastAPI code
What is the main security flaw in this FastAPI code snippet?
FastAPI
from fastapi import FastAPI, Depends, HTTPException, Header app = FastAPI() async def verify_token(token: str = Header(None)): if token != 'validtoken': raise HTTPException(status_code=401, detail='Invalid token') @app.get('/items/') async def read_items(token: str = Depends(verify_token)): return {'items': ['apple', 'banana']}
Attempts:
2 left
💡 Hint
Check how the token parameter is passed to verify_token.
✗ Incorrect
The verify_token function expects a token string but FastAPI does not know where to get it from. Without specifying Header or Query, token will be missing and verification fails silently.