week 8

Site: Newgate University Minna - Elearning Platform
Course: Data Management
Book: week 8
Printed by: Guest user
Date: Sunday, 14 June 2026, 3:42 AM

Description

Teaching and Learning Methods to be Employed

1.    Lecture on security mechanisms with live SQL demonstrations

2.    SQL injection attack demonstration and prevention

3.    Lab: Creating users, granting/revoking privileges in MySQL

4.    Discussion: NDPR compliance for Nigerian database systems

 

Learning Outcomes / Objectives

By the end of this week, students should be able to:

1.    Describe the major threats to database security.

2.    Explain authentication, authorisation, and access control in DBMS.

3.    Use SQL DCL commands (GRANT, REVOKE) to manage user privileges.

4.    Explain how database views provide security through data abstraction.

5.    Describe SQL injection and how to prevent it.

6.    Explain encryption and audit trails as security mechanisms.

7.    Describe the requirements of NDPR for database-driven applications.

8.1 Database Security Threats

Database security aims to protect data against accidental or intentional disclosure to unauthorised persons, and data modification or destruction. Major threats include:

 

Threat

Description and Nigerian Example

Unauthorised Access

Users accessing data they have no permission to see. E.g., a bank teller accessing the CEO's salary record.

SQL Injection

Attackers injecting malicious SQL code through application inputs to manipulate the database. Caused major breaches at Nigerian financial institutions.

Insider Threat

Authorised employees misusing their access. E.g., a bank employee stealing customer BVN and account details.

Data Interception

Data stolen in transit between client and server. E.g., unencrypted bank transactions on public WiFi.

Privilege Escalation

Obtaining higher access rights than authorised. E.g., a regular user accessing DBA functions.

Denial of Service (DoS)

Overwhelming the database server to make it unavailable. E.g., the JAMB portal crash during registration.

Physical Theft

Stealing physical storage media containing database files.

 

8.2 Authentication and Authorisation

AUTHENTICATION verifies WHO the user is (identity verification). AUTHORISATION determines WHAT the authenticated user can do (access control).

 

1.    Authentication methods: Username/Password, Multi-Factor Authentication (MFA — widely required by CBN for banking apps), biometrics, digital certificates

2.    Authorisation implements the principle of LEAST PRIVILEGE — users are given only the minimum permissions needed for their role

8.3 SQL Data Control Language (DCL)

MySQL uses GRANT and REVOKE to manage user privileges:

 

-- Create a database user for a bank teller

CREATE USER 'teller_user'@'localhost' IDENTIFIED BY 'SecureP@ss123';

 

-- Grant only SELECT on customer table (tellers can view but not modify)

GRANT SELECT ON bank_db.CUSTOMER TO 'teller_user'@'localhost';

 

-- Grant SELECT and INSERT on TRANSACTION table

GRANT SELECT, INSERT ON bank_db.TRANSACTION TO 'teller_user'@'localhost';

 

-- Grant full privileges to the DBA

GRANT ALL PRIVILEGES ON bank_db.* TO 'dba_user'@'localhost' WITH GRANT OPTION;

 

-- Revoke UPDATE on CUSTOMER from teller (they had it mistakenly)

REVOKE UPDATE ON bank_db.CUSTOMER FROM 'teller_user'@'localhost';

 

-- Show what privileges a user has

SHOW GRANTS FOR 'teller_user'@'localhost';

 

PRIVILEGE TYPES in MySQL:

Privilege

What It Allows

SELECT

Read data from tables

INSERT

Add new rows

UPDATE

Modify existing rows

DELETE

Remove rows

CREATE

Create new tables or databases

DROP

Delete tables or databases

INDEX

Create/drop indexes

ALL PRIVILEGES

All of the above

8.4 Database Views for Security

A VIEW is a virtual table based on the result of a SELECT query. Views provide security by allowing users to see only specific rows and columns, hiding sensitive data.

 

-- Create a view that hides salary information from non-HR staff

CREATE VIEW EMPLOYEE_PUBLIC AS

SELECT EmployeeID, FirstName, LastName, Department, JobTitle, Extension

FROM EMPLOYEE

WHERE IsActive = TRUE;

 

-- Create a view for a specific branch manager — only their branch's customers

CREATE VIEW MINNA_BRANCH_CUSTOMERS AS

SELECT CustomerID, FirstName, LastName, AccountType, Balance

FROM CUSTOMER

WHERE BranchCode = 'MNA001';

 

-- Grant access to the view, not the base table

GRANT SELECT ON bank_db.EMPLOYEE_PUBLIC TO 'branch_user'@'localhost';

 

