Shifting Security Left: From Release Gate to Design Phase
Secure SDLC: Building Security In, Not Bolting It On
The traditional approach to application security treats it as a final gate before release — a penetration test or security review that happens after development is complete. This approach is expensive, slow, and ineffective. Fixing a security flaw found in production costs 100x more than fixing it during design. The Secure Software Development Lifecycle (Secure SDLC) integrates security activities into every phase of development, from requirements to deployment.
The Cost of Late-Stage Security
| Phase | Relative Cost to Fix |
|---|---|
| Design | 1x |
| Implementation | 6x |
| Testing | 15x |
| Production | 100x |
These ratios, originally from IBM Systems Sciences Institute, have been validated repeatedly. A design flaw (e.g., missing authorization on object references) is a conversation during design, a code change during implementation, a test case during testing, and an emergency patch with potential data breach in production.
Phases of a Secure SDLC
1. Requirements
- Define security requirements alongside functional requirements
- Identify regulatory and compliance requirements (PCI-DSS, HIPAA, GDPR)
- Define data classification (public, internal, confidential, restricted)
- Establish security acceptance criteria for user stories
2. Design
- Threat modeling: identify attack surfaces, trust boundaries, and potential threats
- Security architecture review: authentication, authorization, data flow, encryption
- Select security controls based on identified threats
- Document security assumptions and trust boundaries
3. Implementation
- Secure coding standards and guidelines
- Static Application Security Testing (SAST) in the IDE and CI/CD
- Dependency scanning for known vulnerabilities
- Security-focused code review
4. Testing
- Dynamic Application Security Testing (DAST)
- Penetration testing for high-risk applications
- Security regression testing
- Fuzz testing for input validation
5. Deployment
- Infrastructure security scanning (container images, cloud configuration)
- Web Application Firewall (WAF) configuration
- Security monitoring and alerting setup
- Incident response plan
6. Operations
- Continuous monitoring and logging
- Vulnerability management and patching
- Incident response and forensics
- Periodic penetration testing and red team exercises
Threat Modeling
Threat modeling is the systematic process of identifying and mitigating security threats before code is written. The most common framework is STRIDE, developed by Microsoft:
| Threat | Category | Question |
|---|---|---|
| Spoofing | Authentication | Can an attacker impersonate another user? |
| Tampering | Integrity | Can an attacker modify data in transit or at rest? |
| Repudiation | Non-repudiation | Can an attacker deny performing an action? |
| Information Disclosure | Confidentiality | Can an attacker access data they should not see? |
| Denial of Service | Availability | Can an attacker prevent legitimate users from accessing the system? |
| Elevation of Privilege | Authorization | Can an attacker gain higher privileges than intended? |
Threat modeling process:
- Diagram the system: Data flow diagrams showing components, data stores, and trust boundaries
- Identify threats: Apply STRIDE to each element and trust boundary
- Rate threats: Use DREAD (Damage, Reproducibility, Exploitability, Affected users, Discoverability) to prioritize
- Mitigate: Design controls for each high-priority threat
- Validate: Verify that mitigations are implemented correctly
SAST, DAST, and Security Code Review
Security Testing Layers and Code Review Practices
No single security testing method catches all vulnerabilities. SAST, DAST, and manual code review each cover different layers, and a mature security program uses all three.
Static Application Security Testing (SAST)
SAST tools analyze source code, bytecode, or binary code without executing the application. They identify patterns associated with vulnerabilities:
- SQL injection (string concatenation in queries)
- Hardcoded credentials
- Weak cryptography (MD5, DES, short key lengths)
- Path traversal (unsanitized file paths)
- Command injection (unsanitized input to
exec,system)
Advantages:
- Catches vulnerabilities early (in IDE or CI/CD)
- Provides exact line numbers and code context
- Scales to large codebases
- Can enforce coding standards
Limitations:
- High false-positive rate (especially for data flow analysis)
- Cannot detect runtime vulnerabilities (authentication bypass, business logic flaws)
- Language-specific (each tool supports specific languages)
- Cannot analyze configuration or infrastructure
Tools: SonarQube, Semgrep, Checkmarx, Bandit (Python), ESLint security plugins
# Semgrep — lightweight SAST with custom rules
semgrep --config=auto --config=custom-rules/ src/
# Bandit — Python-specific SAST
bandit -r ./src -f json -o bandit-report.json
Dynamic Application Security Testing (DAST)
DAST tools test a running application from the outside, simulating attacker behavior:
- Fuzzing input fields with malicious payloads
- Testing for injection vulnerabilities (SQL, XSS, command)
- Analyzing authentication and session management
- Checking security headers and configurations
- Testing access control by attempting unauthorized actions
Advantages:
- Tests the actual running application (including configuration)
- Detects runtime vulnerabilities that SAST cannot
- Language-agnostic (tests the HTTP interface)
- Finds business logic flaws through workflow testing
Limitations:
- Cannot identify exact code locations (only the vulnerable endpoint)
- Requires a running application
- May miss vulnerabilities in unlinked or hidden endpoints
- Can be slow for large applications
Tools: OWASP ZAP, Burp Suite Professional, Acunetix, Nikto
# OWASP ZAP — automated DAST scan
zap-baseline.py -t https://example.com -r zap-report.html
Penetration Testing
Penetration testing is a manual, human-driven assessment that simulates a real attacker:
- Combines automated tools with manual exploitation
- Tests business logic flaws that automated tools miss
- Validates the effectiveness of security controls
- Provides a realistic assessment of risk
When to use:
- Before major releases
- After significant architecture changes
- For high-risk applications (financial, healthcare)
- Periodically (annually or semi-annually)
Security Code Review
Security code review is the manual examination of code changes for security flaws. It is the most effective way to catch business logic vulnerabilities and design flaws that automated tools miss.
What to look for in code review:
- Authentication: Are credentials verified on every request? Is the session token validated?
- Authorization: Is the user authorized for this specific action on this specific object?
- Input validation: Is all user input validated at the trust boundary?
- Output encoding: Is data encoded for the correct output context?
- Cryptography: Are strong algorithms used? Are keys managed securely?
- Error handling: Do error messages leak sensitive information?
- Logging: Are security-relevant events logged? Are secrets redacted?
Scaling code review with security champions:
A security champion is a developer within a product team who has additional security training and serves as the first line of security review. Security champions:
- Review code for security flaws before it reaches the central security team
- Advocate for secure coding practices within their team
- Escalate complex security issues to the central security team
- Scale security review beyond what a central team can handle alone
Practice: Threat Model a Feature
Threat model a new feature: a file upload service that allows users to upload profile pictures. The images are stored in cloud storage and served via a CDN. Use STRIDE to identify threats.
Practice Problems
For each scenario, choose the most appropriate security testing method (SAST, DAST, penetration testing, or code review) and explain why: 1. A developer wants to check their code for SQL injection before committing 2. A team wants to test their running web application for XSS vulnerabilities 3. A financial application needs to validate that its funds transfer workflow cannot be manipulated 4. A team wants to enforce secure coding standards across their entire codebase
Solution
1. **SAST** — The developer needs to check source code before committing. SAST tools (like Semgrep or SonarQube) integrate into the IDE and CI/CD to catch vulnerabilities like SQL injection at the code level, with exact line numbers.
2. **DAST** — The team needs to test a running application. DAST tools (like OWASP ZAP) test the live application from the outside, simulating attacker behavior and detecting runtime XSS vulnerabilities.
3. **Penetration testing** — Business logic flaws in a funds transfer workflow require manual testing by a skilled penetration tester. Automated tools cannot understand the business context and workflow logic well enough to identify manipulation opportunities.
4. **SAST** — Enforcing secure coding standards across a codebase is a SAST use case. Tools like SonarQube and Semgrep can be configured with custom rules to enforce coding standards and fail builds when violations are found. Threat model a password reset feature using STRIDE. The feature allows users to reset their password by entering their email address. The system sends a reset link with a token to the user's email. The token expires after 15 minutes.
Solution
**STRIDE Analysis:**
1. **Spoofing**: An attacker could request a password reset for a victim's email address, potentially flooding the victim's inbox (email bombing). *Mitigation: Rate limit reset requests per IP and per email address.*
2. **Tampering**: An attacker could intercept the reset link (if sent over HTTP) or modify the token. *Mitigation: Use HTTPS, sign the token with HMAC, and validate the token integrity on use.*
3. **Repudiation**: A user could request a reset and deny it. *Mitigation: Log all reset requests with IP address and timestamp.*
4. **Information Disclosure**: The reset token could be leaked via the Referer header if the reset page loads external resources. *Mitigation: Use `Referrer-Policy: no-referrer` on the reset page.*
5. **Denial of Service**: An attacker could repeatedly request resets for a victim's email, causing the victim to receive spam. *Mitigation: Rate limit, CAPTCHA after multiple requests.*
6. **Elevation of Privilege**: An attacker could guess or brute-force the reset token. *Mitigation: Use a cryptographically random token with sufficient entropy (128+ bits). Expire after 15 minutes. Invalidate after use.* Quiz
1. What does 'shifting security left' mean in the context of Secure SDLC?
2. What is the primary difference between SAST and DAST?
3. In the STRIDE threat modeling framework, what does the 'E' stand for and what question does it answer?
4. Why is manual security code review still necessary even when SAST and DAST tools are in place?
5. What is a security champion in the context of scaling security code review?
Flashcards
Question
What does 'shifting security left' mean?
Click to reveal answer
Answer
Integrating security activities earlier in the development lifecycle — from design through deployment — rather than only at release. Fixing a flaw during design costs 1x; in production it costs 100x.
Question
What is the difference between SAST and DAST?
Click to reveal answer
Answer
SAST analyzes source code without executing the application — catches vulnerabilities early with exact line numbers. DAST tests a running application from the outside — detects runtime vulnerabilities but without code-level context.
Question
What does STRIDE stand for in threat modeling?
Click to reveal answer
Answer
Spoofing, Tampering, Repudiation, Information Disclosure, Denial of Service, Elevation of Privilege. Each category answers a specific security question about the system being modeled.
Question
Why is manual code review necessary even with SAST and DAST?
Click to reveal answer
Answer
Automated tools cannot detect business logic flaws, design vulnerabilities, or context-dependent issues. Manual review by a security-trained engineer identifies issues that require understanding the application's intended behavior.
Question
What is a security champion?
Click to reveal answer
Answer
A developer within a product team who has additional security training and serves as the first line of security review. They scale security review beyond what a central team can handle alone.
Revision Notes
Key Takeaways
- 1. Shifting security left means integrating security from design through deployment — fixing flaws early costs 100x less than in production
- 2. Threat modeling with STRIDE identifies threats before code is written
- 3. SAST analyzes source code, DAST tests running applications, penetration testing covers business logic — all three are necessary
- 4. Security champions scale code review by embedding security-trained developers in product teams
- 5. No single security testing method catches all vulnerabilities — defense in depth requires multiple layers
Interview Tips
- • Explain the cost differential of fixing vulnerabilities at different phases (1x design vs 100x production)
- • Walk through a STRIDE threat model for a specific feature to demonstrate practical application
- • Discuss the strengths and limitations of SAST, DAST, and penetration testing with concrete examples
- • Describe how security champions scale security review and why a central-only model fails for large organizations
Cheat Sheet
Secure SDLC and Security Code Review Cheat Sheet
Phase: Application Security and Secure Coding | Level: advanced
Secure SDLC Phases:
- Requirements — security requirements, data classification
- Design — threat modeling, security architecture
- Implementation — SAST, dependency scanning, code review
- Testing — DAST, penetration testing, fuzzing
- Deployment — infrastructure scanning, WAF, monitoring
- Operations — continuous monitoring, incident response
Threat Modeling (STRIDE):
- Spoofing — Can an attacker impersonate a user?
- Tampering — Can an attacker modify data?
- Repudiation — Can an attacker deny an action?
- Information Disclosure — Can an attacker access restricted data?
- Denial of Service — Can an attacker disrupt service?
- Elevation of Privilege — Can an attacker gain higher privileges?
Security Testing:
- SAST — source code analysis, early detection, exact line numbers
- DAST — running application testing, runtime vulnerabilities
- Penetration testing — manual, business logic flaws, high-risk apps
- Code review — manual, design flaws, context-dependent issues
Key points:
- Shifting security left means threat modeling at design instead of scanning only at release
- SAST, DAST, and penetration tests cover different layers and none replaces the others
- Security champions embedded in product teams scale review beyond a central security group
Tags: secure-sdlc, code-review
Continue Learning
Before You Start
- No prerequisites listed.