0
0
Rest APIprogramming~20 mins

Why API security is non-negotiable in Rest API - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
API Security Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why is API security critical for businesses?

APIs connect different software systems and share data. Why is it important to keep APIs secure?

ABecause API security slows down the system and should be avoided.
BBecause APIs are only used internally and do not affect external users.
CBecause APIs do not handle any important data.
DBecause unsecured APIs can expose sensitive data and allow unauthorized access.
Attempts:
2 left
💡 Hint

Think about what happens if someone bad gets access to your API.

Predict Output
intermediate
2:00remaining
What is the output of this API authentication check?

Consider this simplified Python code snippet checking an API key:

def check_api_key(key):
    valid_keys = ['abc123', 'def456']
    if key in valid_keys:
        return 'Access granted'
    else:
        return 'Access denied'

print(check_api_key('xyz789'))

What will this print?

AAccess denied
BAccess granted
CKey error
DNone
Attempts:
2 left
💡 Hint

Is 'xyz789' in the list of valid keys?

🔧 Debug
advanced
2:00remaining
Identify the security flaw in this API token validation code

Look at this code snippet that validates an API token:

def validate_token(token):
    if token == None:
        return False
    if token == '':
        return False
    return True

print(validate_token(''))

What is the problem with this validation?

AIt raises a syntax error due to missing colon.
BIt incorrectly allows empty strings as valid tokens.
CIt correctly rejects empty tokens.
DIt raises a TypeError because of wrong comparison.
Attempts:
2 left
💡 Hint

Check what happens when the token is an empty string.

📝 Syntax
advanced
2:00remaining
Which option causes a syntax error in API request handling?

Which of these Python code snippets will cause a syntax error when handling an API request?

Aresponse = requests.get('https://api.example.com/data')
Bif response.status_code == 200 print('Success')
Cdata = response.json()
Dprint(data['result'])
Attempts:
2 left
💡 Hint

Look for missing punctuation or keywords in the if statement.

🚀 Application
expert
2:00remaining
What is the number of items in the secured API response dictionary?

Given this Python code simulating an API response with security filtering:

response = {'user': 'alice', 'password': 'secret', 'token': 'abc123'}
secured_response = {k: v for k, v in response.items() if k != 'password'}
print(len(secured_response))

What number will be printed?

A2
B3
C1
D0
Attempts:
2 left
💡 Hint

Count keys except 'password'.