Skip to content

Commit 29c7786

Browse files
committed
fix(security): add rate limiting to search endpoint
1 parent a5ab8ce commit 29c7786

1 file changed

Lines changed: 94 additions & 38 deletions

File tree

checkpoints/checkpoint-19-owasp-security-practices.md

Lines changed: 94 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ To answer that question, I explored:
1313
- OWASP Top 10 risks
1414
- Secrets management
1515
- Dependency scanning
16-
- Static application security testing (SAST)
16+
- Static Application Security Testing (SAST)
1717
- Container security
1818
- Secure CI/CD pipelines
1919
- Branch protection rules
@@ -26,20 +26,21 @@ OWASP is not a tool.
2626

2727
OWASP is a collection of security risks, best practices, and guidelines that help developers build secure applications.
2828

29-
Many of the tools I practiced throughout Phase 4 exist to mitigate OWASP risks.
29+
Many of the tools and practices explored throughout Phase 4 exist to mitigate OWASP risks.
3030

3131
---
3232

3333
# 🔥 OWASP Risks and Their DevSecOps Counterparts
3434

35-
| OWASP Risk | Tool / Practice |
36-
| --------------------------- | ------------------------ |
37-
| SQL Injection | Semgrep, CodeQL |
38-
| Sensitive Data Exposure | `.env`, GitHub Secrets |
39-
| Vulnerable Components | `npm audit`, Trivy |
40-
| Security Misconfiguration | Branch Protection, CI/CD |
41-
| Broken Access Control | RBAC |
42-
| Software Integrity Failures | CodeQL, Secure Pipelines |
35+
| OWASP Risk | Tool / Practice |
36+
| :-------------------------- | :------------------------------------- |
37+
| Injection | Semgrep, CodeQL, Parameterized Queries |
38+
| Sensitive Data Exposure | `.env`, GitHub Secrets |
39+
| Vulnerable Components | `npm audit`, Trivy |
40+
| Security Misconfiguration | Branch Protection, CI/CD |
41+
| Broken Access Control | RBAC |
42+
| Software Integrity Failures | CodeQL, Secure Pipelines |
43+
| Denial of Service (DoS) | Rate Limiting |
4344

4445
---
4546

@@ -56,7 +57,7 @@ labs/security/secrets-lab/
5657
Practiced:
5758

5859
- Storing secrets inside `.env`
59-
- Preventing secret leaks with `.gitignore`
60+
- Preventing secret leaks using `.gitignore`
6061
- Using GitHub Secrets inside workflows
6162

6263
---
@@ -100,7 +101,64 @@ Integrated GitHub CodeQL scanning.
100101
Observed:
101102

102103
- Detection of clear-text logging
103-
- Security findings inside the Security tab
104+
- Detection of SQL Injection risks
105+
- Detection of missing rate limiting on database endpoints
106+
- Security findings inside the GitHub Security tab
107+
108+
Learned:
109+
110+
- Secure code is not only about preventing SQL Injection.
111+
- Security tools analyze data flow between application components.
112+
- API endpoints that access databases should implement rate limiting.
113+
- Security also includes protecting application availability.
114+
115+
---
116+
117+
## OWASP Practice: SQL Injection and Rate Limiting
118+
119+
Created:
120+
121+
```text
122+
labs/security/owasp-lab/
123+
```
124+
125+
Practiced:
126+
127+
- Writing intentionally vulnerable SQL queries
128+
- Detecting SQL Injection using CodeQL
129+
- Fixing vulnerabilities using parameterized queries
130+
- Protecting endpoints with `express-rate-limit`
131+
132+
Vulnerable query:
133+
134+
```javascript
135+
const sql = `SELECT * FROM users WHERE name = '${query}'`;
136+
```
137+
138+
Secure query:
139+
140+
```javascript
141+
const [rows] = await db.execute('SELECT * FROM users WHERE name = ?', [query]);
142+
```
143+
144+
Added rate limiting:
145+
146+
```javascript
147+
const rateLimit = require('express-rate-limit');
148+
149+
const limiter = rateLimit({
150+
windowMs: 15 * 60 * 1000,
151+
max: 100,
152+
});
153+
154+
app.use(limiter);
155+
```
156+
157+
Learned:
158+
159+
- User input should never be directly concatenated into SQL queries.
160+
- Databases should receive queries and parameters separately.
161+
- Public endpoints should implement rate limiting to prevent denial-of-service attacks.
104162

105163
---
106164

@@ -110,13 +168,14 @@ Commands:
110168

111169
```bash
112170
trivy image my-first-image
171+
113172
trivy image node:24-slim
114173
```
115174

116175
Learned:
117176

118-
- Containers inherit vulnerabilities from base images.
119-
- Smaller images reduce attack surface.
177+
- Containers inherit vulnerabilities from their base images.
178+
- Smaller images reduce the attack surface.
120179
- Security is not only about application code.
121180

122181
---
@@ -160,23 +219,25 @@ Security is not a single tool.
160219
161220
Modern DevSecOps combines:
162221
222+
```text
163223
Developer
164-
224+
165225
Secrets Management
166-
226+
167227
Dependency Scanning
168-
228+
169229
SAST
170-
230+
171231
CodeQL
172-
232+
173233
Container Security
174-
234+
175235
Secure CI/CD
176-
236+
177237
Branch Protection
178-
238+
179239
Deployment
240+
```
180241

181242
OWASP provides the security model that connects all of these layers.
182243

@@ -188,28 +249,23 @@ Before this checkpoint, I viewed security as individual tools and isolated vulne
188249

189250
After completing Phase 4, I understand that modern application security is a chain of defenses that protects code before it reaches production.
190251

252+
I also learned that security is not limited to preventing SQL Injection or protecting secrets. Modern applications must also defend against denial-of-service attacks, insecure dependencies, vulnerable containers, and unsafe deployment pipelines.
253+
191254
---
192255

193256
# 🚀 Phase 4 Complete
194257

195258
Completed:
196259

197-
✅ Environment Variables & Secrets Management
198-
199-
✅ Dependency Scanning
200-
201-
✅ SAST
202-
203-
✅ CodeQL
204-
205-
✅ Trivy Container Scanning
206-
207-
✅ Container Security
208-
209-
✅ Secure CI/CD Pipelines
210-
211-
✅ OWASP Security Practices
260+
- ✅ Environment Variables & Secrets Management
261+
- ✅ Dependency Scanning
262+
- ✅ SAST
263+
- ✅ CodeQL
264+
- ✅ Trivy Container Scanning
265+
- ✅ Container Security
266+
- ✅ Secure CI/CD Pipelines
267+
- ✅ OWASP Security Practices
212268

213269
The next step is:
214270

215-
🌐 Phase 5 — Infrastructure
271+
🌐 **Phase 5 — Infrastructure**

0 commit comments

Comments
 (0)