Database systems: correct, shared and hard to keep secret

8 min 6 sections 4 practice questions 11 sources citedISC2 objective 3.5

A database holds an organisation's records in a form many people and programs can search and change at once. It must stay correct while hundreds of changes arrive together, and it must stop users learning more than they are allowed, even from answers they are allowed to see. No technical background is assumed. A security professional recognises how databases fail and which controls keep them correct and discreet.

By the end of this unit you will be able to:

  • Explain tables, rows, primary and foreign keys, queries and views
  • Name the four ACID properties and explain commit, rollback, locking and two-phase commit
  • Describe how SQL injection works and why parameterised queries stop it
  • Tell apart aggregation and inference, and choose a defence against each
  • Explain polyinstantiation, data warehouses, data mining and non-relational stores

An average that gave away one salary

An illustrative example

A housing association's reporting tool lets team managers see the average salary of any team, but never one person's salary. A manager runs the report for the five-person finance team: the average is 32,000 pounds.

The next week one finance officer moves to another team. The manager runs the same report for the four who remain: the average is now 30,000 pounds. She works out the departed officer's salary in her head.

Every answer she saw was one she was allowed to see. How did she learn a figure she was not allowed to know, and what should the tool have refused?

Tables, rows, keys and views

A relational database stores data in tables, like spreadsheets that link to one another. Each row, also called a record or tuple, describes one thing, such as one tenant. Each column, or attribute, holds one fact about it, such as a rent amount.

Primary key
A column whose value is unique in every row and never empty, such as a tenant number. It identifies exactly one row.
Foreign key
A column that holds another table's primary key, linking the two. A rent payment row holds the tenant number of the tenant who paid.
Query
A request to find or change data, usually written in SQL, the Structured Query Language.
View
A saved query that looks like a table but holds no data of its own. A view showing names and phone numbers, but not salaries, lets staff use the table without seeing salaries.

Views are a basic database control. Users are given rights to a view, not to the full table, so they see only the rows and columns their job needs.

Transactions and the four ACID properties

Moving money from savings to a current account is two changes: take from one, add to the other. If the computer fails between them, the money vanishes. A transaction groups changes so they succeed or fail as one. Four properties, known as ACID, describe a reliable transaction.

The ACID properties of a database transaction
PropertyMeaningIn the bank transfer
AtomicityAll of the changes happen, or none doBoth the debit and the credit are made, or neither
ConsistencyThe data obeys every rule of the database after the transactionTotal money held by the bank is unchanged
IsolationUnfinished changes are invisible to other transactionsNo other report sees the money gone from both accounts
DurabilityOnce confirmed, changes survive a crashThe transfer is still there after a power cut

A commit makes a transaction's changes final and visible. A rollback undoes every change since the transaction began. Many users work at once, which is concurrency. A lock stops a second user changing a row while the first is still working on it, so that two clerks cannot both sell the last seat.

Without concurrency control, three failures occur. A lost update: two users change the same row and the second overwrites the first. A dirty read: one transaction reads a change that is later rolled back. Locks bring their own failure, deadlock: two transactions each wait for a row the other has locked, and neither can finish.

When one transaction spans several databases, two-phase commit keeps them in step. In the first phase, a coordinator asks every database to prepare and confirm it can commit. In the second, it tells all of them to commit, or, if any could not prepare, all of them to .

SQL injection: data that becomes a command

SQL injection happens when a program builds a query by pasting a user's typing into the text of a command. The database cannot tell the user's words from the program's.

A tenant search box

The program builds: SELECT * FROM tenants WHERE surname = ' followed by whatever was typed, then a closing quote mark.

A user types Smith. The query finds tenants named Smith.

An attacker types x' OR '1'='1. The finished command now asks for tenants named x, or any row where 1 equals 1. Every row matches, and the whole table is returned.

The fix is a parameterised query, also called a . The program sends the command with a placeholder, and sends the user's input separately. The database treats the input only as a value to look for, never as part of the command. Supporting controls are checking input against what is expected, and connecting with an account that may read only what the program needs.

Aggregation and inference

Two problems let a user learn more than any single answer shows.

Aggregation is when a collection of items is more sensitive than each item alone. One web page lists a power company's substations. Another lists which ones have no backup supply. Each is harmless; together they are a map of weak points. The defence is to the collection higher than its parts and control who may gather it.