View Security Benefit: A bank branch manager can SELECT from MINNA_BRANCH_CUSTOMERS and see only their branch's customers. They cannot see customers from other branches even if they try SELECT * FROM CUSTOMER (they don't have permission on the base table). This is security through abstraction.

8.5 SQL Injection — Attack and Prevention

SQL injection is one of the most common and dangerous web application vulnerabilities. An attacker inputs malicious SQL code into a form field that gets incorporated into a database query.

 

ATTACK EXAMPLE: A login form sends the query:

SELECT * FROM USERS WHERE Username='' + input_username + '' AND Password='' + input_password + ''

If the attacker enters: Username = ' OR '1'='1 and Password = ' OR '1'='1

The query becomes: SELECT * FROM USERS WHERE Username='' OR '1'='1' AND Password='' OR '1'='1'

'1'='1' is always TRUE, so the attacker gains access without a valid password!

 

PREVENTION METHODS:

1.    Parameterised Queries (Prepared Statements) — NEVER concatenate user input directly into SQL

2.    Input Validation — Validate and sanitise all user inputs

3.    Stored Procedures — Use pre-compiled SQL

4.    Principle of Least Privilege — DB user for the app should have minimal rights

5.    Web Application Firewalls (WAF) — Detect and block injection attempts

 

SAFE QUERY (Java PreparedStatement):

PreparedStatement stmt = conn.prepareStatement('SELECT * FROM USERS WHERE Username=? AND Password=?');

stmt.setString(1, inputUsername);

stmt.setString(2, inputPassword);

8.6 Encryption

Encryption converts data into an unreadable format that can only be decoded with the correct key.

 

Encryption Type

Description and Example

Data at Rest

Encrypting database files on disk. E.g., MySQL Transparent Data Encryption (TDE) — if the server's hard disk is stolen, data remains unreadable.

Data in Transit

Encrypting data as it moves between client and server. E.g., SSL/TLS encryption for bank API connections.

Column-Level Encryption

Encrypting specific sensitive columns. E.g., encrypting BVN, credit card numbers, passwords using AES-256.

Password Hashing

Passwords are never stored in plain text. A one-way hash (bcrypt, SHA-256) is stored instead. Even if the DB is stolen, passwords cannot be reversed.

8.7 NDPR Compliance for Nigerian Database Systems

The Nigeria Data Protection Regulation (NDPR) 2019, issued by NITDA, places significant obligations on organisations that collect and process personal data of Nigerians. Key database-relevant requirements:

 

NDPR Requirement

Database Implementation

Lawful basis for processing

Document why each personal data field is collected

Data minimisation

Only store data you actually need — no speculative collection

Storage limitation

Delete personal data when no longer needed (implement data retention policies)

Integrity and confidentiality

Encrypt sensitive fields; implement access controls

Data subject rights (access, erasure)

Implement mechanisms for users to request their data or deletion

Data breach notification

Implement audit logs to detect and report breaches within 72 hours

8.8 Database Integrity Constraints

Beyond entity and referential integrity, DBMS supports additional integrity mechanisms:

1.    CHECK Constraints — Enforce domain-specific rules: CHECK (Age >= 18 AND Age <= 120); CHECK (Salary > 0);

2.    UNIQUE Constraints — Ensure no duplicates: BVN VARCHAR(11) UNIQUE;

3.    NOT NULL Constraints — Prevent null values in critical fields

4.    Triggers — Automatic actions that execute when specified events occur (INSERT, UPDATE, DELETE)

 

TRIGGER EXAMPLE — Audit log for salary changes:

CREATE TRIGGER salary_audit BEFORE UPDATE ON STAFF

FOR EACH ROW

INSERT INTO AUDIT_LOG (TableName, FieldChanged, OldValue, NewValue, ChangedBy, ChangeDate)

VALUES ('STAFF', 'Salary', OLD.Salary, NEW.Salary, USER(), NOW());

 

Reading List / References

1.    Elmasri, R. & Navathe, S. B. (2016). Fundamentals of Database Systems, Chapter 24: Database Security and Authorisation. Pearson.

2.    NITDA (2019). Nigeria Data Protection Regulation (NDPR). www.nitda.gov.ng

3.    OWASP (2023). SQL Injection. owasp.org/www-community/attacks/SQL_Injection

 

Activities

Self-Assessment Quiz: 1. What is the difference between authentication and authorisation? 2. Write SQL commands to: (a) create a user 'report_user', (b) grant SELECT on all tables in 'hr_db' to that user, (c) revoke that privilege. 3. Explain how a SQL injection attack works. Give a specific example. 4. How do database views help with security? Give an example from a Nigerian bank context.