Cyber security · GCSE · OCR J277 1.4.2, AQA 8525 3.6.3, Edexcel 1CP2 5.3.2 · about 15 min
Validating input, access levels in code, and testing for security.
[1 mark]How does a program reduce the risk of SQL injection?
[1 mark]What does 'fail safely' mean?
[1 mark]What is the principle of least access?
[1 mark]Why should you test with invalid and boundary input?
[1 mark]What does this program print?
def ok(t):
return t.isdigit() and 0 <= int(t) <= 100
print(ok('50'), ok('999'), ok('go'))Write allowed(role, action) using the can_do table, returning True or False. For each (user, role, action) in requests, print <user> (<role>) <action>: allowed or : denied. Validate first: if the role is not in can_do, print <user> (<role>) <action>: unknown role instead. At the end print denied or blocked: <n>.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
can_do = {"student": ["view"], "teacher": ["view", "edit"], "admin": ["view", "edit", "delete"]}
# user, role, action
requests = [
("Sam", "student", "view"),
("Sam", "student", "edit"),
("Mr Lee", "teacher", "edit"),
("root", "admin", "delete"),
("ghost", "hacker", "delete"),
]Plan your program here, then type it in and press Run.
governor role that can only view. Check a governor cannot delete.safe_speed from the first cell to also reject an empty string and text with spaces.