
IS and Anti-Fraud, Part 3: Secure Development — Typical Vulnerabilities and How to Prevent Them
🌐 Machine-translated from Russian. Show original
In this part:
Where Vulnerabilities Come From#
Most often—not due to complex errors, but because of forgotten checks: permissions were not checked on the server, input data was not validated, the secret was left in the code. A guide for developers is the OWASP Top 10 list: the most common web application vulnerability classes.
Access control breach#
The most common problem: the user sees or changes someone else's data by inserting a different ID into the request.
// ❌ Плохо: доверяем ID из запроса
const order = await db.order.findUnique({ where: { id: req.params.id } });
// ✅ Хорошо: проверяем владельца на сервере
const order = await db.order.findFirst({ where: { id: req.params.id, userId: session.userId } });
if (!order) return notFound();
Rules:
- Each data request checks rights on the server. A hidden button in the interface is not protection.
- Default access is denied, permission is explicitly granted.
- Admin functions — separate routes with separate role verification.
Injections#
SQL injections, command injections, XSS — all occur when user data enters the code without processing.
- SQL — only parameterized queries or ORMs. Never merge SQL from user lines.
- XSS — use templating engines and frameworks that escape output by default; do not insert custom HTML as is; add a Content-Security-Policy header.
- OS commands — do not call shells with strings from the user; pass arguments as a list.
Authentication and sessions#
- Store passwords only as hashes using slow algorithms: argon2id, bcrypt, scrypt.
- Session cookies — with flags
HttpOnly,Secure,SameSite. - Limit the number of login and registration attempts — more details in the account protection section.
Dependencies#
- Most of the application code consists of third-party libraries. Dependency vulnerability — a vulnerability in your product.
- Enable automatic checks:
npm audit, Dependabot, Renovate, or equivalents. - Commit versions (lock files) and update regularly, not every three years.
Uploading files#
- Check the file type by content, not by extension.
- Store downloads outside the executable directory, deliver with the correct Content-Type.
- Re-encode images — this also removes geolocation metadata.
Security during development#
| Stage | Measure |
|---|---|
| Designing | threat model for a new feature (part 1 |
| Code | security checklist in code review |
| CI | security linters, dependency checks, and secrets |
| Before release, | check access rights to new endpoints |
| Product | security headers, HTTPS, error monitoring, |
CI automation — in the "Docker and CI/CD from scratch" series.
Checklist for code review#
- Rights are verified on the server for each data request
- No SQL assembled from user strings
- Output escapes, custom HTML is not inserted as is
- No secrets in code or logs
- Input data is validated according to the scheme
- Errors do not reveal the internals (stacktraces, SQL) to the user
Comments · 0
No comments yet.Sign in to comment, rate and see all comments.