Skip to content
Snippets Groups Projects

Webservice: use SQLite parameter substitution instead of string formatting

Merged Thomas Kluyver requested to merge sqlite-substitution into master
1 unresolved thread

Description

Constructing SQL queries with string formatting can lead to them going spectacularly wrong on malformed inputs. This is usually highlighted as a security vulnerability, but it can also cause problems just by accident if unexpected values appear. Using proper parameters is really just an elementary piece of using a database.

How Has This Been Tested?

I've run this on max-exfl017 and requested recalibration of some CALLAB jobs (following instructions from @danilevc :-). It seems to be running OK - Slurm jobs are being launched and the logs don't show errors. I don't know if there's anything more specific I should check.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the code style of this project.

Reviewers

@danilevc @ahmedk @hammerd

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
43 43 # https://pypi.org/project/databases/
44 44 logging.info("Initializing database")
45 45 conn = sqlite3.connect(config['web-service']['job-db'])
46 c = conn.cursor()
47 try:
48 c.execute("SELECT * FROM jobs")
49 except Exception: # TODO: is it sqlite3.OperationalError?
50 logging.info("Creating initial job database")
51 c.execute("CREATE TABLE jobs(rid, jobid, proposal, run, status, time, det, act)") # noqa
46 conn.execute(
47 "CREATE TABLE IF NOT EXISTS "
48 "jobs(rid, jobid, proposal, run, status, time, det, act)"
49 )
  • Nice changes you are applying there @kluyvert, LGTM

  • Thomas Kluyver mentioned in commit 535e1af2

    mentioned in commit 535e1af2

  • Please register or sign in to reply
    Loading