Admin

Sep 9, 2025

Admin

Sep 9, 2025

Admin

Sep 9, 2025

OWASP Explained: A Complete Guide with Checklist for Developers

OWASP Explained: A Complete Guide with Checklist for Developers

Learn what OWASP is, explore the OWASP Top 10, and see secure coding examples in Java, Node.js, and Android—a complete guide with the MyPhones.app case study.

Introduction: What is OWASP?

The Open Web Application Security Project (OWASP) is a nonprofit foundation established in 2001 to improve software security worldwide. It provides developers and organizations with open resources such as the OWASP Top 10, Application Security Verification Standard (ASVS), Mobile Application Security Verification Standard (MASVS), and testing tools like OWASP ZAP.

OWASP matters because it creates a global standard for application security. Developers, security experts, and businesses use OWASP guidelines to secure apps, reduce vulnerabilities, and comply with industry regulations.

Why OWASP Matters

  • For developers: clear, secure coding guidelines and checklists to prevent common mistakes.

  • For businesses: a framework to audit security, train teams, and meet compliance.

  • For security teams: tools and standards to identify vulnerabilities and manage risk.

Simply put, OWASP bridges the gap between theory and practice in cybersecurity.

OWASP Top 10 with Code Examples

The OWASP Top 10 (2021 Edition) lists the most critical risks for web applications. Each category below includes a short explanation, insecure vs. secure code examples, and best practices.

A1: Broken Access Control

Why It Matters: Weak access control lets attackers access restricted resources.

Code Example:

// ✅ Spring Security: enforce server-side authorization
@PreAuthorize("hasRole('ADMIN') or #id == authentication.principal.id")
@GetMapping("/users/{id}")
public UserDto getUser(@PathVariable Long id) {
    return userService.findById(id);
}

Best Practice: Enforce least privilege and validate access on the server.

A2: Cryptographic Failures

Why It Matters: Insecure storage or transmission of data exposes passwords and sensitive information.

Code Example:

// ✅ Node.js: bcrypt password hashing
const bcrypt = require("bcrypt");
const SALT_ROUNDS = 12;

async function hashPassword(plain) {
  return await bcrypt.hash(plain, SALT_ROUNDS);
}

async function verifyPassword(plain, hash) {
  return await bcrypt.compare(plain, hash);
}

Best Practice: Use strong hashing (bcrypt, Argon2) and encrypt data in transit (TLS 1.2/1.3) and at rest (AES-GCM).

A3: Injection (SQL Injection)

Why It Matters: SQL Injection can compromise entire databases.

Code Example:

// ❌ Insecure: prone to SQL Injection
String user = request.getParameter("user");
String sql = "SELECT * FROM accounts WHERE username = '" + user + "'";
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql);

// ✅ Secure: parameterized query
String sql = "SELECT * FROM accounts WHERE username = ?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, user);
ResultSet rs = ps.executeQuery();

Best Practice: Always use parameterized queries or ORM frameworks.

A4: Insecure Design

Why It Matters: Flawed design allows attackers to bypass intended restrictions.

Code Example:

// ✅ Enforce business rule server-side
function assertCanTransfer(fromUserId: string, toUserId: string, actor: Actor) {
  if (actor.role !== "ADMIN" && actor.userId !== fromUserId) {
    throw new ForbiddenError("Not allowed to transfer from this account");
  }
}

Best Practice: Apply defense-in-depth and validate rules at multiple layers.

A5: Security Misconfiguration

Why It Matters: Default or insecure settings expose systems.

Code Example:

# Node.js production flag
export NODE_ENV=production
# Nginx: disable directory listing
location / {
  autoindex off;
}

Best Practice: Harden environments, disable unused features, review headers (CSP, HSTS, X-Frame-Options).

A6: Vulnerable and Outdated Components

Why It Matters: Using outdated libraries introduces known vulnerabilities.

Code Example:

// ✅ Gradle OWASP Dependency-Check
plugins {
  id "org.owasp.dependencycheck" version "10.0.4"
}

dependencyCheck {
  failBuildOnCVSS = 7.0
}

Best Practice: Automate dependency scanning in CI/CD and patch regularly.

A7: Identification and Authentication Failures

Why It Matters: Weak login mechanisms and broken sessions enable account takeover.

Code Example:

// ✅ Express: rate limit login attempts
import rateLimit from "express-rate-limit";

const loginLimiter = rateLimit({
  windowMs: 15 * 60 * 1000,
  max: 10,
});

