Bird
Raised Fist0
Cybersecurityknowledge~10 mins

Serverless security considerations in Cybersecurity - Interactive Code Practice

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the sentence to identify a key security concern in serverless computing.

Cybersecurity
One major security concern in serverless is [1] due to the shared environment.
Drag options to blanks, or click blank then click option'
Anetwork speed
Bdata isolation
Chardware failure
Duser interface
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing network speed with security
Thinking hardware failure is the main concern in serverless
2fill in blank
medium

Complete the sentence to explain a security best practice for serverless functions.

Cybersecurity
To reduce risk, serverless functions should have [1] permissions following the principle of least privilege.
Drag options to blanks, or click blank then click option'
Amaximum
Bshared
Cminimal
Ddefault
Attempts:
3 left
💡 Hint
Common Mistakes
Assuming maximum permissions improve security
Using default permissions without review
3fill in blank
hard

Fix the error in the security practice described below.

Cybersecurity
Serverless functions should avoid [1] to prevent unauthorized access to resources.
Drag options to blanks, or click blank then click option'
Aencrypting data
Busing environment variables
Clogging errors
Dhardcoding credentials
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing environment variables with hardcoding
Thinking logging errors is a security risk in this context
4fill in blank
hard

Fill both blanks to complete the security measure for serverless functions.

Cybersecurity
Implement [1] to monitor function activity and use [2] to control access based on user identity.
Drag options to blanks, or click blank then click option'
Alogging
Bfirewalls
Cidentity and access management
Dcaching
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up firewalls with IAM
Choosing caching instead of logging
5fill in blank
hard

Fill all three blanks to complete the serverless security best practices.

Cybersecurity
Use [1] to protect data in transit, [2] to secure stored secrets, and [3] to limit function execution time.
Drag options to blanks, or click blank then click option'
Aencryption
Bsecret managers
Ctimeouts
Dload balancers
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing load balancers with security controls
Not using secret managers for credentials

Practice

(1/5)
1. What is a key security principle to follow when configuring permissions for serverless functions?
easy
A. Allow permissions only during business hours
B. Give all permissions to avoid errors
C. Use default permissions without changes
D. Grant only the minimum permissions needed for the function to work

Solution

  1. Step 1: Understand the principle of least privilege

    Least privilege means giving only the permissions necessary for a task, nothing extra.
  2. Step 2: Apply least privilege to serverless functions

    Serverless functions should have minimal permissions to reduce risk if compromised.
  3. Final Answer:

    Grant only the minimum permissions needed for the function to work -> Option D
  4. Quick Check:

    Least privilege = Grant minimum permissions [OK]
Hint: Always limit permissions to what is strictly needed [OK]
Common Mistakes:
  • Giving too many permissions increases risk
  • Using default permissions without review
  • Assuming permissions can be broad safely
2. Which of the following is the correct way to validate input data in a serverless function?
easy
A. Ignore input validation to save time
B. Validate inputs against expected formats and reject invalid data
C. Trust all inputs from authenticated users
D. Validate inputs only after processing

Solution

  1. Step 1: Recognize the importance of input validation

    Validating inputs prevents malicious or malformed data from causing harm.
  2. Step 2: Apply validation before processing inputs

    Rejecting invalid data early protects the function and backend systems.
  3. Final Answer:

    Validate inputs against expected formats and reject invalid data -> Option B
  4. Quick Check:

    Input validation = Check and reject bad data [OK]
Hint: Always check inputs before using them in your code [OK]
Common Mistakes:
  • Trusting inputs from authenticated users blindly
  • Skipping validation to speed up development
  • Validating inputs only after processing
3. Consider this serverless function snippet that processes user data:
def handler(event):
    user_input = event.get('input')
    if not user_input:
        return 'No input'
    return f'Processed: {user_input}'

What is a potential security risk in this code?
medium
A. It does not validate or sanitize the user input
B. It does not encrypt the user input
C. It uses a return statement
D. It checks if input is missing

Solution

  1. Step 1: Analyze input handling in the function

    The function accepts user input but does not check if it is safe or clean.
  2. Step 2: Identify missing input validation or sanitization

    Without validation, malicious input could cause injection or other attacks.
  3. Final Answer:

    It does not validate or sanitize the user input -> Option A
  4. Quick Check:

    Missing input validation = Security risk [OK]
Hint: Look for missing input checks in code snippets [OK]
Common Mistakes:
  • Thinking encryption is needed for all inputs
  • Confusing return usage with security
  • Ignoring input validation importance
4. A developer wrote this serverless function to encrypt data but it fails to run:
import cryptography

def encrypt(data):
    return cryptography.encrypt(data)

What is the main error?
medium
A. The cryptography module does not have a direct encrypt function
B. The function encrypts data correctly
C. Missing import for json module
D. The function encrypts data twice

Solution

  1. Step 1: Check the cryptography module usage

    The cryptography library requires specific classes and methods for encryption, not a direct encrypt function.
  2. Step 2: Identify the incorrect function call

    Calling cryptography.encrypt(data) will cause an error because no such function exists directly.
  3. Final Answer:

    The cryptography module does not have a direct encrypt function -> Option A
  4. Quick Check:

    cryptography.encrypt() does not exist [OK]
Hint: Check library docs for correct function names [OK]
Common Mistakes:
  • Assuming all modules have simple encrypt() functions
  • Ignoring import errors
  • Confusing encryption with data formatting
5. You want to secure a serverless app that processes sensitive user data. Which combination of practices best improves security?
hard
A. Encrypt data only after processing and ignore monitoring
B. Grant full permissions to speed up development and skip input validation
C. Use least privilege permissions, validate inputs, encrypt data at rest and in transit, and monitor logs for suspicious activity
D. Use default permissions and rely on cloud provider security alone

Solution

  1. Step 1: Identify best security practices for serverless apps

    Key practices include least privilege, input validation, encryption, and monitoring.
  2. Step 2: Evaluate each option against these practices

    Use least privilege permissions, validate inputs, encrypt data at rest and in transit, and monitor logs for suspicious activity includes all important steps; others skip critical protections.
  3. Final Answer:

    Use least privilege permissions, validate inputs, encrypt data at rest and in transit, and monitor logs for suspicious activity -> Option C
  4. Quick Check:

    Combine key security steps = Strong protection [OK]
Hint: Combine multiple security steps for best protection [OK]
Common Mistakes:
  • Skipping input validation or monitoring
  • Granting excessive permissions
  • Relying only on cloud defaults