Inference is deducing information a user is not cleared for from information they are allowed to see. The manager in the housing association combined two permitted averages with a known staff move.

Aggregation gathers items; inference deduces from them

Aggregation gathers items; inference deduces from themTwo panels. Aggregation: a public list of substations and a list of those without backup supply combine into a map of weak points, answered by classifying the collection. Inference: two permitted averages reveal one salary, answered by query-size limits.AggregationSubstationlocationspublic listNo backupsupplypublic listWeak-pointmapmore sensitivethan eitherClassifycollectionhigher, andcontrol itInferenceAverageof five32,000 poundsAverageof four30,000 poundsSalarydeduced40,000 pounds,never shownQuery-sizelimitsrefuse smallgroupsAggregation gathers items; inference deduces from themTwo panels. Aggregation: a public list of substations and a list of those without backup supply combine into a map of weak points, answered by classifying the collection. Inference: two permitted averages reveal one salary, answered by query-size limits.AggregationSubstationlocationspublic listNo backupsupplypublic listWeak-pointmapmore sensitivethan eitherClassifycollectionhigher, andcontrol itInferenceAverageof five32,000 poundsAverageof four30,000 poundsSalarydeduced40,000 pounds,never shownQuery-sizelimitsrefuse smallgroups
Read this figure as text

Two problems let a user learn more than any single answer shows. Aggregation gathers items; inference deduces from them.

  1. Aggregation: one web page lists a power company's substations.
  2. Another lists which substations have no backup supply. Each list is harmless alone.
  3. Together they are a map of weak points, more sensitive than either. The defence is to classify the collection higher than its parts and control who may gather it.
  4. Inference: a housing association's tool shows a manager the average salary of the five-person finance team, 32,000 pounds, and never one person's salary.
  5. After one officer moves team, the same report for the four who remain shows 30,000 pounds.
  6. From two permitted answers and a known staff move, the manager deduces the departed officer's salary, 40,000 pounds, which she was never shown. Query-size limits, which refuse answers drawn from too few records, answer inference.

Polyinstantiation is one answer in multilevel databases. The same record exists more than once, at different classification levels, with different contents. A flight's cargo row shows the real cargo to Top Secret users and a plausible cover story to Secret users. An empty cargo field, by contrast, would itself tell Secret users something was hidden.

Defences against inference

Controls that stop users deducing what they may not see
ControlHow it works
Query-size limitsRefuse any statistical answer drawn from fewer than a set number of records
Cell suppressionHide any cell in a published table whose count falls below a threshold
Noise and perturbationAdd small random changes to answers, so exact values cannot be recovered
PartitioningSplit a database into parts so that sensitive combinations cannot be queried together
PolyinstantiationKeep a separate version of a record for each classification level
ViewsShow each user only the rows and columns their role needs
Query-overlap controlRefuse a query whose group differs by only a few records from one the user has already run

A size limit alone fails when two large groups differ by one person. Overlap control, noise or context-dependent control is needed then.

Noise protects at the cost of accuracy, so it suits statistics, not records used to make payments.

Two forms of refine the decision. Content-dependent access control decides on what the data holds: a manager may see salary rows only for staff in her own department. Context-dependent access control decides on the circumstances of the request: the time, the place, or what the user has already retrieved. Context-dependent control can refuse a query that, combined with earlier ones, would allow an inference.

Warehouses, mining and non-relational stores

Data warehouse
A large store that copies data from many operational systems into one place for analysis and reporting. It is an by design, so it needs protection at least as strong as its most sensitive source.
Data mining
Searching large data sets for correlations and patterns. It can reveal facts no single record contains, which is inference at scale.
Big data
Data sets so large, varied or fast-moving that they need storage and processing spread across many machines.
Metadata
Data about data, such as a file's author, creation date or security label. It can disclose more than the data it describes.
NoSQL
Databases that do not use related tables, storing documents, key and value pairs or graphs instead. They spread easily across many machines, and their access controls must be checked as carefully as a 's.

A question, worked through

A university's HR reporting tool lets heads of department see average salaries for any group of staff, but no individual salary. An audit shows a head of department worked out a lecturer's pay by comparing the average for a five-person team with the average for the same team after one member left. The HR director wants reporting to continue.