app.post("/login", loginLimiter, loginHandler);

Best Practice: Use MFA, secure cookies, session expiration, and rate limiting.

A8: Software and Data Integrity Failures

Why It Matters: Without integrity checks, attackers can tamper with updates or payloads.

Code Example:

// ✅ Verify HMAC signature for webhook payload
import crypto from "crypto";

function verifySignature(rawBody, signature, secret) {
  const hmac = crypto.createHmac("sha256", secret);
  hmac.update(rawBody, "utf8");
  const expected = "sha256=" + hmac.digest("hex");
  return crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected));
}

Best Practice: Verify signatures for code, updates, and data.

A9: Security Logging and Monitoring Failures

Why It Matters: Without proper logging, attacks may go unnoticed.

Code Example:

// ✅ Structured logging with sensitive data redaction
import pino from "pino";
const logger = pino();

function safeUserLog(user) {
  const { password, token, ...safe } = user;
  logger.info({ event: "user_read", user: safe });
}

Best Practice: Log security events, redact sensitive data, and monitor in real time.

A10: Server-Side Request Forgery (SSRF)

Why It Matters: SSRF can expose internal services and data.

Code Example:

// ✅ Validate target against allowlist and block private IPs
const ALLOWLIST = new Set(["api.example.com"]);

async function fetchSafe(url) {
  const u = new URL(url);
  if (!ALLOWLIST.has(u.hostname)) throw new Error("Blocked by SSRF policy");
  return axios.get(url, { timeout: 5000 });
}

Best Practice: Use allowlists, block internal IPs, and sanitize user-supplied URLs.

OWASP Security Checklist

  • Authentication & Session: bcrypt/Argon2, MFA, secure cookies

  • Access Control: least privilege, deny-by-default

  • Data Protection: TLS 1.2+, AES-GCM, secure key storage

  • Input Validation: parameterized queries, sanitize input

  • Secure Design & Config: disable defaults, apply CSP, patch regularly

  • Logging & Monitoring: structured logs, alerts, and monitoring

OWASP for Mobile: MASVS

The Mobile Application Security Verification Standard (MASVS) focuses on secure mobile app development.

Why It Matters: With billions of mobile users, insecure apps can leak personal data.

Code Example (Android Secure Storage):

val masterKey = MasterKey.Builder(context)
  .setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
  .build()

val prefs = EncryptedSharedPreferences.create(
  context,
  "secure_prefs",
  masterKey,
  EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
  EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
)

prefs.edit().putString("token", token).apply()

Best Practice: Use Keystore, encrypted shared preferences, and TLS pinning.

Tools from OWASP

  • OWASP ZAP – penetration testing proxy

  • Dependency-Check – scan for vulnerable libraries

  • DefectDojo – vulnerability management platform

  • ESAPI – enterprise security APIs

Best Practices for Developers

  1. Shift left – integrate security early in SDLC

  2. Automate – add OWASP tools to CI/CD pipelines

  3. Train – educate dev teams on secure coding

  4. Review – patch dependencies regularly

  5. Audit – penetration tests and code reviews

Related Project: MyPhones.app — Real-World OWASP Adoption

MyPhones.app is a practical example of applying OWASP and MASVS in production:

  • bcrypt/Argon2 password hashing and MFA

  • Spring Security with role-based access control

  • AES-GCM with Android Keystore for secure storage

  • TLS 1.3, HSTS, and secure cookie flags

  • CSP, secure headers, and certificate pinning

  • Automated dependency scanning and SSRF validation

  • Privacy-by-design logging with sensitive-field redaction

Explore MyPhones.app: https://myphones.app/

Final Thoughts

OWASP is more than a list of vulnerabilities — it is a global movement dedicated to securing software. By following the OWASP Top 10, applying ASVS and MASVS, and using secure code patterns, you reduce risks and build user trust.

Security is not one-time; it is a continuous process. Integrating OWASP into your workflow ensures your applications are prepared for modern threats.

====================
📌 Key Takeaways

• OWASP sets global standards for application security
• OWASP Top 10 covers the most critical risks
• Secure coding prevents injection, auth, and SSRF flaws
• OWASP tools (ZAP, Dependency-Check) support testing
• MASVS ensures secure mobile app development
• MyPhones.app applies OWASP and MASVS in production

====================

Comments (please send an email at support@droidinsights.dev)

Comments (please send an email at support@droidinsights.dev)

Comments (please send an email at support@droidinsights.dev)