Your question is Production Security Vulnerabilities. Take a moment with it on the right.
Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).
Tendo builds clinical workflow software that hospital staff use to look up patient status. Here's the endpoint a new engineer submitted for review.
from flask import Flask, request, jsonify
import jwt
app = Flask(__name__)
SECRET = "tendo-dev-2023"
@app.route("/api/patients/<patient_id>")
def get_patient(patient_id):
token = request.headers.get("Authorization", "").replace("Bearer ", "")
decoded = jwt.decode(token, SECRET, algorithms=["HS256", "none"])
patient = db.execute(f"SELECT * FROM patients WHERE id = {patient_id}").fetchone()
print(f"patient lookup: id={patient_id}, requester={decoded.get('user')}, ssn={patient['ssn']}")
return jsonify({
"id": patient["id"],
"name": patient["name"],
"ssn": patient["ssn"],
"diagnosis": patient["diagnosis"],
})
What security vulnerabilities might exist in this implementation, and how would you mitigate them in a production environment at Tendo?