Which control BEST addresses the weakness the audit found?

  1. Refuse any average drawn from fewer than ten people
  2. Encrypt the salary column in the database tables
  3. Remove heads' access to the reporting tool
  4. Log every query heads run against salaries
Decide on your answer, then open the reasoning
  1. The weakness is inference: permitted averages over small, overlapping groups revealed one person's pay. Reporting must continue.
  2. Rule out b. Encryption protects stored data from someone who takes the storage. The tool decrypts salaries to compute averages, so the answers are unchanged.
  3. Rule out c. It stops the inference by stopping reporting, which the HR director has said must continue.
  4. Between a and d: logging may reveal the misuse afterwards, but the salary is already known. A query-size limit refuses the small groups that make the deduction possible.
  5. Option a prevents the inference and keeps reporting available.

Answer: A. Refuse any average drawn from fewer than ten people

Choosing between good answers

Harmless items become sensitive when gathered together
name it aggregation, and classify and control the collection.
A user deduces a protected fact from permitted answers
name it inference. Choose query-size limits, cell suppression, noise or polyinstantiation over encryption.
A question offers input checking and parameterised queries against SQL injection
choose parameterised queries as the primary defence. Input checking supports it.
A question asks which ACID property is lost when half a transaction is saved
choose atomicity: all or nothing.

Check your understanding

4 questions on this unit, easiest first. Confirm an answer to see the reasoning for it, then the right answer, the other options and the rule to reuse. Your answers are kept in this browser and feed readiness and review.

These questions are drafts that no named reviewer has approved yet.

Question 1 of 4

A warehouse stock report runs while a large order is half processed. It counts goods as removed from the shelves but not yet added to the dispatch area, so stock appears to have vanished.

Which ACID property has failed?

What to remember

  • A primary key identifies one row; a foreign key links to another table; a view shows a chosen part of the data and is a basic access control.
  • ACID: atomicity, consistency, isolation, durability. Commit makes changes final, rollback undoes them, locks manage concurrency, and two-phase commit keeps several databases in step.
  • SQL injection turns input into a command. Parameterised queries keep input as data.
  • Aggregation: the collection is more sensitive than its parts. Inference: a protected fact is deduced from permitted ones.
  • Inference is limited by query-size limits, query-overlap control, cell suppression, noise, partitioning, polyinstantiation, views and context-dependent access control.

Say it from memory

  1. What are the main weaknesses of database systems, and which controls answer them?

    Integrity under concurrent change: ACID transactions, commit and rollback, locking and two-phase commit. SQL injection: parameterised queries and least-privilege connections. Aggregation: classify and control the collection. Inference: query-size limits, cell suppression, noise, partitioning, polyinstantiation, views, and content- and context-dependent access control. Warehouses and data mining aggregate and infer by design.

    Read this part again

  2. How does a primary key differ from a foreign key, and why are views a basic database control?

    A primary key is a column whose value is unique in every row and never empty, identifying exactly one row. A foreign key holds another table's primary key, linking the two. A view is a saved query holding no data of its own; users get rights to a view, so they see only the rows and columns their job needs.

    Read this part again

  3. What do the four ACID properties of a transaction mean?

    Atomicity: all of the changes happen, or none do. Consistency: the data obeys every rule of the database after the transaction. Isolation: unfinished changes are invisible to other transactions. Durability: once confirmed, changes survive a crash.

    Read this part again

  4. What makes SQL injection possible, and what is the fix?

    The program builds a query by pasting a user's typing into the text of a command, so the database cannot tell the user's words from the program's. The fix is a parameterised query, or prepared statement: the command is sent with a placeholder and the input separately, so the input is treated only as a value.

    Read this part again

  5. How does content-dependent access control differ from context-dependent access control?

    Content-dependent control decides on what the data holds: a manager may see salary rows only for staff in her own department. Context-dependent control decides on the circumstances of the request: the time, the place, or what the user has already retrieved. Context-dependent control can refuse a query that, with earlier ones, would allow an inference.

    Read this part again

  6. What is a data warehouse, and why does it need protection at least as strong as its most sensitive source?

    A large store that copies data from many operational systems into one place for analysis and reporting. It is an aggregation by design. Data mining across it searches for correlations and patterns, which is inference at scale.

    Read this part again

Sources