Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started

Code Review for Security Flaws

HardSecurity & Infrastructure00:00
Practice interviewer
In session
5 left
00:00

Your question is Code Review for Security Flaws. 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).

You need to log in / sign up to chat or submit.

Problem

Hitachi Vantara is doing a pre-release security pass on an internal API that manages customer storage volumes for its data-infrastructure platform. Here is one file from that service, pulled as-is from the pull request.

import sqlite3
import pickle
from flask import Flask, request, jsonify

app = Flask(__name__)

API_SIGNING_KEY = "hv-prod-8f61c2a9b3d4e5f6a7b8c9d0e1f2a3b4"

def get_db():
    return sqlite3.connect("volumes.db")

@app.route("/volumes/search")
def search_volumes():
    tenant = request.args.get("tenant")
    name = request.args.get("name")
    db = get_db()
    cursor = db.cursor()
    query = "SELECT id, name, size_gb FROM volumes WHERE tenant = '" + tenant + "' AND name LIKE '%" + name + "%'"
    cursor.execute(query)
    return jsonify(cursor.fetchall())

@app.route("/volumes/<volume_id>", methods=["DELETE"])
def delete_volume(volume_id):
    db = get_db()
    db.execute("DELETE FROM volumes WHERE id = ?", (volume_id,))
    db.commit()
    return jsonify({"status": "deleted"})

@app.route("/volumes/restore", methods=["POST"])
def restore_volume():
    snapshot = pickle.loads(request.data)
    write_snapshot_to_disk(snapshot)
    return jsonify({"status": "restored"})

Given this code, tell some of the security flaws that you notice. For each one, say what an attacker could actually do with it and which OWASP Top 10 category it falls under.