What is Security by Design?
Security by Design is a proactive approach where security is integrated into every phase of the Software Development Life Cycle (SDLC), rather than being added as an afterthought. It ensures that security and privacy are fundamental considerations from requirements gathering through to maintenance.Security in the SDLC
Security should be considered at every phase of development:| Phase | Security by Design Processes | What Normo PWA Does Instead |
|---|---|---|
| Requirements Definition | • Gather specific security and privacy requirements • Vulnerability assessment | ❌ No security requirements defined ❌ No threat assessment performed |
| Determining Specifications | • Explicit security and privacy specifications • Risk assessment | ❌ No security specifications ❌ Risks deliberately introduced |
| Design | • Threat modelling • Security design review • Security tests included in test designs | ❌ Insecure architecture by design ❌ No security controls planned |
| Development | • Code reviews • Static application security testing | ❌ Vulnerable code intentionally written ❌ No code review process |
| Integration | • Risk assessment • Code reviews • Dynamic application security testing • Grey-box penetration testing | ❌ No integration security testing ❌ Vulnerabilities not addressed |
| Testing & Debugging | • Code reviews • SAST • DAST • Penetration testing | ✅ This is your phase! Students perform security testing |
| Installation | • Penetration testing • Vulnerability assessment | ⚠️ Sandbox-only deployment required |
| Maintenance | • Log monitoring & reporting • Vulnerability assessment | ❌ No logging or monitoring implemented |
Core Security Principles
1. Principle of Least Privilege
What it means: Users and processes should have the minimum level of access necessary to perform their functions. How Normo PWA violates it:host="0.0.0.0"exposes app to all network interfaces instead of localhost- No role-based access control (RBAC)
- All users have equal privileges
2. Defense in Depth
What it means: Multiple layers of security controls should be implemented so that if one fails, others provide protection. How Normo PWA violates it:| Security Layer | What Should Exist | What Actually Exists |
|---|---|---|
| Network | HTTPS/TLS, Firewall rules | ❌ HTTP only, no network security |
| Application | Input validation, Output encoding | ❌ No validation or encoding |
| Authentication | Strong passwords, MFA, session management | ❌ No password policy, no MFA, no sessions |
| Database | Parameterized queries, encrypted storage | ⚠️ Mixed (some queries secure, others not) |
| Logging | Security event logging, monitoring | ❌ No security logging |
user_management.py:17-39
- Input validation before the query
- Parameterized queries
- Rate limiting to prevent brute force
- Failed login tracking and account lockout
- Security event logging
3. Fail Securely
What it means: When systems fail, they should default to a secure state and not expose sensitive information. How Normo PWA violates it:main.py:70-73
- Full stack traces exposed to users
- Interactive debugger accessible via browser
- Source code snippets revealed
- Database structure exposed in SQL errors
Secure Configuration
4. Secure by Default
What it means: Default configurations should be secure, requiring users to explicitly opt into less secure options. How Normo PWA violates it:CORS Configuration
CORS Configuration
main.py:12-13
Password Storage
Password Storage
user_management.py:6-14
5. Separation of Concerns
What it means: Different aspects of the application should be isolated into distinct modules with well-defined interfaces. How Normo PWA violates it:main.py:46-67
Layered Architecture
6. Don’t Trust User Input
What it means: All user input should be treated as potentially malicious and validated/sanitized before use. How Normo PWA violates it:- SQL Injection
- XSS
- Open Redirect
user_management.py:45
feedback = "'); DROP TABLE users; --"Secure: Use parameterized queries7. Minimize Attack Surface
What it means: Reduce the number of potential entry points and exposed functionality. How Normo PWA violates it:| Unnecessary Exposure | Impact |
|---|---|
| Accepts all HTTP methods (GET, POST, PUT, PATCH, DELETE) | Increases attack vectors |
host="0.0.0.0" exposes to all network interfaces | Should use 127.0.0.1 for local development |
| Debug mode enabled | Exposes interactive debugger and stack traces |
| CORS allows all origins | Any website can make requests |
| No authentication on routes | All endpoints publicly accessible |
| Includes unused dependencies | Increases dependency vulnerability surface |
8. Keep Security Simple
What it means: Complex security systems are harder to implement correctly and maintain. Example of unnecessary complexity:user_management.py:32-33
Privacy by Design
Privacy by Design complements Security by Design with privacy-specific principles:Data Minimization
Principle: Collect only necessary dataViolation: App collects date of birth (DoB) but never uses it
Consent & Control
Principle: Users should control their dataViolation: No way to view, export, or delete user data
Transparency
Principle: Clear privacy policiesViolation: No privacy policy or terms of service
Secure Storage
Principle: Protect personal dataViolation: Plaintext passwords, unencrypted database
Threat Modeling Exercise
A proper threat model would identify threats and countermeasures:Example Threat Model
Example Threat Model
| Threat | Attack Vector | Current State | Countermeasure |
|---|---|---|---|
| Attacker steals user passwords | SQL injection in login form | ❌ Vulnerable | Parameterized queries |
| Attacker bypasses authentication | No session management | ❌ Vulnerable | Implement Flask-Login |
| Attacker executes JavaScript in victim’s browser | XSS in feedback system | ❌ Vulnerable | HTML escape all output |
| Attacker performs actions on behalf of victim | No CSRF protection | ❌ Vulnerable | Implement CSRF tokens |
| Attacker intercepts credentials in transit | HTTP instead of HTTPS | ❌ Vulnerable | Configure SSL/TLS |
| Attacker cracks passwords from database dump | Plaintext password storage | ❌ Vulnerable | Hash with bcrypt + salt |
| Attacker performs brute force login attempts | No rate limiting | ❌ Vulnerable | Implement Flask-Limiter |
| Attacker redirects users to phishing site | Open redirect vulnerability | ❌ Vulnerable | Validate redirect URLs |
Cost of Insecurity
The later in the SDLC that vulnerabilities are discovered, the more expensive they are to fix:The Normo Unsecure PWA gives you experience identifying vulnerabilities in the Testing phase. In real-world projects, you should implement security from the Requirements phase onward.
Your Learning Objectives
As you analyze this application, consider:- Identify violations: Which security principles does each vulnerability violate?
- Assess impact: What’s the worst-case scenario for each vulnerability?
- Design fixes: How would you implement proper security by design?
- Prevent recurrence: What processes would prevent these issues in future projects?
Next Steps
Testing Approaches
Learn how to systematically test for these vulnerabilities
Architecture Review
Understand the technical implementation details
Vulnerability Catalog
Explore each vulnerability in detail
Secure Coding Guide
Learn how to implement security by design
