# Security Design Specification

---

**Document Version:** 1.0
**Project:** Student Bazaar
**Document Type:** Security Design Specification
**Status:** Approved
**Last Updated:** 28 June 2026
**Author:** Nemmi Tangha

---

# 1. Purpose

This document defines the security architecture and security standards for Student Bazaar.

The objective is to protect user accounts, marketplace data, uploaded files, and application resources while following modern web application security best practices.

Security is implemented across all application layers, including authentication, authorization, database access, file handling, and session management.

---

# 2. Security Objectives

Student Bazaar is designed to achieve the following security objectives:

* Protect user accounts
* Protect sensitive information
* Prevent unauthorized access
* Maintain data integrity
* Prevent common web attacks
* Secure uploaded files
* Provide secure session management
* Support future security enhancements

---

# 3. Authentication Security

Authentication follows secure account management practices.

Security measures include:

* Password hashing using Werkzeug
* Email verification before account activation
* Secure password reset tokens
* Account lockout after repeated failed login attempts
* Password change tracking
* Secure session management

Passwords are never stored or transmitted in plain text.

---

# 4. Authorization

Student Bazaar uses role-based access control (RBAC).

Supported roles:

* Student
* Super Admin

Students can:

* Buy products
* Sell products
* Send messages
* Make offers
* Schedule meet-ups

Super Admins can:

* Manage users
* Moderate listings
* Review reports
* Manage advertisements
* Configure system settings

Every protected route must verify the user's role before allowing access.

---

# 5. Password Security

Passwords must satisfy the following requirements:

* Minimum length of 8 characters
* At least one uppercase letter
* At least one lowercase letter
* At least one number
* At least one special character

Passwords are hashed using Werkzeug's secure password hashing utilities before storage.

Passwords are never logged, displayed, or stored in plain text.

---

# 6. Email Verification

Every newly registered account must verify its email address before accessing protected features.

Verification tokens:

* Are cryptographically secure
* Are single-use
* Have an expiration time
* Become invalid after successful verification

---

# 7. Account Lockout

To reduce brute-force attacks:

* Failed login attempts are tracked.
* Accounts may be temporarily locked after exceeding the configured threshold.
* Successful login resets the failed login counter.
* Locked accounts automatically unlock after the configured lock period.

The maximum number of attempts and lock duration should be configurable through the `system_settings` table.

---

# 8. Session Security

Student Bazaar uses Flask-Login for secure session management.

Security measures include:

* Secure session cookies
* HTTPOnly cookies
* SameSite cookie protection
* Session expiration after inactivity
* Automatic logout after password reset
* Session invalidation after account suspension

---

# 9. CSRF Protection

All forms must be protected against Cross-Site Request Forgery (CSRF).

Implementation:

* Flask-WTF
* CSRF Tokens
* Validation on every POST, PUT, PATCH, and DELETE request

---

# 10. SQL Injection Prevention

Database access must use SQLAlchemy ORM and parameterized queries.

Direct string concatenation for SQL statements is prohibited.

This prevents SQL Injection attacks.

---

# 11. Cross-Site Scripting (XSS) Prevention

To reduce XSS attacks:

* Escape user-generated content by default.
* Validate and sanitize input.
* Restrict HTML where appropriate.
* Use Jinja2 automatic escaping.

---

# 12. File Upload Security

Supported uploads:

* Profile Pictures
* Listing Images
* Advertisement Images

Security requirements:

* Validate MIME type
* Validate file extension
* Validate file size
* Rename uploaded files using unique filenames
* Store uploads outside executable directories

Executable file uploads are not permitted.

---

# 13. Input Validation

Every request must be validated.

Validation includes:

* Required fields
* Data types
* Length restrictions
* Numeric ranges
* Email format
* File validation
* Authorization checks

Validation occurs before business logic execution.

---

# 14. Secure Communication

Student Bazaar should be deployed using HTTPS.

Benefits include:

* Encrypted communication
* Protection against eavesdropping
* Secure authentication
* Secure session cookies

Production deployments should enforce HTTPS.

---

# 15. Logging and Auditing

Important security events should be logged.

Examples include:

* Successful login
* Failed login
* Account lockout
* Password reset
* Email verification
* Listing removal
* Report resolution
* Administrative actions

Logs assist with auditing, monitoring, and troubleshooting.

---

# 16. Error Handling

Security-related errors must not expose sensitive information.

Guidelines:

* Display user-friendly messages.
* Log detailed errors internally.
* Never expose stack traces in production.
* Avoid revealing database or server details.

---

# 17. Marketplace Security

Marketplace protections include:

* Listing ownership verification
* Offer ownership verification
* Chat access restricted to conversation participants
* Meet-up access restricted to participants
* Listing moderation by Super Admin
* Report handling workflow

---

# 18. Privacy Protection

Student Bazaar stores only information necessary for platform operation.

Privacy principles include:

* Password hashing
* Secure token generation
* Limited data exposure
* Secure profile management

Student Bazaar does not process or store payment information.

---

# 19. Future Security Enhancements

Future versions may introduce:

* Multi-Factor Authentication (MFA)
* OAuth Login
* College Email Verification
* Device Recognition
* Login Notifications
* Risk-Based Authentication
* Push Authentication

The current architecture supports these enhancements without major redesign.

---
### Personal Contact Information Policy

To maintain user safety and encourage communication within the platform, students are not permitted to share personal contact information (such as phone numbers, WhatsApp numbers, email addresses, Telegram usernames, or similar contact details) through the chat before an offer has been accepted.

Once an offer is accepted and a meet-up has been scheduled, students may exchange contact details if necessary.

This policy supports platform safety, moderation, and the Premium messaging model.
---

# 20. Security Standards Summary

The application implements:

* Password Hashing
* Email Verification
* Strong Password Policy
* Account Lockout
* Role-Based Access Control
* CSRF Protection
* SQL Injection Prevention
* XSS Prevention
* Input Validation
* Secure File Uploads
* Secure Sessions
* HTTPS Support
* Security Logging
* Audit Logging

---

# 21. Conclusion

Security is integrated throughout Student Bazaar rather than treated as a separate feature.

By combining secure authentication, role-based authorization, strong input validation, secure file handling, and modern web security practices, the platform provides a robust and scalable security foundation while remaining ready for future enhancements.
