0
0
Cybersecurityknowledge~10 mins

File upload security in Cybersecurity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check the file extension before upload.

Cybersecurity
if filename.endswith([1]):
    print("File accepted")
Drag options to blanks, or click blank then click option'
A".jpg"
B".bat"
C".exe"
D".dll"
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing executable extensions like .exe or .bat which are unsafe.
2fill in blank
medium

Complete the code to limit the maximum file size to 5MB.

Cybersecurity
if file_size [1] 5 * 1024 * 1024:
    print("File size is acceptable")
Drag options to blanks, or click blank then click option'
A>
B==
C<=
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using > or >= which would accept files larger than 5MB.
3fill in blank
hard

Fix the error in the code that checks for allowed MIME types.

Cybersecurity
allowed_types = ['image/png', 'image/jpeg']
if file_mime_type [1] allowed_types:
    print("MIME type allowed")
Drag options to blanks, or click blank then click option'
A==
Bnot in
C!=
Din
Attempts:
3 left
💡 Hint
Common Mistakes
Using == which compares to the whole list, not membership.
4fill in blank
hard

Fill both blanks to safely save the uploaded file with a unique name.

Cybersecurity
import uuid
unique_name = str(uuid.[1]()) + [2] + file_extension
save_file(unique_name)
Drag options to blanks, or click blank then click option'
Auuid4
B"_"
C"."
Duuid1
Attempts:
3 left
💡 Hint
Common Mistakes
Using uuid1 which is time-based and less random.
Joining with underscore instead of dot.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension filtering safe files by size and extension.

Cybersecurity
safe_files = {file: size for file, size in files.items() if file.endswith([1]) and size [2] [3]
Drag options to blanks, or click blank then click option'
A".png"
B<=
C5 * 1024 * 1024
D".exe"
Attempts:
3 left
💡 Hint
Common Mistakes
Using unsafe extensions like .exe.
Using > instead of <= for size.