Security and data governance
הוצג
6:35
מאגרי נתונים
A database is a set of true sentences about a domain. This course shows how to model, query, protect and govern data. The first three units model and shape it…
קריינות באנגלית · כתוביות באנגלית ובסינית 中文 שאפשר להחליף ביניהן
בשיעור הזה
| English | משמעות |
|---|---|
| Authentication/ɔːˌθentɪˈkeɪʃn/ | checking who a user is |
| authorisation/ˌɔːθəraɪˈzeɪʃn/ | הרשאה |
| principle of least privilege/ˈprɪnsɪpl ɒv liːst ˈprɪvɪlɪdʒ/ | עקרון זכויות מינימליות |
| SQL injection/ˌes kjuː ˈel ɪnˈdʒekʃn/ | An injection attack in which untrusted input is treated as SQL instructions and alters the intended database operation. |
| Data governance/ˈdeɪtə ˈɡʌvənəns/ | the rules and roles for who may use which data, and how |
| quasi-identifiers/ˈkweɪzaɪ aɪˈdentɪfaɪəz/ | attributes such as birth date or postcode that can identify a person when combined |
| k-anonymous/keɪ əˈnɒnəməs/ | every record shares its quasi-identifier values with at least k − 1 others |
| Pseudonymisation/ˌsuːdəʊˌnɪmaɪˈzeɪʃn/ | replacing names and IDs with codes that can be linked back only with separate information |
| l-diversity/el daɪˈvɜːsɪti/ | each group of matching records contains at least l different values of the sensitive attribute |
| keyed hash | |
| parameterised statement |
Who you are, what you may do
- Authentication 身份认证 proves who you are; authorisation 授权 decides what you may do. The principle of least privilege 最小权限原则 shapes both: each account gets the narrowest rights that let the job run.

Authorisation decides —
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
Authentication proves identity; authorisation bounds the rights.
Injection, ended
- A query built by pasting user text,
"... WHERE name = '" + input + "'", with the input' OR '1'='1, matches every row: on the sample schema, all 8 students. This is SQL injection SQL注入. - Parameterised statements 参数化语句 send the query and the values separately. The attacker's text can only ever be a value, so the whole type of attack ends, not just this example.
# Unsafe: the input becomes SQL
q = ("SELECT * FROM Student"
" WHERE name = '" + name + "'")
cur.execute(q)
# Safe: the value travels apart
cur.execute(
"SELECT * FROM Student"
" WHERE name = ?", (name,))
Input ' OR '1'='1 in a pasted query matches —
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
The tautology makes the WHERE always true - on the sample, all 8 students.
Grants that fit, governance that repeats
- The teaching grants:
GRANT SELECT ON Student TO reader; GRANT SELECT, INSERT ON Enrollment TO clerk;. The clerk cannot delete an enrolment, and a stolen session can do no more than the grant allows. Remove rights when a person's role changes, not on audit day. - Data governance 数据治理 classifies data (public, internal, sensitive), names an owner, sets how long data is kept and checks who accessed it.
- The sensitive grade column is encrypted on disk, every access is logged, and unused grants are removed every quarter. Never connect the application as the owner: every bug would then run with full authority.
Parameterised statements end SQL injection because —
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
Separate channels: attacker text can only ever be a value.
Removing names is not anonymity
- Deleting names leaves quasi-identifiers 准标识符: postcode, birth date and sex together identify most people. A release is k-anonymous k匿名 if every combination of quasi-identifiers appears at least $k$ times; group sizes $5, 3, 7, 4$ make it $3$-anonymous.
- Pseudonymisation 假名化 replaces names with codes, but the data is still personal, because the key can link back.
- Privacy by design adds minimisation (collect only what the purpose needs), limits on how long data is kept, and coarser values, such as age bands instead of birth dates.
A release has quasi-identifier groups of sizes 6, 4, 9, 2 and 5. What is the largest k for which it is k-anonymous?
רמת קושי 2/5 · 140 מטבעות + בונוס קטן בהשלמה הראשונה היום
k is the smallest group size: 2.
Removing the name column is enough to make a table anonymous.
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
Postcode, birth date and sex together can still identify most people.
k-anonymous but still leaking
- A group of 3 records with the same quasi-identifiers is 3-anonymous. If all three have the same diagnosis, anyone who knows a person is in that group learns the diagnosis.
- l-diversity l多样性 asks for at least $l$ different sensitive values in every group. Group size measures hiding in a crowd; diversity measures whether the crowd shares the secret.
A 3-anonymous group in which all three share one diagnosis protects the diagnosis.
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
Anyone placing a person in the group learns it; l-diversity is needed.
Worked example: make a release 2-anonymous
- Four rows share no quasi-identifiers 准标识符, so each person is unique. Generalise until every combination appears at least twice.
| Before: postcode, birth date | After: postcode, age band |
|---|---|
| 315010, 2004-03-12 | 3150**, 20–24 |
| 315016, 2003-11-30 | 3150**, 20–24 |
| 315201, 1998-07-04 | 3152**, 25–29 |
| 315208, 1999-01-19 | 3152**, 25–29 |
- Now each group holds 2 rows: 2-anonymous. Then check the diagnoses: if both rows in a group share one, the group still leaks it (l-diversity).
Hashing every 8-digit ID at $10^9$ hashes a second: time (seconds)?
רמת קושי 2/5 · 140 מטבעות + בונוס קטן בהשלמה הראשונה היום
$10^8/10^9 = 0.1$ s.
The safest replacement for student IDs in a shared research file is:
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
Small ID spaces make plain hashes reversible by brute force.
Worked example: a hash is not a pseudonym
- Replacing 8-digit student IDs with their SHA-256 hashes looks anonymous. But there are only $10^8$ possible IDs, and hashing them all at $10^9$ a second takes $\mathbf{0.1}$ s.
- A table of all the hashes reverses every one. Use a random code with the key kept separately, or a keyed hash 密钥哈希 whose secret key never leaves the data owner.
Marks that slip away
- Escaping instead of parameterising. Escaping fixes one character; a parameterised statement 参数化语句 ends the whole type of attack.
- Deleting names and calling it anonymous. Postcode, birth date and sex together still identify most people.
- Calling pseudonymised data non-personal. Whoever holds the key can link the codes back, so it is still personal data.
Recap
| Step | Answers | Checked with |
|---|---|---|
| Authentication | who are you? | password, key, second factor |
| Authorisation | what may you do? | roles and grants |
-
Least privilege: grant only what the job needs.
-
Parameterised statements 参数化语句 end SQL injection as a type of attack.
-
Grant narrowly, remove rights when roles change, classify and audit sensitive data.
מה השתבש? רק צוות האתר רואה זאת.