Overview
The School Management Platform implements multiple layers of security to protect user data and prevent common web vulnerabilities. Security is integrated at every level: session management, database access, authentication, and authorization.Security Architecture
Authentication
Password Security
Passwords are secured using PHP’s built-in password hashing functions.Password Hashing
PASSWORD_DEFAULT currently uses the bcrypt algorithm. This automatically handles salt generation and provides strong one-way encryption.Password Verification
app/controllers/AuthController.php:27
Key Password Security Features
One-Way Hashing
Passwords cannot be reversed from their hash
Automatic Salting
Each password gets a unique random salt
Adaptive Algorithm
PASSWORD_DEFAULT evolves with PHP security improvements
Constant-Time Comparison
password_verify() prevents timing attacks
Session Management
Secure Session Configuration
Session security is configured at application startup:public/index.php:2-8
Session Cookie Parameters Explained
| Parameter | Value | Purpose |
|---|---|---|
httponly | true | Prevents XSS attacks by blocking JavaScript access to cookies |
secure | false (dev) / true (prod) | Ensures cookies only sent over HTTPS |
samesite | Strict | Blocks cookies from being sent with cross-site requests (CSRF protection) |
Session Timeout (30 Minutes)
Automatic logout after 30 minutes of inactivity:app/core/Auth.php:12-27
Session Fixation Prevention
app/controllers/AuthController.php:32-33
Session regeneration creates a new session ID while preserving session data, preventing attackers from using a pre-set session ID.
Authorization (Role-Based Access Control)
The application implements RBAC with three distinct roles:Role Enforcement Methods
app/core/Auth.php
Controller Protection Examples
Role Permissions Matrix
| Feature | Admin | Teacher | Student |
|---|---|---|---|
| Manage Students | ✅ | ❌ | ❌ |
| Manage Teachers | ✅ | ❌ | ❌ |
| Manage Subjects | ✅ | ❌ | ❌ |
| Create Courses | ✅ | ❌ | ❌ |
| Manage Enrollments | ✅ | ❌ | ❌ |
| Create Timetable | ✅ | ❌ | ❌ |
| View All Bulletins | ✅ | ❌ | ❌ |
| Assign Grades | ❌ | ✅ | ❌ |
| View Assigned Courses | ❌ | ✅ | ❌ |
| View Teacher Timetable | ❌ | ✅ | ❌ |
| View Personal Grades | ❌ | ❌ | ✅ |
| View Personal Bulletin | ❌ | ❌ | ✅ |
| View Student Timetable | ❌ | ❌ | ✅ |
SQL Injection Prevention
All database queries use PDO prepared statements to prevent SQL injection attacks.Prepared Statement Examples
Why Prepared Statements Are Secure
Cross-Site Scripting (XSS) Prevention
While not explicitly shown in the model code, views should use output escaping:View Output Escaping Best Practice
htmlspecialchars() converts special characters to HTML entities, preventing malicious scripts from executing in the browser.Cross-Site Request Forgery (CSRF) Protection
CSRF protection is partially implemented through:- SameSite Cookie Attribute: Prevents cookies from being sent with cross-origin requests
- Session Validation: All state-changing operations require valid session
Enhancement Opportunity: Implement CSRF tokens for critical actions like delete operations.
Security Best Practices Implementation
Principle of Least Privilege
Principle of Least Privilege
Users only have access to features required for their role:
- Students cannot modify grades
- Teachers cannot manage users
- Only admins can create/delete entities
Defense in Depth
Defense in Depth
Multiple security layers:
- Session validation
- Role-based authorization
- Prepared statements
- Password hashing
- HttpOnly cookies
Secure Defaults
Secure Defaults
Security features enabled by default:
- Sessions always checked
- Prepared statements required
- Passwords always hashed
Fail Securely
Fail Securely
On authentication/authorization failure:
- Sessions destroyed
- Users redirected to login
- No sensitive information leaked
Security Checklist
Production Security Recommendations
Common Vulnerabilities Prevented
SQL Injection
Status: ✅ PreventedPDO prepared statements throughout
Session Hijacking
Status: ✅ PreventedHttpOnly cookies + session regeneration
Session Fixation
Status: ✅ PreventedSession ID regeneration on login
Brute Force
Status: ⚠️ PartialPassword hashing implemented; rate limiting recommended
CSRF
Status: ⚠️ PartialSameSite cookies; CSRF tokens recommended
XSS
Status: ⚠️ View-DependentRequires proper output escaping in views
Security Monitoring
Session Activity Tracking
Every request updates the last activity timestamp:app/core/Auth.php:26
- Automatic timeout enforcement
- Activity logging (if implemented)
- Session duration tracking
User Session Data
Password not stored in session: Only non-sensitive user information is kept in session data.
Next Steps
MVC Structure
Understand how security is integrated into the MVC pattern
Database Schema
Review database-level security constraints